From: Sebastien Douheret Date: Wed, 30 Aug 2017 16:29:00 +0000 (+0200) Subject: Don't try to send signal while gdb is not started. X-Git-Tag: v0.1.0~2 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fxds%2Fxds-gdb.git;a=commitdiff_plain;h=662dd0f910150228ba93096d77637f697c2c3ed7 Don't try to send signal while gdb is not started. --- diff --git a/Makefile b/Makefile index ee8e5e2..e4973ad 100644 --- a/Makefile +++ b/Makefile @@ -94,6 +94,7 @@ package-all: @echo " WARNING: build on Windows not supported for now." @echo "# Build darwin amd64..." GOOS=darwin GOARCH=amd64 RELEASE=1 make -f $(ROOT_SRCDIR)/Makefile package + make -f $(ROOT_SRCDIR)/Makefile clean vendor: tools/glide glide.yaml ./tools/glide install --strip-vendor diff --git a/gdb-native.go b/gdb-native.go index a4e6189..4bae3d3 100644 --- a/gdb-native.go +++ b/gdb-native.go @@ -151,6 +151,9 @@ func (g *GdbNative) Write(args ...interface{}) error { // SendSignal is used to send a signal to remote process/gdb func (g *GdbNative) SendSignal(sig os.Signal) error { + if g.exeCmd == nil { + return fmt.Errorf("exeCmd not initialized") + } return g.exeCmd.Process.Signal(sig) } diff --git a/gdb-xds.go b/gdb-xds.go index bb8ad2f..22e13ed 100644 --- a/gdb-xds.go +++ b/gdb-xds.go @@ -76,6 +76,9 @@ func (g *GdbXds) SetConfig(name string, value interface{}) error { // Init initializes gdb XDS func (g *GdbXds) Init() (int, error) { + // Reset command ID (also used to enable sending of signals) + g.cmdID = "" + // Define HTTP and WS url baseURL := g.uri if !strings.HasPrefix(g.uri, "http://") { @@ -167,6 +170,7 @@ func (g *GdbXds) Close() error { g.cbOnExit = nil g.cbRead = nil g.cbInferiorRead = nil + g.cmdID = "" return nil } @@ -285,6 +289,10 @@ func (g *GdbXds) Write(args ...interface{}) error { // SendSignal is used to send a signal to remote process/gdb func (g *GdbXds) SendSignal(sig os.Signal) error { + if g.cmdID == "" { + return fmt.Errorf("cmdID not set") + } + var body []byte body, err := json.Marshal(apiv1.ExecSignalArgs{ CmdID: g.cmdID,