diff options
-rw-r--r-- | gdb/infcmd.c | 8 | ||||
-rw-r--r-- | gdb/testsuite/gdb.multi/start-inferior-specific-other.c | 34 | ||||
-rw-r--r-- | gdb/testsuite/gdb.multi/start-inferior-specific.c | 31 | ||||
-rw-r--r-- | gdb/testsuite/gdb.multi/start-inferior-specific.exp | 61 |
4 files changed, 133 insertions, 1 deletions
diff --git a/gdb/infcmd.c b/gdb/infcmd.c index c03ca10..bf4a68e 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -423,7 +423,13 @@ run_command_1 (const char *args, int from_tty, enum run_how run_how) /* Insert temporary breakpoint in main function if requested. */ if (run_how == RUN_STOP_AT_MAIN) { - std::string arg = string_printf ("-qualified %s", main_name ()); + /* To avoid other inferiors hitting this breakpoint, make it + inferior-specific using a condition. A better solution would be to + have proper inferior-specific breakpoint support, in the breakpoint + machinery. We could then avoid inserting a breakpoint in the program + spaces unrelated to this inferior. */ + std::string arg = string_printf ("-qualified %s if $_inferior == %d", main_name (), + current_inferior ()->num); tbreak_command (arg.c_str (), 0); } diff --git a/gdb/testsuite/gdb.multi/start-inferior-specific-other.c b/gdb/testsuite/gdb.multi/start-inferior-specific-other.c new file mode 100644 index 0000000..17a06a5 --- /dev/null +++ b/gdb/testsuite/gdb.multi/start-inferior-specific-other.c @@ -0,0 +1,34 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <unistd.h> + +__attribute__((constructor)) +static void +ctor (void) +{ + sleep (2); +} + +int +main (int argc, const char **argv) +{ + /* We don't want this program finishing and causing spurious "inferior + exited" notifications in GDB, so keep sleeping here. */ + sleep (60); + return 0; +} diff --git a/gdb/testsuite/gdb.multi/start-inferior-specific.c b/gdb/testsuite/gdb.multi/start-inferior-specific.c new file mode 100644 index 0000000..930010c --- /dev/null +++ b/gdb/testsuite/gdb.multi/start-inferior-specific.c @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include <unistd.h> + +__attribute__((constructor)) +static void +ctor (void) +{ + sleep (4); +} + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.multi/start-inferior-specific.exp b/gdb/testsuite/gdb.multi/start-inferior-specific.exp new file mode 100644 index 0000000..45e8e8e --- /dev/null +++ b/gdb/testsuite/gdb.multi/start-inferior-specific.exp @@ -0,0 +1,61 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test that "start"ing an inferior does not inadvertently stop in another +# inferior. +# +# To achieve this, we start inferior 1 in background, which sleeps for a bit +# before reaching its main function. We then "start" inferior 2, which also +# sleeps before reaching its main function. The goal is that inferior 1 +# "crosses" inferior 2's start breakpoint (at the time of writing this test, the +# breakpoint inserted for start is global and has locations in both inferiors). +# A buggy GDB would report a breakpoint hit in inferior 1. + +standard_testfile .c -other.c + +if { [use_gdb_stub] } { + return +} + +set srcfile_other ${srcfile2} +set binfile_other ${binfile}-other + +if { [build_executable ${testfile}.exp ${binfile} "${srcfile}" {debug}] != 0 } { + return -1 +} + +if { [build_executable ${testfile}.exp ${binfile_other} "${srcfile_other}" {debug}] != 0 } { + return -1 +} + +proc do_test {} { + # With remote, to be able to start an inferior while another one is + # running, we need to use the non-stop variant of the protocol. + save_vars { ::GDBFLAGS } { + if { [target_info gdb_protocol] == "extended-remote"} { + append ::GDBFLAGS " -ex \"maintenance set target-non-stop on\"" + } + + clean_restart ${::binfile_other} + } + + gdb_test -no-prompt-anchor "run&" "Starting program: .*" "start background inferior" + gdb_test "add-inferior" "Added inferior 2.*" + gdb_test "inferior 2" "Switching to inferior 2.*" + gdb_file_cmd ${::binfile} + gdb_test "start" "Thread 2.1 .* hit Temporary breakpoint .*" +} + +do_test |