diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index b04a50d..76a027f 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -2312,7 +2312,8 @@ gdbserver_usage (FILE *stream) " --debug Enable general debugging output.\n" " --remote-debug Enable remote protocol debugging output.\n" " --version Display version information and exit.\n" - " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n"); + " --wrapper WRAPPER -- Run WRAPPER to start new programs.\n" + " --once Exit after the first connection closed.\n"); if (REPORT_BUGS_TO[0] && stream == stdout) fprintf (stream, "Report bugs to \"%s\".\n", REPORT_BUGS_TO); } @@ -2536,6 +2537,8 @@ main (int argc, char *argv[]) } } } + else if (strcmp (*next_arg, "--once") == 0) + exit_requested = 1; else { fprintf (stderr, "Unknown argument: %s\n", *next_arg); diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp index 3a098ae..c045c5f 100644 --- a/gdb/testsuite/lib/gdbserver-support.exp +++ b/gdb/testsuite/lib/gdbserver-support.exp @@ -218,10 +218,16 @@ proc gdbserver_start { options arguments } { # Fire off the debug agent. set gdbserver_command "$gdbserver" + + # GDB client could accidentally connect to a stale server. + append gdbserver_command " --once" + if { $options != "" } { append gdbserver_command " $options" } + append gdbserver_command " :$portnum" + if { $arguments != "" } { append gdbserver_command " $arguments" }