summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gdb-xds.go82
-rw-r--r--main.go23
2 files changed, 79 insertions, 26 deletions
diff --git a/gdb-xds.go b/gdb-xds.go
index e2dfeb8..d57817d 100644
--- a/gdb-xds.go
+++ b/gdb-xds.go
@@ -35,17 +35,18 @@ import (
// GdbXds - Implementation of IGDB used to interfacing XDS
type GdbXds struct {
- log *logrus.Logger
- ccmd string
- aargs []string
- eenv []string
- uri string
- prjID string
- sdkID string
- rPath string
- listPrj bool
- cmdID string
- xGdbPid string
+ log *logrus.Logger
+ ccmd string
+ aargs []string
+ eenv []string
+ agentURL string
+ serverURL string
+ prjID string
+ sdkID string
+ rPath string
+ listPrj bool
+ cmdID string
+ xGdbPid string
httpCli *common.HTTPClient
ioSock *sio_client.Client
@@ -76,8 +77,10 @@ func NewGdbXds(log *logrus.Logger, args []string, env []string) *GdbXds {
// SetConfig set additional config fields
func (g *GdbXds) SetConfig(name string, value interface{}) error {
switch name {
- case "uri":
- g.uri = value.(string)
+ case "agentURL":
+ g.agentURL = value.(string)
+ case "serverURL":
+ g.serverURL = value.(string)
case "prjID":
g.prjID = value.(string)
case "sdkID":
@@ -99,9 +102,15 @@ func (g *GdbXds) Init() (int, error) {
g.cmdID = ""
// Define HTTP and WS url
- baseURL := g.uri
- if !strings.HasPrefix(g.uri, "http://") {
- baseURL = "http://" + g.uri
+ baseURL := g.agentURL
+
+ // Allow to only set port number
+ if match, _ := regexp.MatchString("^([0-9]+)$", baseURL); match {
+ baseURL = "http://localhost:" + g.agentURL
+ }
+ // Add http prefix if missing
+ if baseURL != "" && !strings.HasPrefix(g.agentURL, "http://") {
+ baseURL = "http://" + g.agentURL
}
// Create HTTP client
@@ -133,8 +142,25 @@ func (g *GdbXds) Init() (int, error) {
}
g.log.Infoln("XDS agent & server version:", ver)
- // SEB Check that server is connected
+ // Get current config and update connection to server when needed
+ xdsConf := xaapiv1.APIConfig{}
+ if err := g.httpCli.Get("/config", &xdsConf); err != nil {
+ return int(syscallEBADE), err
+ }
// FIXME: add multi-servers support
+ idx := 0
+ svrCfg := xdsConf.Servers[idx]
+ if g.serverURL != "" && (svrCfg.URL != g.serverURL || !svrCfg.Connected) {
+ svrCfg.URL = g.serverURL
+ svrCfg.ConnRetry = 10
+ newCfg := xaapiv1.APIConfig{}
+ if err := g.httpCli.Post("/config", xdsConf, &newCfg); err != nil {
+ return int(syscallEBADE), err
+ }
+
+ } else if !svrCfg.Connected {
+ return int(syscallEBADE), fmt.Errorf("XDS server not connected (url=%s)", svrCfg.URL)
+ }
// Get XDS projects list
var data []byte
@@ -182,9 +208,29 @@ func (g *GdbXds) Init() (int, error) {
}
})
+ // SEB gdbPid := ""
iosk.On(xaapiv1.ExecOutEvent, func(ev xaapiv1.ExecOutMsg) {
if g.cbRead != nil {
g.cbRead(ev.Timestamp, ev.Stdout, ev.Stderr)
+ /*
+ stdout := ev.Stdout
+ // SEB
+ //New Thread 15139
+ if strings.Contains(stdout, "pid = ") {
+ re := regexp.MustCompile("pid = ([0-9]+)")
+ if res := re.FindAllStringSubmatch(stdout, -1); len(res) > 0 {
+ gdbPid = res[0][1]
+ }
+ g.log.Errorf("SEB FOUND THREAD in '%s' => gdbPid=%s", stdout, gdbPid)
+ }
+ if gdbPid != "" && g.xGdbPid != "" && strings.Contains(stdout, gdbPid) {
+ g.log.Errorf("SEB THREAD REPLACE 1 stdout=%s", stdout)
+ stdout = strings.Replace(stdout, gdbPid, g.xGdbPid, -1)
+ g.log.Errorf("SEB THREAD REPLACE 2 stdout=%s", stdout)
+ }
+
+ g.cbRead(ev.Timestamp, stdout, ev.Stderr)
+ */
}
})
@@ -261,7 +307,7 @@ func (g *GdbXds) Start(inferiorTTY bool) (int, error) {
CmdTimeout: -1, // no timeout, end when stdin close or command exited normally
}
- g.log.Infof("POST %s/exec %v", g.uri, args)
+ g.log.Infof("POST %s/exec %v", g.agentURL, args)
res := xaapiv1.ExecResult{}
err = g.httpCli.Post("/exec", args, &res)
if err != nil {
diff --git a/main.go b/main.go
index 81b9154..4cc05e6 100644
--- a/main.go
+++ b/main.go
@@ -90,7 +90,8 @@ func exitError(code syscall.Errno, f string, a ...interface{}) {
// main
func main() {
- var uri, prjID, rPath, logLevel, logFile, sdkid, confFile, gdbNative string
+ var agentURL, serverURL string
+ var prjID, rPath, logLevel, logFile, sdkid, confFile, gdbNative string
var listProject bool
var err error
@@ -106,7 +107,7 @@ func main() {
log.Out = fdL
log.Level = logrus.DebugLevel
- uri = "localhost:8000"
+ agentURL = "localhost:8000"
logLevel = defaultLogLevel
// Create a new App instance
@@ -166,9 +167,14 @@ func main() {
Destination: &sdkid,
},
EnvVar{
+ Name: "XDS_AGENT_URL",
+ Usage: "local XDS agent url",
+ Destination: &agentURL,
+ },
+ EnvVar{
Name: "XDS_SERVER_URL",
- Usage: "remote XDS server url",
- Destination: &uri,
+ Usage: "overwrite remote XDS server url (default value set in xds-agent-config.json file)",
+ Destination: &serverURL,
},
}
@@ -295,7 +301,8 @@ endloop:
gdb = NewGdbNative(log, gdbArgs, env)
} else {
gdb = NewGdbXds(log, gdbArgs, env)
- gdb.SetConfig("uri", uri)
+ gdb.SetConfig("agentURL", agentURL)
+ gdb.SetConfig("serverURL", serverURL)
gdb.SetConfig("prjID", prjID)
gdb.SetConfig("sdkID", sdkid)
gdb.SetConfig("rPath", rPath)
@@ -574,9 +581,9 @@ func loadConfigEnvFile(confFile, gdbCmdFile string) (map[string]string, string,
All commented lines (#) in gdb command file that start with ':XDS-ENV:' prefix
will be considered as XDS env commands. For example the 3 syntaxes below
are supported:
- # :XDS-ENV: XDS_PROJECT_ID=IW7B4EE-DBY4Z74_myProject
- #:XDS-ENV:XDS_SDK_ID=poky-agl_aarch64_3.99.1+snapshot
- # :XDS-ENV: export XDS_SERVER_URL=localhost:8800
+ # :XDS-ENV: XDS_PROJECT_ID=4021617e-ced0-11e7-acd2-3c970e49ad9b
+ #:XDS-ENV:XDS_SDK_ID=06c0e95a-e215-3a5a-b373-f677c0dabd3b
+ # :XDS-ENV: export XDS_AGENT_URL=localhost:8800
*/
func extractEnvFromCmdFile(cmdFile string) (string, error) {
if !common.Exists(cmdFile) {