X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=main.go;h=81b9154a38260d09cad6912a6146173287bbbfac;hb=fa4dd5b6cdaff7173b24eafe2d2f22a4905aac39;hp=4302e9c9fb9afddbd9c233ce1516b570ff6c8598;hpb=68ac563c8ce709fe55d3cf38ea230ea78d633d6a;p=src%2Fxds%2Fxds-gdb.git diff --git a/main.go b/main.go index 4302e9c..81b9154 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,23 @@ -// xds-gdb: a wrapper on gdb tool for X(cross) Development System. +/* + * Copyright (C) 2017 "IoT.bzh" + * Author Sebastien Douheret + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * xds-gdb: a wrapper on gdb tool for X(cross) Development System. + */ + package main import ( @@ -43,7 +62,7 @@ var logFileInitial = "/tmp/xds-gdb.log" // Application details const ( - appCopyright = "Apache-2.0" + appCopyright = "Copyright (C) 2017 IoT.bzh - Apache-2.0" defaultLogLevel = "warning" ) @@ -123,7 +142,7 @@ func main() { }, EnvVar{ Name: "XDS_LOGFILE", - Usage: "logging file", + Usage: "logging file (default: " + logFileInitial + ")", Destination: &logFile, }, EnvVar{ @@ -345,7 +364,7 @@ endloop: // Handle client tty / pts if clientPty != "" { - log.Infoln("Client tty detected: %v\n", clientPty) + log.Infoln("Client tty detected: %v", clientPty) cpFd, err := os.OpenFile(clientPty, os.O_RDWR, 0) if err != nil { @@ -360,7 +379,7 @@ endloop: sc := bufio.NewScanner(reader) for sc.Scan() { data := sc.Text() - iosk.Emit(apiv1.ExecInferiorInEvent, data+"\n") + iosk.Emit(xaapiv1.ExecInferiorInEvent, data+"\n") log.Debugf("Inferior IN: <%v>", data) } if sc.Err() != nil { @@ -409,6 +428,10 @@ endloop: paranoia := 600 reader := bufio.NewReader(os.Stdin) + // Enable workaround to correctly close connection + // except if XDS_GDBSERVER_EXIT_NOFIX is defined + _, gdbExitNoFix := os.LookupEnv("XDS_GDBSERVER_EXIT_NOFIX") + for { sc := bufio.NewScanner(reader) for sc.Scan() { @@ -421,6 +444,16 @@ endloop: log.Debugf("OVERWRITE %s -> %s", key, value) } } + + // Send SIGINT to stop debugged process execution before sending -gdb-exit command + if !gdbExitNoFix && strings.Contains(command, "-gdb-exit") { + log.Infof("Detection of -gdb-exit, exiting...") + if err := gdb.SendSignal(syscall.SIGINT); err != nil { + log.Errorf("Error while sending signal SIGINT : %s", err.Error()) + } + time.Sleep(time.Millisecond * 200) + } + gdb.Write(command + "\n") log.Debugf("Send: <%v>", command) } @@ -446,8 +479,13 @@ endloop: go func() { for { sig := <-sigs + + if isIgnoredSignal(sig) { + return + } + if err := gdb.SendSignal(sig); err != nil { - log.Errorf("Error while sending signal: %s", err.Error()) + log.Errorf("Error while sending signal %v : %s", sig, err.Error()) } } }() @@ -503,9 +541,10 @@ func loadConfigEnvFile(confFile, gdbCmdFile string) (map[string]string, string, path.Join(curDir, "target"), path.Join(u.HomeDir, ".config", "xds"), } { - confFile = path.Join(d, xdsEnvFile) - log.Infof("Search config in %s", confFile) - if common.Exists(confFile) { + cf := path.Join(d, xdsEnvFile) + log.Infof("Search config in %s", cf) + if common.Exists(cf) { + confFile = cf break } }