]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2023-2024 Free Software Foundation, Inc. |
ce068c5f AB |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # Check that GDB uses the correct thread-id when describing multiple | |
17 | # thread specific breakpoints at the same location. | |
442716d4 AB |
18 | # |
19 | # Also check that the correct thread-ids are used in the saved | |
20 | # breakpoints file. | |
ce068c5f AB |
21 | |
22 | # The plain remote target can't do multiple inferiors. | |
23 | require !use_gdb_stub | |
24 | ||
25 | standard_testfile | |
26 | ||
27 | if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} { | |
28 | return -1 | |
29 | } | |
30 | ||
31 | if {![runto_main]} { | |
32 | return -1 | |
33 | } | |
34 | ||
35 | gdb_test "add-inferior -exec ${binfile}" "Added inferior 2.*" "add inferior 2" | |
36 | gdb_test "inferior 2" | |
37 | ||
38 | if {![runto_main]} { | |
39 | return -1 | |
40 | } | |
41 | ||
42 | gdb_test "info threads" \ | |
43 | [multi_line \ | |
44 | " Id\\s+Target Id\\s+Frame\\s*" \ | |
45 | " 1\\.1\\s+\[^\r\n\]+" \ | |
46 | "\\* 2\\.1\\s+\[^\r\n\]+"] \ | |
47 | "check we have the expected threads" | |
48 | ||
49 | # Set the first breakpoint. Currently this is going to insert at two | |
50 | # locations ('foo' in both inferiors) even though only one of those | |
51 | # locations will ever trigger ('foo' in inferior 2). | |
52 | gdb_test "break foo thread 2.1" \ | |
53 | "Breakpoint $decimal at $hex: foo\\. \\(2 locations\\)" | |
54 | ||
55 | set bpnum [get_integer_valueof "\$bpnum" "INVALID"] | |
56 | ||
57 | # Now set another breakpoint that will be at the same location as the | |
58 | # earlier breakpoint. Check that the thread-id used when describing | |
59 | # the earlier breakpoints is correct. | |
60 | gdb_test "break foo thread 1.1" \ | |
61 | [multi_line \ | |
62 | "Note: breakpoint $bpnum \\(thread 2.1\\) also set at pc $hex\\." \ | |
63 | "Note: breakpoint $bpnum \\(thread 2.1\\) also set at pc $hex\\." \ | |
64 | "Breakpoint $decimal at $hex: foo\\. \\(2 locations\\)"] | |
442716d4 AB |
65 | |
66 | # Save the breakpoints into a file. | |
67 | if {[is_remote host]} { | |
68 | set bps bps | |
69 | } else { | |
70 | set bps [standard_output_file bps] | |
71 | } | |
72 | ||
73 | remote_file host delete "$bps" | |
74 | gdb_test "save breakpoints $bps" "" "save breakpoint to bps" | |
75 | ||
76 | if {[is_remote host]} { | |
77 | set bps [remote_upload host bps [standard_output_file bps]] | |
78 | } | |
79 | ||
80 | # Now dig through the saved breakpoints file and check that the | |
81 | # thread-ids were written out correctly. First open the saved | |
82 | # breakpoints and read them into a list. | |
83 | set fh [open $bps] | |
84 | set lines [split [read $fh] "\n"] | |
85 | close $fh | |
86 | ||
87 | # Except the list created from the saved breakpoints file will have a | |
88 | # blank line entry at the end, so remove it now. | |
89 | gdb_assert {[string equal [lindex $lines end] ""]} \ | |
90 | "check last item was an empty line" | |
91 | set lines [lrange $lines 0 end-1] | |
92 | ||
93 | # These are the lines we expect in the saved breakpoints file, in the | |
94 | # order that we expect them. These are strings, not regexps. | |
95 | set expected_results \ | |
96 | [list \ | |
97 | "break -qualified main" \ | |
98 | "break foo thread 2.1" \ | |
99 | "break foo thread 1.1"] | |
100 | ||
101 | # Now check that the files contents (in LINES) matches the | |
102 | # EXPECTED_RESULTS. | |
103 | gdb_assert {[llength $lines] == [llength $expected_results]} \ | |
104 | "correct number of lines in saved breakpoints file" | |
105 | foreach a $lines b $expected_results { | |
106 | gdb_assert {[string equal $a $b]} "line '$b'" | |
107 | } |