]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.multi/inferior-specific-bp.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.multi / inferior-specific-bp.exp
1 # Copyright 2022-2024 Free Software Foundation, Inc.
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 # Test inferior-specific breakpoints.
17
18 standard_testfile -1.c -2.c
19
20 if {[use_gdb_stub]} {
21 return
22 }
23
24 set srcfile1 ${srcfile}
25 set binfile1 ${binfile}-1
26 set binfile2 ${binfile}-2
27
28 if {[build_executable ${testfile}.exp ${binfile1} "${srcfile1}"] != 0} {
29 return -1
30 }
31
32 if {[build_executable ${testfile}.exp ${binfile2} "${srcfile2}"] != 0} {
33 return -1
34 }
35
36 # Start the first inferior.
37 clean_restart ${binfile1}
38 if {![runto_main]} {
39 return
40 }
41
42 # Add a second inferior, and start this one too.
43 gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
44 gdb_test "inferior 2" "Switching to inferior 2.*" "switch to inferior 2"
45 gdb_load $binfile2
46 if {![runto_main]} {
47 return
48 }
49
50 # Try to create a breakpoint using both the 'inferior' and 'thread' keywords,
51 # this should fail. Try with the keywords in both orders just in case the
52 # parser has a bug.
53 gdb_test "break foo thread 1.1 inferior 1" \
54 "You can specify only one of inferior or thread\\."
55 gdb_test "break foo inferior 1 thread 1.1" \
56 "You can specify only one of inferior or thread\\."
57
58 # Try to create a breakpoint using the 'inferior' keyword multiple times.
59 gdb_test "break foo inferior 1 inferior 2" \
60 "You can specify only one inferior\\."
61
62 # Clear out any other breakpoints.
63 delete_breakpoints
64
65 # Use 'info breakpoint' to check that the inferior specific breakpoint is
66 # present in the breakpoint list. TESTNAME is the name used for this test,
67 # BP_NUMBER is the number for the breakpoint, and EXPECTED_LOC_COUNT is the
68 # number of locations we expect for that breakpoint.
69 proc check_info_breakpoints { testname bp_number expected_loc_count } {
70 gdb_test_multiple "info breakpoints $bp_number" $testname {
71 -re "\r\nNum\\s+\[^\r\n\]+\r\n" {
72 exp_continue
73 }
74
75 -re "^$bp_number\\s+breakpoint\\s+keep\\s+y\\s+<MULTIPLE>\\s*\r\n" {
76 set saw_header true
77 exp_continue
78 }
79
80 -re "^\\s+stop only in inferior 1\r\n" {
81 set saw_inf_cond true
82 exp_continue
83 }
84
85 -re "^\\s+breakpoint already hit $::decimal times\r\n" {
86 exp_continue
87 }
88
89 -re "^$bp_number\\.\[123\]\\s+y\\s+ $::hex in foo at \[^\r\n\]+(?: inf \[12\])?\r\n" {
90 incr location_count
91 exp_continue
92 }
93
94 -re "^$::gdb_prompt $" {
95 with_test_prefix $gdb_test_name {
96 gdb_assert { $saw_header \
97 && $location_count == $expected_loc_count \
98 && $saw_inf_cond } \
99 $gdb_test_name
100 }
101 }
102 }
103 }
104
105 # Create an inferior-specific breakpoint. Use gdb_test instead of
106 # gdb_breakpoint here as we want to check the breakpoint was placed in
107 # multiple locations.
108 #
109 # Currently GDB still places inferior specific breakpoints into every
110 # inferior, just like it does with thread specific breakpoints.
111 # Hopefully this will change in the future, at which point, this test
112 # will need updating.
113 #
114 # Two of these locations are in inferior 1, while the third is in
115 # inferior 2.
116 gdb_test "break foo inferior 1" \
117 "Breakpoint $decimal at $hex: foo\\. \\(3 locations\\)"
118 set bp_number [get_integer_valueof "\$bpnum" "INVALID" \
119 "get b/p number for inferior specific breakpoint"]
120
121 set saw_header false
122 set location_count 0
123 set saw_inf_cond false
124
125 check_info_breakpoints "first check for inferior specific breakpoint" \
126 $bp_number 3
127
128 # Create a multi-inferior breakpoint to stop at.
129 gdb_breakpoint "stop_breakpt" message
130 set stop_bp_num [get_integer_valueof "\$bpnum" "INVALID" \
131 "get b/p number for stop_breakpt"]
132
133 # Now resume inferior 2, this should reach 'stop_breakpt'.
134 gdb_test "continue" \
135 "hit Breakpoint $stop_bp_num\.$decimal, stop_breakpt \\(\\) .*" \
136 "continue in inferior 2"
137
138 # Switch to inferior 1, and try there.
139 gdb_test "inferior 1" ".*" \
140 "select inferior 1 to check the inferior-specific b/p works"
141 gdb_test "continue " \
142 "Thread 1\\.${decimal}\[^\r\n\]* hit Breakpoint\
143 $bp_number\.$decimal, foo \\(\\) .*" \
144 "first continue in inferior 1"
145
146 # Now back to inferior 2, let the inferior exit, and then remove the
147 # inferior, the inferior-specific breakpoint should not be deleted.
148 gdb_test "inferior 2" ".*" \
149 "switch back to allow inferior 2 to exit"
150 gdb_test "continue" "\\\[Inferior 2 \[^\r\n\]+ exited normally\\\]" \
151 "allow inferior 2 to exit"
152 gdb_test "inferior 1" ".*" \
153 "back to inferior 1 so inferior 2 can be deleted"
154 gdb_test_no_output "remove-inferiors 2"
155
156 gdb_test "continue " "hit Breakpoint $bp_number\.$decimal, foo \\(\\) .*" \
157 "second continue in inferior 1"
158 gdb_test "continue " "hit Breakpoint $stop_bp_num, stop_breakpt \\(\\) .*" \
159 "third continue in inferior 1"
160
161 # Now allow inferior 1 to exit, the inferior specific breakpoint
162 # should not be deleted.
163 gdb_test "continue" \
164 "\\\[Inferior 1 \[^\r\n\]+ exited normally\\\]" \
165 "allow inferior 1 to exit"
166
167 check_info_breakpoints "second check for inferior specific breakpoint" \
168 $bp_number 2
169
170 # Now create another new inferior, then remove inferior 1. As a result of
171 # this removal, the inferior specific breakpoint should be deleted.
172 gdb_test "add-inferior" "Added inferior 3.*" "add empty inferior 3"
173 gdb_test "inferior 3" "Switching to inferior 3.*" "switch to inferior 3"
174 gdb_test "remove-inferiors 1" \
175 "Inferior-specific breakpoint $bp_number deleted - inferior 1 has been removed\\."
176
177 # Now check 'info breakpoints' to ensure the breakpoint is gone.
178 gdb_test "info breakpoints $bp_number" \
179 "No breakpoint or watchpoint matching '$bp_number'\\."