* [PATCH 0/2] Fix "thread find" with multi inferior/target (PR gdb/26631)
@ 2020-09-17 18:00 Pedro Alves
2020-09-17 18:00 ` [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases Pedro Alves
2020-09-17 18:00 ` [PATCH 2/2] Fix "thread find" with multiple inferiors/targets (PR gdb/26631) Pedro Alves
0 siblings, 2 replies; 8+ messages in thread
From: Pedro Alves @ 2020-09-17 18:00 UTC (permalink / raw)
To: gdb-patches
"thread find" with multiple inferiors got broken with the multi-target
work. Patch #2 fixes it. Patch #1 is a preparatory patch for the
testcase in patch #2.
Pedro Alves (2):
Split gdb.multi/multi-target.exp into separate testcases
Fix "thread find" with multiple inferiors/targets (PR gdb/26631)
gdb/testsuite/gdb.multi/mtarg-continue.exp | 105 +++++
gdb/testsuite/gdb.multi/mtarg-info-inferiors.exp | 110 +++++
gdb/testsuite/gdb.multi/mtarg-interrupt.exp | 79 ++++
gdb/testsuite/gdb.multi/mtarg-no-resumed.exp | 90 ++++
gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp | 85 ++++
gdb/testsuite/gdb.multi/mtarg-thread-find.exp | 106 +++++
gdb/testsuite/gdb.multi/multi-target.exp | 546 -----------------------
gdb/testsuite/gdb.multi/multi-target.exp.tcl | 185 ++++++++
gdb/thread.c | 6 +
9 files changed, 766 insertions(+), 546 deletions(-)
create mode 100644 gdb/testsuite/gdb.multi/mtarg-continue.exp
create mode 100644 gdb/testsuite/gdb.multi/mtarg-info-inferiors.exp
create mode 100644 gdb/testsuite/gdb.multi/mtarg-interrupt.exp
create mode 100644 gdb/testsuite/gdb.multi/mtarg-no-resumed.exp
create mode 100644 gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp
create mode 100644 gdb/testsuite/gdb.multi/mtarg-thread-find.exp
delete mode 100644 gdb/testsuite/gdb.multi/multi-target.exp
create mode 100644 gdb/testsuite/gdb.multi/multi-target.exp.tcl
base-commit: 9519b2eea05637faa380a68fd679a950176de6db
--
2.14.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases
2020-09-17 18:00 [PATCH 0/2] Fix "thread find" with multi inferior/target (PR gdb/26631) Pedro Alves
@ 2020-09-17 18:00 ` Pedro Alves
2020-09-17 19:16 ` Simon Marchi
2020-09-17 19:41 ` Simon Marchi
2020-09-17 18:00 ` [PATCH 2/2] Fix "thread find" with multiple inferiors/targets (PR gdb/26631) Pedro Alves
1 sibling, 2 replies; 8+ messages in thread
From: Pedro Alves @ 2020-09-17 18:00 UTC (permalink / raw)
To: gdb-patches
gdb.multi/multi-target.exp sets up a debug environment with multiple
gdbservers, multiple native processes, and multiple cores, which has
proved useful for exercising a number of multi-target scenarios.
But, as we add more tests to gdb.base/multi-target.exp, it is growing
a bit too large (making a bit cumbersome to debug) and too slow to run
(if you have glibc debug info).
This commit thus splits the multi-target.exp into several testcases,
one per use case. The common setup code is moved to a new
multi-target.exp.tcl file that is included by all the resulting
multi-target testcases.
gdb/testsuite/ChangeLog:
* gdb.multi/mtarg-continue.exp: New file, factored out from
multi-target.exp.
* gdb.multi/mtarg-info-inferiors.exp: New file, factored out from
multi-target.exp.
* gdb.multi/mtarg-interrupt.exp: New file, factored out from
multi-target.exp.
* gdb.multi/mtarg-no-resumed.exp: New file, factored out from
multi-target.exp.
* gdb.multi/mtarg-ping-pong-next.exp: New file, factored out from
multi-target.exp.
* gdb.multi/multi-target.exp.tcl: New file, factored out from
multi-target.exp.
* gdb.multi/multi-target.exp: Delete.
---
gdb/testsuite/gdb.multi/mtarg-continue.exp | 105 +++++
gdb/testsuite/gdb.multi/mtarg-info-inferiors.exp | 110 +++++
gdb/testsuite/gdb.multi/mtarg-interrupt.exp | 79 ++++
gdb/testsuite/gdb.multi/mtarg-no-resumed.exp | 90 ++++
gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp | 85 ++++
gdb/testsuite/gdb.multi/multi-target.exp | 546 -----------------------
gdb/testsuite/gdb.multi/multi-target.exp.tcl | 185 ++++++++
7 files changed, 654 insertions(+), 546 deletions(-)
create mode 100644 gdb/testsuite/gdb.multi/mtarg-continue.exp
create mode 100644 gdb/testsuite/gdb.multi/mtarg-info-inferiors.exp
create mode 100644 gdb/testsuite/gdb.multi/mtarg-interrupt.exp
create mode 100644 gdb/testsuite/gdb.multi/mtarg-no-resumed.exp
create mode 100644 gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp
delete mode 100644 gdb/testsuite/gdb.multi/multi-target.exp
create mode 100644 gdb/testsuite/gdb.multi/multi-target.exp.tcl
diff --git a/gdb/testsuite/gdb.multi/mtarg-continue.exp b/gdb/testsuite/gdb.multi/mtarg-continue.exp
new file mode 100644
index 00000000000..15a77b8ea85
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/mtarg-continue.exp
@@ -0,0 +1,105 @@
+# Copyright 2017-2020 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 "continue" to breakpoints in different targets. In non-stop
+# mode, also tests "interrupt -a".
+
+source $srcdir/$subdir/multi-target.exp.tcl
+
+if {![mtarg_prepare]} {
+ return
+}
+
+proc test_continue {non-stop} {
+ if {![setup ${non-stop}]} {
+ untested "setup failed"
+ return
+ }
+
+ proc set_break {inf} {
+ gdb_test "break function${inf} thread ${inf}.1" \
+ "Breakpoint .* function${inf}\\..*"
+ }
+
+ # Select inferior INF, and then run to a breakpoint on inferior
+ # INF+1.
+ proc test_continue_inf {inf} {
+ upvar 1 non-stop non-stop
+
+ global gdb_prompt
+ delete_breakpoints
+
+ set next_inf [next_live_inferior $inf]
+
+ gdb_test "inferior $inf" "Switching to inferior $inf.*"
+ set_break $next_inf
+
+ if {${non-stop} == "off"} {
+ gdb_test "continue" "hit Breakpoint .* function${next_inf}.*"
+ } else {
+ set msg "continue"
+ gdb_test_multiple "continue -a&" $msg {
+ -re "Continuing.*$gdb_prompt " {
+ pass $msg
+ }
+ }
+
+ set msg "hit bp"
+ gdb_test_multiple "" $msg {
+ -re "hit Breakpoint .* function${next_inf}" {
+ pass $msg
+ }
+ }
+
+ set msg "stop all threads"
+ gdb_test_multiple "interrupt -a" $msg {
+ -re "$gdb_prompt " {
+ for {set i 0} {$i < 7} {incr i} {
+ set ok 0
+ gdb_test_multiple "" $msg {
+ -re "Thread\[^\r\n\]*stopped\\." {
+ set ok 1
+ }
+ }
+ if {!$ok} {
+ break
+ }
+ }
+ gdb_assert $ok $msg
+ }
+ }
+ }
+ }
+
+ for {set i 1} {$i <= 5} {incr i} {
+ if {$i == 3} {
+ # This is a core inferior.
+ continue
+ }
+
+ with_test_prefix "inf$i" {
+ test_continue_inf $i
+ }
+ }
+}
+
+# Some basic "continue" + breakpoints tests.
+with_test_prefix "continue" {
+ foreach_with_prefix non-stop {"off" "on"} {
+ test_continue ${non-stop}
+ }
+}
+
+mtarg_cleanup
diff --git a/gdb/testsuite/gdb.multi/mtarg-info-inferiors.exp b/gdb/testsuite/gdb.multi/mtarg-info-inferiors.exp
new file mode 100644
index 00000000000..8b5a6227761
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/mtarg-info-inferiors.exp
@@ -0,0 +1,110 @@
+# Copyright 2017-2020 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 "info inferiors" and "info connections" with multiple targets.
+
+source $srcdir/$subdir/multi-target.exp.tcl
+
+if {![mtarg_prepare]} {
+ return
+}
+
+# Test "info inferiors" and "info connections". MULTI_PROCESS
+# indicates whether the multi-process feature of remote targets is
+# turned off or on.
+proc test_info_inferiors {multi_process} {
+ setup "off"
+
+ gdb_test_no_output \
+ "set remote multiprocess-feature-packet $multi_process"
+
+ # Get the description for inferior INF for when the current
+ # inferior id is CURRENT.
+ proc inf_desc {inf current} {
+ set ws "\[ \t\]+"
+ global decimal
+ upvar multi_process multi_process
+
+ if {($multi_process == "off") && ($inf == 2 || $inf == 5)} {
+ set desc "Remote target"
+ } else {
+ set desc "process ${decimal}"
+ }
+
+ set desc "${inf}${ws}${desc}${ws}"
+ if {$inf == $current} {
+ return "\\* $desc"
+ } else {
+ return " $desc"
+ }
+ }
+
+ # Get the "Num" column for CONNECTION for when the current
+ # inferior id is CURRENT_INF.
+ proc connection_num {connection current_inf} {
+ switch $current_inf {
+ "4" { set current_connection "1"}
+ "5" { set current_connection "4"}
+ "6" { set current_connection "5"}
+ default { set current_connection $current_inf}
+ }
+ if {$connection == $current_connection} {
+ return "\\* $connection"
+ } else {
+ return " $connection"
+ }
+ }
+
+ set ws "\[ \t\]+"
+ global decimal binfile
+
+ # Test "info connections" and "info inferior" by switching to each
+ # inferior one by one.
+ for {set inf 1} {$inf <= 6} {incr inf} {
+ with_test_prefix "inferior $inf" {
+ gdb_test "inferior $inf" "Switching to inferior $inf.*"
+
+ gdb_test "info connections" \
+ [multi_line \
+ "Num${ws}What${ws}Description${ws}" \
+ "[connection_num 1 $inf]${ws}native${ws}Native process${ws}" \
+ "[connection_num 2 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \
+ "[connection_num 3 $inf]${ws}core${ws}Local core dump file${ws}" \
+ "[connection_num 4 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \
+ "[connection_num 5 $inf]${ws}core${ws}Local core dump file${ws}" \
+ ]
+
+ gdb_test "info inferiors" \
+ [multi_line \
+ "Num${ws}Description${ws}Connection${ws}Executable${ws}" \
+ "[inf_desc 1 $inf]1 \\(native\\)${ws}${binfile}${ws}" \
+ "[inf_desc 2 $inf]2 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
+ "[inf_desc 3 $inf]3 \\(core\\)${ws}${binfile}${ws}" \
+ "[inf_desc 4 $inf]1 \\(native\\)${ws}${binfile}${ws}" \
+ "[inf_desc 5 $inf]4 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
+ "[inf_desc 6 $inf]5 \\(core\\)${ws}${binfile}${ws}" \
+ ]
+ }
+ }
+}
+
+# Test "info inferiors" and "info connections" commands.
+with_test_prefix "info-inferiors" {
+ foreach_with_prefix multi_process {"on" "off"} {
+ test_info_inferiors $multi_process
+ }
+}
+
+mtarg_cleanup
diff --git a/gdb/testsuite/gdb.multi/mtarg-interrupt.exp b/gdb/testsuite/gdb.multi/mtarg-interrupt.exp
new file mode 100644
index 00000000000..32f01947401
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/mtarg-interrupt.exp
@@ -0,0 +1,79 @@
+# Copyright 2017-2020 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 interrupting multiple targets with Ctrl-C.
+
+source $srcdir/$subdir/multi-target.exp.tcl
+
+if {![mtarg_prepare]} {
+ return
+}
+
+proc test_ctrlc {} {
+ if {![setup "off"]} {
+ untested "setup failed"
+ return
+ }
+
+ delete_breakpoints
+
+ # Select inferior INF, continue all inferiors, and then Ctrl-C.
+ proc test_ctrlc_inf {inf} {
+ global gdb_prompt
+
+ gdb_test "inferior $inf" "Switching to inferior $inf.*"
+
+ set msg "continue"
+ gdb_test_multiple "continue" $msg {
+ -re "Continuing" {
+ pass $msg
+ }
+ }
+
+ after 200 { send_gdb "\003" }
+
+ set msg "send_gdb control C"
+ gdb_test_multiple "" $msg {
+ -re "received signal SIGINT.*$gdb_prompt $" {
+ pass $msg
+ }
+ }
+
+ set msg "all threads stopped"
+ gdb_test_multiple "info threads" "$msg" {
+ -re "\\\(running\\\).*$gdb_prompt $" {
+ fail $msg
+ }
+ -re "$gdb_prompt $" {
+ pass $msg
+ }
+ }
+ }
+
+ for {set i 1} {$i <= 5} {incr i} {
+ if {$i == 3} {
+ # This is a core inferior.
+ continue
+ }
+
+ with_test_prefix "inf$i" {
+ test_ctrlc_inf $i
+ }
+ }
+}
+
+test_ctrlc
+
+mtarg_cleanup
diff --git a/gdb/testsuite/gdb.multi/mtarg-no-resumed.exp b/gdb/testsuite/gdb.multi/mtarg-no-resumed.exp
new file mode 100644
index 00000000000..262a7fd891e
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/mtarg-no-resumed.exp
@@ -0,0 +1,90 @@
+# Copyright 2017-2020 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 when there's a foreground execution command in progress, a
+# TARGET_WAITKIND_NO_RESUMED for a particular target is ignored when
+# other targets are still resumed.
+
+source $srcdir/$subdir/multi-target.exp.tcl
+
+if {![mtarg_prepare]} {
+ return
+}
+
+proc test_no_resumed_infs {inf_A inf_B} {
+ global gdb_prompt
+
+ if {![setup "off"]} {
+ untested "setup failed"
+ return
+ }
+
+ gdb_test "thread $inf_A.2" "Switching to thread $inf_A\.2 .*" \
+ "select thread of target A"
+
+ gdb_test_no_output "set scheduler-locking on"
+
+ gdb_test_multiple "continue &" "" {
+ -re "Continuing.*$gdb_prompt " {
+ pass $gdb_test_name
+ }
+ }
+
+ gdb_test "thread $inf_B.2" "Switching to thread $inf_B\.2 .*" \
+ "select thread of target B"
+ gdb_test "p exit_thread = 1" " = 1" \
+ "set the thread to exit on resumption"
+
+ # Wait 3 seconds. If we see any response from GDB, such as
+ # "No unwaited-for children left." it's a bug.
+ gdb_test_multiple "continue" "continue" {
+ -timeout 3
+ timeout {
+ pass $gdb_test_name
+ }
+ }
+
+ # Now stop the program (all targets).
+ send_gdb "\003"
+ gdb_test_multiple "" "send_gdb control C" {
+ -re "received signal SIGINT.*$gdb_prompt $" {
+ pass $gdb_test_name
+ }
+ }
+
+ gdb_test_multiple "info threads" "all threads stopped" {
+ -re "\\\(running\\\).*$gdb_prompt $" {
+ fail $gdb_test_name
+ }
+ -re "$gdb_prompt $" {
+ pass $gdb_test_name
+ }
+ }
+}
+
+# inferior 1 -> native
+# inferior 2 -> extended-remote 1
+# inferior 5 -> extended-remote 2
+set inferiors {1 2 5}
+foreach_with_prefix inf_A $inferiors {
+ foreach_with_prefix inf_B $inferiors {
+ if {$inf_A == $inf_B} {
+ continue
+ }
+ test_no_resumed_infs $inf_A $inf_B
+ }
+}
+
+mtarg_cleanup
diff --git a/gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp b/gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp
new file mode 100644
index 00000000000..551e383b6d1
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp
@@ -0,0 +1,85 @@
+# Copyright 2017-2020 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 "next" bouncing between two breakpoints in two threads running
+# in different targets.
+
+source $srcdir/$subdir/multi-target.exp.tcl
+
+if {![mtarg_prepare]} {
+ return
+}
+
+proc test_ping_pong_next {} {
+ global srcfile
+
+ if {![setup "off"]} {
+ untested "setup failed"
+ return
+ }
+
+ # block/unblock inferiors 1 and 2 according to INF1 and INF2.
+ proc block {inf1 inf2} {
+ gdb_test "thread apply 1.1 p wait_for_gdb = $inf1" " = $inf1"
+ gdb_test "thread apply 2.1 p wait_for_gdb = $inf2" " = $inf2"
+ }
+
+ # We're use inferiors 1 and 2. Make sure they're really connected
+ # to different targets.
+ gdb_test "thread apply 1.1 maint print target-stack" \
+ "- native.*"
+ gdb_test "thread apply 2.1 maint print target-stack" \
+ "- extended-remote.*"
+
+ # Set two breakpoints, one for each of inferior 1 and 2. Inferior
+ # 1 is running on the native target, and inferior 2 is running on
+ # extended-gdbserver. Run to breakpoint 1 to gets things started.
+ set line1 [gdb_get_line_number "set break 1 here"]
+ set line2 [gdb_get_line_number "set break 2 here"]
+
+ gdb_test "thread 1.1" "Switching to thread 1.1 .*"
+
+ gdb_test "break $srcfile:$line1 thread 1.1" \
+ "Breakpoint .*$srcfile:$line1\\..*"
+
+ gdb_test "continue" "hit Breakpoint .*"
+
+ gdb_test "break $srcfile:$line2 thread 2.1" \
+ "Breakpoint .*$srcfile:$line2\\..*"
+
+ # Now block inferior 1 and issue "next". We should stop at the
+ # breakpoint for inferior 2, given schedlock off.
+ with_test_prefix "next inf 1" {
+ block 1 0
+ gdb_test "next" "Thread 2.1 .*hit Breakpoint .*$srcfile:$line2.*"
+ }
+
+ # Now unblock inferior 2 and block inferior 1. "next" should run
+ # into the breakpoint in inferior 1.
+ with_test_prefix "next inf 2" {
+ block 0 1
+ gdb_test "next" "Thread 1.1 .*hit Breakpoint .*$srcfile:$line1.*"
+ }
+
+ # Try nexting inferior 1 again.
+ with_test_prefix "next inf 1 again" {
+ block 1 0
+ gdb_test "next" "Thread 2.1 .*hit Breakpoint .*$srcfile:$line2.*"
+ }
+}
+
+test_ping_pong_next
+
+mtarg_cleanup
diff --git a/gdb/testsuite/gdb.multi/multi-target.exp b/gdb/testsuite/gdb.multi/multi-target.exp
deleted file mode 100644
index d19cee6595a..00000000000
--- a/gdb/testsuite/gdb.multi/multi-target.exp
+++ /dev/null
@@ -1,546 +0,0 @@
-# Copyright 2017-2020 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 multi-target features.
-
-load_lib gdbserver-support.exp
-
-if { [skip_gdbserver_tests] } {
- return 0
-}
-
-standard_testfile
-
-# The plain remote target can't do multiple inferiors.
-if {[target_info gdb_protocol] != ""} {
- return
-}
-
-if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \
- {debug pthreads}] } {
- return
-}
-
-# Keep a list of (inferior ID, spawn ID).
-set server_spawn_ids [list]
-
-proc connect_target_extended_remote {binfile num} {
- set res [gdbserver_start "--multi" ""]
- global server_spawn_ids server_spawn_id
- lappend server_spawn_ids $num $server_spawn_id
- set gdbserver_gdbport [lindex $res 1]
- return [gdb_target_cmd "extended-remote" $gdbserver_gdbport]
-}
-
-# Add and start inferior number NUM. Returns true on success, false
-# otherwise.
-proc add_inferior {num target binfile {gcorefile ""}} {
- # Start another inferior.
- gdb_test "add-inferior -no-connection" "Added inferior $num" \
- "add empty inferior $num"
- gdb_test "inferior $num" "Switching to inferior $num.*" \
- "switch to inferior $num"
- gdb_test "file ${binfile}" ".*" "load file in inferior $num"
- gdb_test_no_output "set remote exec-file ${binfile}" \
- "set remote-exec file in inferior $num"
-
- if {$target == "core"} {
- gdb_test "core $gcorefile" "Core was generated by.*" \
- "core [file tail $gcorefile], inf $num"
- return 1
- }
-
- if {$target == "extended-remote"} {
- if {[connect_target_extended_remote $binfile $num]} {
- return 0
- }
- }
- if ![runto "all_started"] then {
- return 0
- }
- delete_breakpoints
-
- return 1
-}
-
-proc prepare_core {} {
- global gcorefile gcore_created
- global binfile
-
- clean_restart ${binfile}
-
- if ![runto all_started] then {
- return -1
- }
-
- global testfile
- set gcorefile [standard_output_file $testfile.gcore]
- set gcore_created [gdb_gcore_cmd $gcorefile "save a core file"]
-}
-
-proc next_live_inferior {inf} {
- incr inf
- if {$inf == 3} {
- # 3 is a core.
- return 4
- }
- if {$inf > 5} {
- # 6 is a core.
- return 1
- }
-
- return $inf
-}
-
-# Clean up the server_spawn_ids.
-proc cleanup_gdbservers { } {
- global server_spawn_id
- global server_spawn_ids
- foreach { inferior_id spawn_id } $server_spawn_ids {
- set server_spawn_id $spawn_id
- gdb_test "inferior $inferior_id"
- gdbserver_exit 0
- }
- set server_spawn_ids [list]
-}
-
-# Return true on success, false otherwise.
-
-proc setup {non-stop} {
- global gcorefile gcore_created
- global binfile
-
- cleanup_gdbservers
- clean_restart ${binfile}
-
- # multi-target depends on target running in non-stop mode. Force
- # it on for remote targets, until this is the default.
- gdb_test_no_output "maint set target-non-stop on"
-
- gdb_test_no_output "set non-stop ${non-stop}"
-
- if ![runto all_started] then {
- return 0
- }
-
- delete_breakpoints
-
- # inferior 1 -> native
- # inferior 2 -> extended-remote
- # inferior 3 -> core
- # inferior 4 -> native
- # inferior 5 -> extended-remote
- # inferior 6 -> core
- if {![add_inferior 2 "extended-remote" $binfile]} {
- return 0
- }
- if {![add_inferior 3 "core" $binfile $gcorefile]} {
- return 0
- }
- if {![add_inferior 4 "native" $binfile]} {
- return 0
- }
- if {![add_inferior 5 "extended-remote" $binfile]} {
- return 0
- }
- if {![add_inferior 6 "core" $binfile $gcorefile]} {
- return 0
- }
-
- # For debugging.
- gdb_test "info threads" ".*"
-
- # Make "continue" resume all inferiors.
- if {${non-stop} == "off"} {
- gdb_test_no_output "set schedule-multiple on"
- }
-
- return 1
-}
-
-# Test "continue" to breakpoints in different targets. In non-stop
-# mode, also tests "interrupt -a".
-proc test_continue {non-stop} {
- if {![setup ${non-stop}]} {
- untested "setup failed"
- return
- }
-
- proc set_break {inf} {
- gdb_test "break function${inf} thread ${inf}.1" \
- "Breakpoint .* function${inf}\\..*"
- }
-
- # Select inferior INF, and then run to a breakpoint on inferior
- # INF+1.
- proc test_continue_inf {inf} {
- upvar 1 non-stop non-stop
-
- global gdb_prompt
- delete_breakpoints
-
- set next_inf [next_live_inferior $inf]
-
- gdb_test "inferior $inf" "Switching to inferior $inf.*"
- set_break $next_inf
-
- if {${non-stop} == "off"} {
- gdb_test "continue" "hit Breakpoint .* function${next_inf}.*"
- } else {
- set msg "continue"
- gdb_test_multiple "continue -a&" $msg {
- -re "Continuing.*$gdb_prompt " {
- pass $msg
- }
- }
-
- set msg "hit bp"
- gdb_test_multiple "" $msg {
- -re "hit Breakpoint .* function${next_inf}" {
- pass $msg
- }
- }
-
- set msg "stop all threads"
- gdb_test_multiple "interrupt -a" $msg {
- -re "$gdb_prompt " {
- for {set i 0} {$i < 7} {incr i} {
- set ok 0
- gdb_test_multiple "" $msg {
- -re "Thread\[^\r\n\]*stopped\\." {
- set ok 1
- }
- }
- if {!$ok} {
- break
- }
- }
- gdb_assert $ok $msg
- }
- }
- }
- }
-
- for {set i 1} {$i <= 5} {incr i} {
- if {$i == 3} {
- # This is a core inferior.
- continue
- }
-
- with_test_prefix "inf$i" {
- test_continue_inf $i
- }
- }
-}
-
-# Test interrupting multiple targets with Ctrl-C.
-
-proc test_ctrlc {} {
- if {![setup "off"]} {
- untested "setup failed"
- return
- }
-
- delete_breakpoints
-
- # Select inferior INF, continue all inferiors, and then Ctrl-C.
- proc test_ctrlc_inf {inf} {
- global gdb_prompt
-
- gdb_test "inferior $inf" "Switching to inferior $inf.*"
-
- set msg "continue"
- gdb_test_multiple "continue" $msg {
- -re "Continuing" {
- pass $msg
- }
- }
-
- after 200 { send_gdb "\003" }
-
- set msg "send_gdb control C"
- gdb_test_multiple "" $msg {
- -re "received signal SIGINT.*$gdb_prompt $" {
- pass $msg
- }
- }
-
- set msg "all threads stopped"
- gdb_test_multiple "info threads" "$msg" {
- -re "\\\(running\\\).*$gdb_prompt $" {
- fail $msg
- }
- -re "$gdb_prompt $" {
- pass $msg
- }
- }
- }
-
- for {set i 1} {$i <= 5} {incr i} {
- if {$i == 3} {
- # This is a core inferior.
- continue
- }
-
- with_test_prefix "inf$i" {
- test_ctrlc_inf $i
- }
- }
-}
-
-# Test "next" bouncing between two breakpoints in two threads running
-# in different targets.
-proc test_ping_pong_next {} {
- global srcfile
-
- if {![setup "off"]} {
- untested "setup failed"
- return
- }
-
- # block/unblock inferiors 1 and 2 according to INF1 and INF2.
- proc block {inf1 inf2} {
- gdb_test "thread apply 1.1 p wait_for_gdb = $inf1" " = $inf1"
- gdb_test "thread apply 2.1 p wait_for_gdb = $inf2" " = $inf2"
- }
-
- # We're use inferiors 1 and 2. Make sure they're really connected
- # to different targets.
- gdb_test "thread apply 1.1 maint print target-stack" \
- "- native.*"
- gdb_test "thread apply 2.1 maint print target-stack" \
- "- extended-remote.*"
-
- # Set two breakpoints, one for each of inferior 1 and 2. Inferior
- # 1 is running on the native target, and inferior 2 is running on
- # extended-gdbserver. Run to breakpoint 1 to gets things started.
- set line1 [gdb_get_line_number "set break 1 here"]
- set line2 [gdb_get_line_number "set break 2 here"]
-
- gdb_test "thread 1.1" "Switching to thread 1.1 .*"
-
- gdb_test "break $srcfile:$line1 thread 1.1" \
- "Breakpoint .*$srcfile:$line1\\..*"
-
- gdb_test "continue" "hit Breakpoint .*"
-
- gdb_test "break $srcfile:$line2 thread 2.1" \
- "Breakpoint .*$srcfile:$line2\\..*"
-
- # Now block inferior 1 and issue "next". We should stop at the
- # breakpoint for inferior 2, given schedlock off.
- with_test_prefix "next inf 1" {
- block 1 0
- gdb_test "next" "Thread 2.1 .*hit Breakpoint .*$srcfile:$line2.*"
- }
-
- # Now unblock inferior 2 and block inferior 1. "next" should run
- # into the breakpoint in inferior 1.
- with_test_prefix "next inf 2" {
- block 0 1
- gdb_test "next" "Thread 1.1 .*hit Breakpoint .*$srcfile:$line1.*"
- }
-
- # Try nexting inferior 1 again.
- with_test_prefix "next inf 1 again" {
- block 1 0
- gdb_test "next" "Thread 2.1 .*hit Breakpoint .*$srcfile:$line2.*"
- }
-}
-
-# Test "info inferiors" and "info connections". MULTI_PROCESS
-# indicates whether the multi-process feature of remote targets is
-# turned off or on.
-proc test_info_inferiors {multi_process} {
- setup "off"
-
- gdb_test_no_output \
- "set remote multiprocess-feature-packet $multi_process"
-
- # Get the description for inferior INF for when the current
- # inferior id is CURRENT.
- proc inf_desc {inf current} {
- set ws "\[ \t\]+"
- global decimal
- upvar multi_process multi_process
-
- if {($multi_process == "off") && ($inf == 2 || $inf == 5)} {
- set desc "Remote target"
- } else {
- set desc "process ${decimal}"
- }
-
- set desc "${inf}${ws}${desc}${ws}"
- if {$inf == $current} {
- return "\\* $desc"
- } else {
- return " $desc"
- }
- }
-
- # Get the "Num" column for CONNECTION for when the current
- # inferior id is CURRENT_INF.
- proc connection_num {connection current_inf} {
- switch $current_inf {
- "4" { set current_connection "1"}
- "5" { set current_connection "4"}
- "6" { set current_connection "5"}
- default { set current_connection $current_inf}
- }
- if {$connection == $current_connection} {
- return "\\* $connection"
- } else {
- return " $connection"
- }
- }
-
- set ws "\[ \t\]+"
- global decimal binfile
-
- # Test "info connections" and "info inferior" by switching to each
- # inferior one by one.
- for {set inf 1} {$inf <= 6} {incr inf} {
- with_test_prefix "inferior $inf" {
- gdb_test "inferior $inf" "Switching to inferior $inf.*"
-
- gdb_test "info connections" \
- [multi_line \
- "Num${ws}What${ws}Description${ws}" \
- "[connection_num 1 $inf]${ws}native${ws}Native process${ws}" \
- "[connection_num 2 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \
- "[connection_num 3 $inf]${ws}core${ws}Local core dump file${ws}" \
- "[connection_num 4 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \
- "[connection_num 5 $inf]${ws}core${ws}Local core dump file${ws}" \
- ]
-
- gdb_test "info inferiors" \
- [multi_line \
- "Num${ws}Description${ws}Connection${ws}Executable${ws}" \
- "[inf_desc 1 $inf]1 \\(native\\)${ws}${binfile}${ws}" \
- "[inf_desc 2 $inf]2 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
- "[inf_desc 3 $inf]3 \\(core\\)${ws}${binfile}${ws}" \
- "[inf_desc 4 $inf]1 \\(native\\)${ws}${binfile}${ws}" \
- "[inf_desc 5 $inf]4 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
- "[inf_desc 6 $inf]5 \\(core\\)${ws}${binfile}${ws}" \
- ]
- }
- }
-}
-
-# Test that when there's a foreground execution command in progress, a
-# TARGET_WAITKIND_NO_RESUMED for a particular target is ignored when
-# other targets are still resumed.
-
-proc test_no_resumed {} {
- proc test_no_resumed_infs {inf_A inf_B} {
- global gdb_prompt
-
- if {![setup "off"]} {
- untested "setup failed"
- return
- }
-
- gdb_test "thread $inf_A.2" "Switching to thread $inf_A\.2 .*" \
- "select thread of target A"
-
- gdb_test_no_output "set scheduler-locking on"
-
- gdb_test_multiple "continue &" "" {
- -re "Continuing.*$gdb_prompt " {
- pass $gdb_test_name
- }
- }
-
- gdb_test "thread $inf_B.2" "Switching to thread $inf_B\.2 .*" \
- "select thread of target B"
- gdb_test "p exit_thread = 1" " = 1" \
- "set the thread to exit on resumption"
-
- # Wait 3 seconds. If we see any response from GDB, such as
- # "No unwaited-for children left." it's a bug.
- gdb_test_multiple "continue" "continue" {
- -timeout 3
- timeout {
- pass $gdb_test_name
- }
- }
-
- # Now stop the program (all targets).
- send_gdb "\003"
- gdb_test_multiple "" "send_gdb control C" {
- -re "received signal SIGINT.*$gdb_prompt $" {
- pass $gdb_test_name
- }
- }
-
- gdb_test_multiple "info threads" "all threads stopped" {
- -re "\\\(running\\\).*$gdb_prompt $" {
- fail $gdb_test_name
- }
- -re "$gdb_prompt $" {
- pass $gdb_test_name
- }
- }
- }
-
- # inferior 1 -> native
- # inferior 2 -> extended-remote 1
- # inferior 5 -> extended-remote 2
- set inferiors {1 2 5}
- foreach_with_prefix inf_A $inferiors {
- foreach_with_prefix inf_B $inferiors {
- if {$inf_A == $inf_B} {
- continue
- }
- test_no_resumed_infs $inf_A $inf_B
- }
- }
-}
-
-
-# Make a core file with two threads upfront. Several tests load the
-# same core file.
-prepare_core
-
-# Some basic "continue" + breakpoints tests.
-with_test_prefix "continue" {
- foreach_with_prefix non-stop {"off" "on"} {
- test_continue ${non-stop}
- }
-}
-
-# Some basic all-stop Ctrl-C tests.
-with_test_prefix "interrupt" {
- test_ctrlc
-}
-
-# Test ping-ponging between two targets with "next".
-with_test_prefix "ping-pong" {
- test_ping_pong_next
-}
-
-# Test "info inferiors" and "info connections" commands.
-with_test_prefix "info-inferiors" {
- foreach_with_prefix multi_process {"on" "off"} {
- test_info_inferiors $multi_process
- }
-}
-
-# Test TARGET_WAITKIND_NO_RESUMED handling with multiple targets.
-with_test_prefix "no-resumed" {
- test_no_resumed
-}
-
-cleanup_gdbservers
diff --git a/gdb/testsuite/gdb.multi/multi-target.exp.tcl b/gdb/testsuite/gdb.multi/multi-target.exp.tcl
new file mode 100644
index 00000000000..f098f075991
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/multi-target.exp.tcl
@@ -0,0 +1,185 @@
+# Copyright 2017-2020 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/>.
+
+# Common routines for testing multi-target features.
+
+load_lib gdbserver-support.exp
+
+standard_testfile multi-target.c
+
+# Keep a list of (inferior ID, spawn ID).
+set server_spawn_ids [list]
+
+proc connect_target_extended_remote {binfile num} {
+ set res [gdbserver_start "--multi" ""]
+ global server_spawn_ids server_spawn_id
+ lappend server_spawn_ids $num $server_spawn_id
+ set gdbserver_gdbport [lindex $res 1]
+ return [gdb_target_cmd "extended-remote" $gdbserver_gdbport]
+}
+
+# Add and start inferior number NUM. Returns true on success, false
+# otherwise.
+proc add_inferior {num target binfile {gcorefile ""}} {
+ # Start another inferior.
+ gdb_test "add-inferior -no-connection" "Added inferior $num" \
+ "add empty inferior $num"
+ gdb_test "inferior $num" "Switching to inferior $num.*" \
+ "switch to inferior $num"
+ gdb_test "file ${binfile}" ".*" "load file in inferior $num"
+ gdb_test_no_output "set remote exec-file ${binfile}" \
+ "set remote-exec file in inferior $num"
+
+ if {$target == "core"} {
+ gdb_test "core $gcorefile" "Core was generated by.*" \
+ "core [file tail $gcorefile], inf $num"
+ return 1
+ }
+
+ if {$target == "extended-remote"} {
+ if {[connect_target_extended_remote $binfile $num]} {
+ return 0
+ }
+ }
+ if ![runto "all_started"] then {
+ return 0
+ }
+ delete_breakpoints
+
+ return 1
+}
+
+proc prepare_core {} {
+ global gcorefile gcore_created
+ global binfile
+
+ clean_restart ${binfile}
+
+ if ![runto all_started] then {
+ return -1
+ }
+
+ global testfile
+ set gcorefile [standard_output_file $testfile.gcore]
+ set gcore_created [gdb_gcore_cmd $gcorefile "save a core file"]
+}
+
+proc next_live_inferior {inf} {
+ incr inf
+ if {$inf == 3} {
+ # 3 is a core.
+ return 4
+ }
+ if {$inf > 5} {
+ # 6 is a core.
+ return 1
+ }
+
+ return $inf
+}
+
+# Clean up the server_spawn_ids.
+proc cleanup_gdbservers { } {
+ global server_spawn_id
+ global server_spawn_ids
+ foreach { inferior_id spawn_id } $server_spawn_ids {
+ set server_spawn_id $spawn_id
+ gdb_test "inferior $inferior_id"
+ gdbserver_exit 0
+ }
+ set server_spawn_ids [list]
+}
+
+# Return true on success, false otherwise.
+
+proc setup {non-stop} {
+ global gcorefile gcore_created
+ global binfile
+
+ cleanup_gdbservers
+ clean_restart ${binfile}
+
+ # multi-target depends on target running in non-stop mode. Force
+ # it on for remote targets, until this is the default.
+ gdb_test_no_output "maint set target-non-stop on"
+
+ gdb_test_no_output "set non-stop ${non-stop}"
+
+ if ![runto all_started] then {
+ return 0
+ }
+
+ delete_breakpoints
+
+ # inferior 1 -> native
+ # inferior 2 -> extended-remote
+ # inferior 3 -> core
+ # inferior 4 -> native
+ # inferior 5 -> extended-remote
+ # inferior 6 -> core
+ if {![add_inferior 2 "extended-remote" $binfile]} {
+ return 0
+ }
+ if {![add_inferior 3 "core" $binfile $gcorefile]} {
+ return 0
+ }
+ if {![add_inferior 4 "native" $binfile]} {
+ return 0
+ }
+ if {![add_inferior 5 "extended-remote" $binfile]} {
+ return 0
+ }
+ if {![add_inferior 6 "core" $binfile $gcorefile]} {
+ return 0
+ }
+
+ # For debugging.
+ gdb_test "info threads" ".*"
+
+ # Make "continue" resume all inferiors.
+ if {${non-stop} == "off"} {
+ gdb_test_no_output "set schedule-multiple on"
+ }
+
+ return 1
+}
+
+proc mtarg_prepare {} {
+ global binfile srcfile
+
+ if { [skip_gdbserver_tests] } {
+ return 0
+ }
+
+ # The plain remote target can't do multiple inferiors.
+ if {[target_info gdb_protocol] != ""} {
+ return 0
+ }
+
+ if { [prepare_for_testing "failed to prepare" ${binfile} "${srcfile}" \
+ {debug pthreads}] } {
+ return 0
+ }
+
+ # Make a core file with two threads upfront. Several tests load
+ # the same core file.
+ prepare_core
+
+ return 1
+}
+
+proc mtarg_cleanup {} {
+ cleanup_gdbservers
+}
--
2.14.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] Fix "thread find" with multiple inferiors/targets (PR gdb/26631)
2020-09-17 18:00 [PATCH 0/2] Fix "thread find" with multi inferior/target (PR gdb/26631) Pedro Alves
2020-09-17 18:00 ` [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases Pedro Alves
@ 2020-09-17 18:00 ` Pedro Alves
2020-09-17 19:37 ` Simon Marchi
1 sibling, 1 reply; 8+ messages in thread
From: Pedro Alves @ 2020-09-17 18:00 UTC (permalink / raw)
To: gdb-patches
"thread find" with multiple inferiors got broken with the multi-target
work:
Thread 1 "gdb" hit Breakpoint 1, internal_error (...) at ../../src/gdbsupport/errors.cc:51
51 {
(top-gdb) bt
#0 internal_error (file=0xffffd4d0 <error: Cannot access memory at address 0xffffd4d0>, line=0, fmt=0x555556330320 "en_US.UTF-8") at ../../src/gdbsupport/errors.cc:51
#1 0x0000555555bca4c7 in target_thread_name (info=0x555556801290) at ../../src/gdb/target.c:2035
#2 0x0000555555beb07a in thread_find_command (arg=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/thread.c:1959
#3 0x000055555572ec49 in do_const_cfunc (c=0x555556786bc0, args=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/cli/cli-decode.c:95
#4 0x0000555555732abd in cmd_func (cmd=0x555556786bc0, args=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/cli/cli-decode.c:2181
#5 0x0000555555bf1245 in execute_command (p=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/top.c:664
#6 0x00005555559cad10 in catch_command_errors (command=0x555555bf0c31 <execute_command(char const*, int)>, arg=0x7fffffffe082 "thread find 1", from_tty=0) at ../../src/gdb/main.c:457
#7 0x00005555559cc33d in captured_main_1 (context=0x7fffffffdb60) at ../../src/gdb/main.c:1218
#8 0x00005555559cc571 in captured_main (data=0x7fffffffdb60) at ../../src/gdb/main.c:1243
#9 0x00005555559cc5e8 in gdb_main (args=0x7fffffffdb60) at ../../src/gdb/main.c:1268
#10 0x0000555555623816 in main (argc=17, argv=0x7fffffffdc78) at ../../src/gdb/gdb.c:32
The problem is that we're not switching to the inferior/target before
calling target methods, which trips on an assertion put in place
exactly to catch this sort of problem.
gdb/testsuite/ChangeLog:
* gdb.multi/mtarg-thread-find.exp: New file.
gdb/ChangeLog:
* thread.c (thread_find_command): Switch inferior before
calling target methods.
---
gdb/testsuite/gdb.multi/mtarg-thread-find.exp | 106 ++++++++++++++++++++++++++
gdb/thread.c | 6 ++
2 files changed, 112 insertions(+)
create mode 100644 gdb/testsuite/gdb.multi/mtarg-thread-find.exp
diff --git a/gdb/testsuite/gdb.multi/mtarg-thread-find.exp b/gdb/testsuite/gdb.multi/mtarg-thread-find.exp
new file mode 100644
index 00000000000..faca16e7aef
--- /dev/null
+++ b/gdb/testsuite/gdb.multi/mtarg-thread-find.exp
@@ -0,0 +1,106 @@
+# Copyright 2020 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 "thread find" with multiple inferiors/targets. Regression test
+# for PR gdb/26631.
+
+source $srcdir/$subdir/multi-target.exp.tcl
+
+if {![mtarg_prepare]} {
+ return
+}
+
+proc test_thread_find {} {
+ global decimal gdb_prompt
+
+ set NUM_INFS 6
+
+ if {![setup "off"]} {
+ untested "setup failed"
+ return
+ }
+
+ # This makes sure we don't crash. See PR gdb/26631.
+ gdb_test "thread find xxxyyyzzz" \
+ "No threads match 'xxxyyyzzz'"
+
+ # Create thread names.
+ for {set i 1} {$i <= $NUM_INFS} {incr i} {
+ gdb_test "thread apply $i.1 thread name threadname_$i" \
+ "Thread $i.1 .*" \
+ "name thread $i"
+ }
+
+ # Collect target ids.
+
+ for {set i 1} {$i <= $NUM_INFS} {incr i} {
+ set target_id($i) ""
+ }
+ set any "\[^\r\n\]*"
+ gdb_test_multiple "info threads" "collect thread id" {
+ -re ". ($decimal).$decimal (Thread ${any}) \"threadname_\[0-9\]+\" $any" {
+ set thr_num $expect_out(1,string)
+ set target_id($thr_num) $expect_out(2,string)
+ exp_continue
+ }
+ -re ".*$gdb_prompt $" {
+ pass "collect target id"
+ }
+ }
+
+ # Find the threads by name. Note we repeat the search with each
+ # inferior selected, so that we're sure that GDB doesn't get
+ # confused with which target stack to consult.
+
+ with_test_prefix "find by name" {
+ for {set sel_inf 1} {$sel_inf <= $NUM_INFS} {incr sel_inf} {
+ with_test_prefix "inf $sel_inf" {
+
+ gdb_test "inferior $sel_inf" \
+ "Switching to inferior $sel_inf .*"
+
+ for {set find_inf 1} {$find_inf <= $NUM_INFS} {incr find_inf} {
+ gdb_test "thread find threadname_$find_inf" \
+ "Thread $find_inf.1 has name 'threadname_$find_inf'" \
+ "find thread name $find_inf"
+ }
+ }
+ }
+ }
+
+ # Find the threads by target id. Likewise we repeat the search
+ # with each inferior selected.
+
+ with_test_prefix "find by target id" {
+ for {set sel_inf 1} {$sel_inf <= $NUM_INFS} {incr sel_inf} {
+ with_test_prefix "inf $sel_inf" {
+
+ gdb_test "inferior $sel_inf" \
+ "Switching to inferior $sel_inf .*"
+
+ for {set find_inf 1} {$find_inf <= $NUM_INFS} {incr find_inf} {
+ set target_id_re [string_to_regexp $target_id($find_inf)]
+ gdb_test "thread find $target_id($find_inf)" \
+ "Thread $find_inf.1 has target id '$target_id_re'.*" \
+ "find thread target id $find_inf"
+ }
+ }
+ }
+ }
+}
+
+test_thread_find
+
+mtarg_cleanup
diff --git a/gdb/thread.c b/gdb/thread.c
index c915407581f..0217f3b54f7 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1946,9 +1946,15 @@ thread_find_command (const char *arg, int from_tty)
if (tmp != 0)
error (_("Invalid regexp (%s): %s"), tmp, arg);
+ /* We're going to be switching threads. */
+ scoped_restore_current_thread restore_thread;
+
update_thread_list ();
+
for (thread_info *tp : all_threads ())
{
+ switch_to_inferior_no_thread (tp->inf);
+
if (tp->name != NULL && re_exec (tp->name))
{
printf_filtered (_("Thread %s has name '%s'\n"),
--
2.14.5
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases
2020-09-17 18:00 ` [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases Pedro Alves
@ 2020-09-17 19:16 ` Simon Marchi
2020-09-18 12:34 ` Pedro Alves
2020-09-17 19:41 ` Simon Marchi
1 sibling, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2020-09-17 19:16 UTC (permalink / raw)
To: Pedro Alves, gdb-patches
On 2020-09-17 2:00 p.m., Pedro Alves wrote:
> gdb.multi/multi-target.exp sets up a debug environment with multiple
> gdbservers, multiple native processes, and multiple cores, which has
> proved useful for exercising a number of multi-target scenarios.
>
> But, as we add more tests to gdb.base/multi-target.exp, it is growing
> a bit too large (making a bit cumbersome to debug) and too slow to run
> (if you have glibc debug info).
>
> This commit thus splits the multi-target.exp into several testcases,
> one per use case. The common setup code is moved to a new
> multi-target.exp.tcl file that is included by all the resulting
> multi-target testcases.
Nice, that makes the test cases much more readable too.
> diff --git a/gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp b/gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp
> new file mode 100644
> index 00000000000..551e383b6d1
> --- /dev/null
> +++ b/gdb/testsuite/gdb.multi/mtarg-ping-pong-next.exp
> @@ -0,0 +1,85 @@
> +# Copyright 2017-2020 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 "next" bouncing between two breakpoints in two threads running
> +# in different targets.
> +
> +source $srcdir/$subdir/multi-target.exp.tcl
> +
> +if {![mtarg_prepare]} {
> + return
> +}
> +
> +proc test_ping_pong_next {} {
> + global srcfile
> +
> + if {![setup "off"]} {
> + untested "setup failed"
> + return
> + }
> +
> + # block/unblock inferiors 1 and 2 according to INF1 and INF2.
> + proc block {inf1 inf2} {
> + gdb_test "thread apply 1.1 p wait_for_gdb = $inf1" " = $inf1"
> + gdb_test "thread apply 2.1 p wait_for_gdb = $inf2" " = $inf2"
> + }
> +
> + # We're use inferiors 1 and 2. Make sure they're really connected
I just spotted this typo: "use" -> "using".
Simon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] Fix "thread find" with multiple inferiors/targets (PR gdb/26631)
2020-09-17 18:00 ` [PATCH 2/2] Fix "thread find" with multiple inferiors/targets (PR gdb/26631) Pedro Alves
@ 2020-09-17 19:37 ` Simon Marchi
0 siblings, 0 replies; 8+ messages in thread
From: Simon Marchi @ 2020-09-17 19:37 UTC (permalink / raw)
To: Pedro Alves, gdb-patches
On 2020-09-17 2:00 p.m., Pedro Alves wrote:
> "thread find" with multiple inferiors got broken with the multi-target
> work:
>
> Thread 1 "gdb" hit Breakpoint 1, internal_error (...) at ../../src/gdbsupport/errors.cc:51
> 51 {
> (top-gdb) bt
> #0 internal_error (file=0xffffd4d0 <error: Cannot access memory at address 0xffffd4d0>, line=0, fmt=0x555556330320 "en_US.UTF-8") at ../../src/gdbsupport/errors.cc:51
> #1 0x0000555555bca4c7 in target_thread_name (info=0x555556801290) at ../../src/gdb/target.c:2035
> #2 0x0000555555beb07a in thread_find_command (arg=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/thread.c:1959
> #3 0x000055555572ec49 in do_const_cfunc (c=0x555556786bc0, args=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/cli/cli-decode.c:95
> #4 0x0000555555732abd in cmd_func (cmd=0x555556786bc0, args=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/cli/cli-decode.c:2181
> #5 0x0000555555bf1245 in execute_command (p=0x7fffffffe08e "1", from_tty=0) at ../../src/gdb/top.c:664
> #6 0x00005555559cad10 in catch_command_errors (command=0x555555bf0c31 <execute_command(char const*, int)>, arg=0x7fffffffe082 "thread find 1", from_tty=0) at ../../src/gdb/main.c:457
> #7 0x00005555559cc33d in captured_main_1 (context=0x7fffffffdb60) at ../../src/gdb/main.c:1218
> #8 0x00005555559cc571 in captured_main (data=0x7fffffffdb60) at ../../src/gdb/main.c:1243
> #9 0x00005555559cc5e8 in gdb_main (args=0x7fffffffdb60) at ../../src/gdb/main.c:1268
> #10 0x0000555555623816 in main (argc=17, argv=0x7fffffffdc78) at ../../src/gdb/gdb.c:32
>
> The problem is that we're not switching to the inferior/target before
> calling target methods, which trips on an assertion put in place
> exactly to catch this sort of problem.
This LGTM. And I can't wait until we make all target methods
independent of the current target/inferior/thread :).
Simon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases
2020-09-17 18:00 ` [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases Pedro Alves
2020-09-17 19:16 ` Simon Marchi
@ 2020-09-17 19:41 ` Simon Marchi
2020-09-18 13:01 ` Pedro Alves
1 sibling, 1 reply; 8+ messages in thread
From: Simon Marchi @ 2020-09-17 19:41 UTC (permalink / raw)
To: Pedro Alves, gdb-patches
On 2020-09-17 2:00 p.m., Pedro Alves wrote:
> gdb.multi/multi-target.exp sets up a debug environment with multiple
> gdbservers, multiple native processes, and multiple cores, which has
> proved useful for exercising a number of multi-target scenarios.
>
> But, as we add more tests to gdb.base/multi-target.exp, it is growing
> a bit too large (making a bit cumbersome to debug) and too slow to run
> (if you have glibc debug info).
>
> This commit thus splits the multi-target.exp into several testcases,
> one per use case. The common setup code is moved to a new
> multi-target.exp.tcl file that is included by all the resulting
> multi-target testcases.
>
> gdb/testsuite/ChangeLog:
>
> * gdb.multi/mtarg-continue.exp: New file, factored out from
> multi-target.exp.
> * gdb.multi/mtarg-info-inferiors.exp: New file, factored out from
> multi-target.exp.
> * gdb.multi/mtarg-interrupt.exp: New file, factored out from
> multi-target.exp.
> * gdb.multi/mtarg-no-resumed.exp: New file, factored out from
> multi-target.exp.
> * gdb.multi/mtarg-ping-pong-next.exp: New file, factored out from
> multi-target.exp.
> * gdb.multi/multi-target.exp.tcl: New file, factored out from
> multi-target.exp.
> * gdb.multi/multi-target.exp: Delete.
Maybe a small comment here: I think it would be clearer to not
abbreviate "multi-target" to "mtarg", so to name the files
"multi-target-foo.exp". Abbreviations like that are a bit intimidating
when you are not familiar with them.
Simon
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases
2020-09-17 19:16 ` Simon Marchi
@ 2020-09-18 12:34 ` Pedro Alves
0 siblings, 0 replies; 8+ messages in thread
From: Pedro Alves @ 2020-09-18 12:34 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 9/17/20 8:16 PM, Simon Marchi wrote:
> On 2020-09-17 2:00 p.m., Pedro Alves wrote:
>> gdb.multi/multi-target.exp sets up a debug environment with multiple
>> gdbservers, multiple native processes, and multiple cores, which has
>> proved useful for exercising a number of multi-target scenarios.
>>
>> But, as we add more tests to gdb.base/multi-target.exp, it is growing
>> a bit too large (making a bit cumbersome to debug) and too slow to run
>> (if you have glibc debug info).
>>
>> This commit thus splits the multi-target.exp into several testcases,
>> one per use case. The common setup code is moved to a new
>> multi-target.exp.tcl file that is included by all the resulting
>> multi-target testcases.
>
> Nice, that makes the test cases much more readable too.
I agree.
>> + # We're use inferiors 1 and 2. Make sure they're really connected
>
> I just spotted this typo: "use" -> "using".
I think I originally meant to say "We'll use". I fixed it to use that.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases
2020-09-17 19:41 ` Simon Marchi
@ 2020-09-18 13:01 ` Pedro Alves
0 siblings, 0 replies; 8+ messages in thread
From: Pedro Alves @ 2020-09-18 13:01 UTC (permalink / raw)
To: Simon Marchi, gdb-patches
On 9/17/20 8:41 PM, Simon Marchi wrote:
> On 2020-09-17 2:00 p.m., Pedro Alves wrote:
>> gdb.multi/multi-target.exp sets up a debug environment with multiple
>> gdbservers, multiple native processes, and multiple cores, which has
>> proved useful for exercising a number of multi-target scenarios.
>>
>> But, as we add more tests to gdb.base/multi-target.exp, it is growing
>> a bit too large (making a bit cumbersome to debug) and too slow to run
>> (if you have glibc debug info).
>>
>> This commit thus splits the multi-target.exp into several testcases,
>> one per use case. The common setup code is moved to a new
>> multi-target.exp.tcl file that is included by all the resulting
>> multi-target testcases.
>>
>> gdb/testsuite/ChangeLog:
>>
>> * gdb.multi/mtarg-continue.exp: New file, factored out from
>> multi-target.exp.
>> * gdb.multi/mtarg-info-inferiors.exp: New file, factored out from
>> multi-target.exp.
>> * gdb.multi/mtarg-interrupt.exp: New file, factored out from
>> multi-target.exp.
>> * gdb.multi/mtarg-no-resumed.exp: New file, factored out from
>> multi-target.exp.
>> * gdb.multi/mtarg-ping-pong-next.exp: New file, factored out from
>> multi-target.exp.
>> * gdb.multi/multi-target.exp.tcl: New file, factored out from
>> multi-target.exp.
>> * gdb.multi/multi-target.exp: Delete.
>
> Maybe a small comment here: I think it would be clearer to not
> abbreviate "multi-target" to "mtarg", so to name the files
> "multi-target-foo.exp". Abbreviations like that are a bit intimidating
> when you are not familiar with them.
I made that change, here and in patch #2. I agree that it does indeed
look better.
I also renamed the mtarg_prepare and mtarg_cleanup routines to
multi_target_prepare and multi_target_cleanup.
I merged this to the master and gdb 10 branches.
Thanks for the review!
Pedro Alves
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-09-18 13:01 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 18:00 [PATCH 0/2] Fix "thread find" with multi inferior/target (PR gdb/26631) Pedro Alves
2020-09-17 18:00 ` [PATCH 1/2] Split gdb.multi/multi-target.exp into separate testcases Pedro Alves
2020-09-17 19:16 ` Simon Marchi
2020-09-18 12:34 ` Pedro Alves
2020-09-17 19:41 ` Simon Marchi
2020-09-18 13:01 ` Pedro Alves
2020-09-17 18:00 ` [PATCH 2/2] Fix "thread find" with multiple inferiors/targets (PR gdb/26631) Pedro Alves
2020-09-17 19:37 ` Simon Marchi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).