Fixed error about no env config file.
[src/xds/xds-gdb.git] / main.go
diff --git a/main.go b/main.go
index dc1d25b..87de43c 100644 (file)
--- a/main.go
+++ b/main.go
@@ -123,7 +123,7 @@ func main() {
                },
                EnvVar{
                        Name:        "XDS_LOGFILE",
-                       Usage:       "logging file",
+                       Usage:       "logging file (default: " + logFileInitial + ")",
                        Destination: &logFile,
                },
                EnvVar{
@@ -409,6 +409,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 +425,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)
                                }
@@ -510,9 +524,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
                                }
                        }