]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.linespec/linespec.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.linespec / linespec.exp
1 # Copyright 2011-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 # Tests of ambiguous linespecs.
17
18 standard_testfile lspec.cc
19
20 set exefile $testfile
21
22 set baseone base/one/thefile.cc
23 set basetwo base/two/thefile.cc
24
25 require allow_cplus_tests
26
27 if {[prepare_for_testing "failed to prepare" $exefile \
28 [list $srcfile $baseone $basetwo] \
29 {debug nowarnings c++}]} {
30 return -1
31 }
32
33 gdb_test_no_output "set multiple-symbols all" \
34 "set multiple-symbols to all for linespec tests"
35
36 set l1 [gdb_get_line_number "thefile breakpoint" $baseone]
37 set l2 [gdb_get_line_number "thefile breakpoint" $basetwo]
38
39 if {$l1 != $l2} {
40 error "somebody incompatibly modified the source files needed by linespec.exp"
41 }
42
43 gdb_test_no_output "set breakpoint pending off" \
44 "disable pending breakpoints for linespec tests"
45
46 # Copying files to a remote host loses the directory prefix during
47 # compilation.
48 if { [is_remote host] } {
49 untested "breakpoints using dir/file:line"
50 } else {
51 gdb_test "break one/thefile.cc:$l1" \
52 "Breakpoint $decimal at $hex: file .*thefile.cc, line $l1." \
53 "single-location break using dir/file:line"
54
55 gdb_test "clear one/thefile.cc:$l1" \
56 "Deleted breakpoint $decimal *" \
57 "clear breakpoint using dir/file:line"
58
59 if { [readline_is_used] } {
60 # There are functions named 'twodup' in both source files.
61 # Both should be found if we restrict the linespec to the
62 # ambiguous "thefile.cc" source filename. Check both
63 # completion and setting the breakpoint.
64 set tst "complete unique function name in two source files"
65 send_gdb "break thefile.cc:t\t"
66 gdb_test_multiple "" $tst {
67 -re "break thefile.cc:twodup\\(\\) " {
68 pass $tst
69
70 send_gdb "\n"
71 gdb_test "" \
72 "Breakpoint $decimal at $hex: thefile.cc:twodup\\(\\). \[(\]2 locations\[)\]" \
73 "set break at unique function name in two source files"
74 }
75 }
76
77 # Check both completing and setting a breakpoint on a linespec
78 # with a source component, where there's more than one source
79 # file with the same basename. We should find the functions
80 # in all matching sources -- one/thefile.cc and
81 # two/thefile.cc. The "one" file has "z1()", while the "two"
82 # file has "z2()".
83 set tst "complete non-unique function name in two source files"
84 send_gdb "break thefile.cc:z\t"
85 gdb_test_multiple "" $tst {
86 -re "break thefile.cc:z\\\x07" {
87 send_gdb "\t"
88 gdb_test_multiple "" $tst {
89 -re "\r\nz1\\(\\)\[ \t\]+z2\\(\\)\[ \t\]+\r\n$gdb_prompt " {
90 pass $tst
91
92 send_gdb "\n"
93 gdb_test "" \
94 "Function \"z\" not defined in \"thefile.cc\"." \
95 "set break at non-unique function name in two source files"
96 }
97 }
98 }
99 }
100
101 # Now check that disambiguating the source path makes GDB only
102 # match the symbols in that file. "z" should now have a
103 # unique completion to "z1()", and setting the breakpoint
104 # should find only one location.
105 set tst "complete unique function name in disambiguated source file"
106 send_gdb "break one/thefile.cc:z\t"
107 gdb_test_multiple "" $tst {
108 -re "break one/thefile.cc:z1\\(\\) " {
109 pass $tst
110
111 send_gdb "\n"
112 gdb_test "" \
113 "Breakpoint $decimal at $hex: file .*thefile.cc, line \[^\r\n\]*" \
114 "set break at unique function name in disambiguated source file"
115 }
116 }
117
118 # Check that using a non-existing source path does not confuse
119 # GDB. It should not match any symbol.
120 set dir_file "one/thefile.cc"
121 set non_existing "/some/non-existing/absolute/path/prefix/$dir_file"
122 set non_existing_re [string_to_regexp $non_existing]
123
124 set tst "complete functions in non-existing absolute path"
125 send_gdb "break $non_existing:\t"
126 gdb_test_multiple "" $tst {
127 -re "break $non_existing_re:\\\x07" {
128 send_gdb "\t\t"
129 gdb_test_multiple "" $tst {
130 -re "^\\\x07\\\x07" {
131 pass $tst
132
133 # There's a function called 'twodup' in each
134 # of the thefile.cc files. Make sure none is
135 # picked.
136 send_gdb "twodup\n"
137 gdb_test "" \
138 "No source file named $non_existing_re." \
139 "set break in function in non-existing absolute path"
140 }
141 }
142 }
143 }
144 }
145 }
146
147 gdb_test "break thefile.cc:$l1" \
148 "Breakpoint $decimal at $hex: thefile.cc:$l1. \[(\]2 locations\[)\]" \
149 "multi-location break using file:line"
150
151 gdb_test "break dupname" \
152 "Breakpoint $decimal at $hex: dupname. \[(\]2 locations\[)\]" \
153 "multi-location break using duplicate function name"
154
155 gdb_test "break dupname:label" \
156 "Breakpoint $decimal at $hex: dupname:label. \[(\]2 locations\[)\]" \
157 "multi-location break using duplicate function name and label"
158
159 # Testing if the "condition" command completes only the breakpoints,
160 # not the locations.
161 gdb_test "complete condition " "condition $decimal\r\ncondition $decimal\r\ncondition $decimal"
162
163 # This is PR breakpoints/12856.
164 gdb_test "break lspec.cc:nosuchfunction" \
165 "Function \"nosuchfunction\" not defined in \"lspec.cc\"." \
166 "set breakpoint on non-existent function"
167
168 gdb_test "break NameSpace::overload" \
169 "Breakpoint \[0-9\]+ at $hex: NameSpace::overload. \[(\]3 locations\[)\]" \
170 "set breakpoint at all instances of NameSpace::overload"
171
172 gdb_test "break lspec.cc:NameSpace::overload" \
173 "Breakpoint \[0-9\]+ at $hex: file .*lspec.cc, line 7." \
174 "set breakpoint at lspec.cc instance of NameSpace::overload"
175
176 gdb_test "break lspec.cc:NameSpace::overload(double)" \
177 "Function \"NameSpace::overload\\(double\\)\" not defined in \"lspec.cc\"." \
178 "set breakpoint at non-existent lspec.cc instance of NameSpace::overload"
179
180 gdb_test "break NameSpace::overload()" \
181 "Breakpoint \[0-9\]+ at $hex: file .*lspec.cc, line 7." \
182 "set breakpoint at specific instance of NameSpace::overload"
183
184 # This should manage to set a breakpoint even though body.h does not
185 # include all of the function in question.
186 set line [gdb_get_line_number "body breakpoint no code" body.h]
187 gdb_test "break body.h:$line" \
188 "Breakpoint \[0-9\]+.*" \
189 "set breakpoint in body.h"
190
191 # This should only have a single location -- in f1.
192 set line [gdb_get_line_number "f1 breakpoint" lspec.h]
193 gdb_test "break lspec.h:$line" \
194 "Breakpoint \[0-9\]+ at $hex: file .*lspec.h, line $line." \
195 "set breakpoint in f1"
196
197 #
198 # Multi-inferior tests.
199 #
200
201 gdb_test "add-inferior" "Added inferior 2.*" \
202 "add inferior for linespec tests"
203
204 gdb_test "inferior 2" "Switching to inferior 2 .*" \
205 "switch to inferior 2 for linespec tests"
206
207 # Note that in particular this should not cause errors when re-setting
208 # breakpoints.
209 gdb_test "file $binfile" \
210 "Reading symbols from .*" \
211 "set the new inferior file for linespec tests"
212
213 gdb_test "break -q main" \
214 "Breakpoint \[0-9\]+ at $hex: -qualified main. .2 locations." \
215 "set breakpoint at main in both inferiors"