return null_ptid;
}
- /* Since the stub is not sending a process id, then default to
- what's in inferior_ptid, unless it's null at this point. If so,
+ /* Since the stub is not sending a process id, default to what's
+ current_inferior, unless it doesn't have a PID yet. If so,
then since there's no way to know the pid of the reported
threads, use the magic number. */
- if (inferior_ptid == null_ptid)
+ inferior *inf = current_inferior ();
+ if (inf->pid == 0)
pid = magic_null_ptid.pid ();
else
- pid = inferior_ptid.pid ();
+ pid = inf->pid;
if (obuf)
*obuf = pp;
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2020-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/>. */
+
+/* This program is intended to be started outside of GDB, and then
+ attached to by GDB. */
+
+#include <unistd.h>
+
+int
+main ()
+{
+ /* Don't run forever in case GDB crashes and DejaGNU fails to kill
+ this program. */
+ alarm (10);
+
+ while (1)
+ usleep (1);
+
+ return 0;
+}
--- /dev/null
+# This testcase is part of GDB, the GNU debugger.
+
+# Copyright 2020-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 attaching to a process, as a second inferior, through a
+# gdbserver that does not support multi-process extensions.
+
+load_lib gdbserver-support.exp
+
+standard_testfile
+
+if {![can_spawn_for_attach]} {
+ return
+}
+
+if {[build_executable "build" $testfile $srcfile {debug}] == -1} {
+ return -1
+}
+
+proc test {target_non_stop} {
+ global binfile
+
+ save_vars { ::GDBFLAGS } {
+ # If GDB and GDBserver are both running locally, set the sysroot to avoid
+ # reading files via the remote protocol.
+ if { ![is_remote host] && ![is_remote target] } {
+ set ::GDBFLAGS "${::GDBFLAGS} -ex \"set sysroot\""
+ }
+ set ::GDBFLAGS \
+ "${::GDBFLAGS} -ex \"set remote multiprocess-feature-packet off\""
+ set ::GDBFLAGS \
+ "${::GDBFLAGS} -ex \"maint set target-non-stop ${target_non_stop}\""
+ clean_restart ${binfile}
+ }
+
+ # Start the first inferior.
+ if {![runto_main]} {
+ return
+ }
+
+ # The second inferior is an extended remote.
+ gdb_test "add-inferior -no-connection" "Added inferior 2.*" \
+ "add the second inferior"
+ gdb_test "inferior 2" ".*Switching to inferior 2.*" \
+ "switch to inferior 2"
+ set res [gdbserver_start "--multi" ""]
+ set gdbserver_gdbport [lindex $res 1]
+ gdb_target_cmd "extended-remote" $gdbserver_gdbport
+
+ # Start a program, then attach to it.
+ set spawn_id_list [spawn_wait_for_attach [list $binfile]]
+ set test_spawn_id [lindex $spawn_id_list 0]
+ set testpid [spawn_id_get_pid $test_spawn_id]
+ gdb_test "attach $testpid" \
+ "Attaching to Remote target.*" \
+ "attach to the program via remote"
+
+ # Check that we have two threads. Bad GDB duplicated the
+ # thread coming from the remote when target-non-stop is off;
+ # or hanged during attach when target-non-stop is on.
+ gdb_test "info threads" \
+ [multi_line \
+ " Id\[^\r\n\]+" \
+ " 1\.1\[^\r\n\]+" \
+ ". 2\.1\[^\r\n\]+"
+ ]
+
+ # Clean the spawned process and gdbserver.
+ gdbserver_exit 0
+ kill_wait_spawned_process $test_spawn_id
+}
+
+foreach_with_prefix target_non_stop {off on} {
+ test $target_non_stop
+}