e188637bc07dd6062512da47b7c72c265a16cfd8
[external/binutils.git] / gdb / testsuite / gdb.linespec / cpls-abi-tag.exp
1 # Copyright 2017-2018 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 # This file is part of the gdb testsuite.
17
18 # Test ABI tag support in linespecs.
19
20 load_lib completion-support.exp
21
22 standard_testfile cpls-abi-tag.cc
23
24 if {[prepare_for_testing "failed to prepare" $testfile \
25          [list $srcfile] {c++ debug}]} {
26     return -1
27 }
28
29 gdb_test_no_output "set max-completions unlimited"
30
31 # Check that the explicit location completer manages to find the next
32 # option name after a -function option, when the -function's argument
33 # is a function with an ABI tag.
34
35 proc check_explicit_skips_function_argument {function} {
36     test_gdb_complete_unique \
37         "b -function $function -sour" \
38         "b -function $function -source"
39 }
40
41 # The ABI tag tests.
42
43 proc_with_prefix test_abi_tag {} {
44     with_test_prefix "completion" {
45         foreach cmd_prefix {"b" "b -function"} {
46             # Complete all prefixes between "_funcio" and the full
47             # prototype.  The ABI tag is not considered for actual
48             # completion.
49
50             with_test_prefix "skip tag" {
51                 # set location "test_abi_tag_function\[abi:tag1\](int)"
52                 set location "test_abi_tag_function(int)"
53                 set line "$cmd_prefix $location"
54                 set start [index_after "_functio" $line]
55                 test_complete_prefix_range $line $start
56             }
57
58             # Now the same, but start completing at the [.  In that case,
59             # GDB considers the ABI tag as part of actual completion.
60             with_test_prefix "at tag" {
61                 set location "test_abi_tag_function\[abi:tag1\](int)"
62                 set line "$cmd_prefix $location"
63                 set start [index_after "_function" $line]
64                 test_complete_prefix_range $line $start
65             }
66
67             # Same, but with extra spaces.  Note that the original spaces in
68             # the input line are preserved after completion.
69
70             with_test_prefix "spaces" {
71                 test_gdb_complete_unique \
72                     "$cmd_prefix test_abi_tag_function \[abi:tag1\] (" \
73                     "$cmd_prefix test_abi_tag_function \[abi:tag1\] (int)"
74
75                 test_gdb_complete_unique \
76                     "$cmd_prefix test_abi_tag_function \[abi:tag1\] ( int " \
77                     "$cmd_prefix test_abi_tag_function \[abi:tag1\] ( int )"
78             }
79         }
80     }
81
82     with_test_prefix "set breakpoints" {
83         foreach cmd_prefix {"b" "b -function"} {
84             # Test setting breakpoints.  If the symbol name has an ABI
85             # tag, but the input linespec doesn't, then the ABI tag in the
86             # symbol name is ignored.
87             set linespec_list {
88                 "test_abi_tag_function"
89                 "test_abi_tag_function[abi:tag1]"
90                 "test_abi_tag_function[abi:tag1](int)"
91                 "test_abi_tag_function [abi:tag1]"
92                 "test_abi_tag_function [abi:tag1] ( int )"
93                 "test_abi_tag_function(int)"
94                 "test_abi_tag_function (int)"
95                 "test_abi_tag_function ( int )"
96             }
97             foreach linespec $linespec_list {
98                 check_bp_locations_match_list \
99                     "$cmd_prefix $linespec" [list $location]
100             }
101         }
102     }
103
104     with_test_prefix "set breakpoints wrong ABI tag" {
105         foreach cmd_prefix {"b" "b -function"} {
106             # Test setting breakpoints with the wrong ABI tag.  Should
107             # fail to create the breakpoints.  Completion should not find
108             # any match either.
109             set linespec_list {
110                 "test_abi_tag_function[abi:tag2]"
111                 "test_abi_tag_function[abi:tag2](int)"
112                 "test_abi_tag_function [abi:tag2]"
113                 "test_abi_tag_function [abi:tag2] ( int )"
114             }
115             foreach linespec $linespec_list {
116                 check_setting_bp_fails "$cmd_prefix $linespec"
117                 test_gdb_complete_none "$cmd_prefix $linespec"
118             }
119
120         }
121     }
122
123     # Test completion of overloaded functions with ABI tags.
124     with_test_prefix "completion of overloaded functions" {
125         foreach cmd_prefix {"b" "b -function"} {
126             set completion_list {
127                 "test_abi_tag_ovld_function[abi:tag1]()"
128                 "test_abi_tag_ovld_function[abi:tag1](int)"
129             }
130
131             # If the input string does not include the ABI tag, then
132             # actual completion ignores it.
133             test_gdb_complete_multiple \
134                 "$cmd_prefix " "test_abi_tag_ovld_f" "unction(" \
135                 $completion_list
136
137             # Otherwise, it's considered.
138             test_gdb_complete_multiple \
139                 "$cmd_prefix " "test_abi_tag_ovld_function\[" "abi:tag1\](" \
140                 $completion_list
141
142         }
143     }
144
145     # Test setting breakpoints on overloaded functions with ABI tags.
146     with_test_prefix "breakpoints on overloaded functions" {
147         foreach cmd_prefix {"b" "b -function"} {
148             set completion_list {
149                 "test_abi_tag_ovld_function[abi:tag1]()"
150                 "test_abi_tag_ovld_function[abi:tag1](int)"
151             }
152             set location_list {
153                 "test_abi_tag_ovld_function"
154                 "test_abi_tag_ovld_function[abi:tag1]"
155             }
156             foreach linespec $location_list {
157                 check_bp_locations_match_list \
158                     "$cmd_prefix $linespec" $completion_list
159             }
160
161         }
162     }
163
164     with_test_prefix "completion of overloaded functions different abi" {
165         foreach cmd_prefix {"b" "b -function"} {
166             # Test completion of overloaded functions with ABI tags.
167             set completion_list {
168                 "test_abi_tag_ovld2_function()"
169                 "test_abi_tag_ovld2_function[abi:tag1](short)"
170                 "test_abi_tag_ovld2_function[abi:tag2](int)"
171                 "test_abi_tag_ovld2_function[abi:tag2](long)"
172             }
173
174             # If the input string does not include the ABI tag, then
175             # actual completion ignores it.
176             test_gdb_complete_multiple \
177                 "$cmd_prefix " "test_abi_tag_ovld2_f" "unction(" \
178                 $completion_list
179
180             # Otherwise, it's considered.  Match stops at the part of
181             # the tag that diverges, and the completion list only
182             # shows matches with ABI tags.
183             set completion_list {
184                 "test_abi_tag_ovld2_function[abi:tag1](short)"
185                 "test_abi_tag_ovld2_function[abi:tag2](int)"
186                 "test_abi_tag_ovld2_function[abi:tag2](long)"
187             }
188             test_gdb_complete_multiple \
189                 "$cmd_prefix " "test_abi_tag_ovld2_function\[" "abi:tag" \
190                 $completion_list
191
192             # If you disambiguate, matches include only locations for
193             # the specified tag.
194             set completion_list {
195                 "test_abi_tag_ovld2_function[abi:tag2](int)"
196                 "test_abi_tag_ovld2_function[abi:tag2](long)"
197             }
198             test_gdb_complete_multiple \
199                 "$cmd_prefix " "test_abi_tag_ovld2_function\[abi:tag2" "\](" \
200                 $completion_list
201
202             test_gdb_complete_unique \
203                 "$cmd_prefix test_abi_tag_ovld2_function\[abi:tag1" \
204                 "$cmd_prefix test_abi_tag_ovld2_function\[abi:tag1\](short)"
205         }
206     }
207
208     with_test_prefix "completion of struct prefixes with tags" {
209         foreach cmd_prefix {"b" "b -function"} {
210             # Test completion of methods of structs with ABI tags.
211             set completion_list {
212                 "test_abi_tag_struct[abi:tag1]::test_abi_tag_struct[abi:tag2]()"
213                 "test_abi_tag_struct[abi:tag1]::~test_abi_tag_struct[abi:tag2]()"
214             }
215
216             # If the input string does not include the ABI tag, then
217             # actual completion ignores it.
218             test_gdb_complete_multiple \
219                 "$cmd_prefix " "test_abi_tag_struc" "t::" \
220                 $completion_list
221
222             # Otherwise, it's considered.
223             test_gdb_complete_multiple \
224                 "$cmd_prefix " "test_abi_tag_struct\[" "abi:tag1\]::" \
225                 $completion_list
226
227             # Mix and match different abi tag positions.
228             test_gdb_complete_unique \
229                 "$cmd_prefix test_abi_tag_struct::t" \
230                 "$cmd_prefix test_abi_tag_struct::test_abi_tag_struct()"
231
232             test_gdb_complete_unique \
233                 "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::t" \
234                 "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::test_abi_tag_struct()"
235
236             test_gdb_complete_unique \
237                 "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::test_abi_tag_struct\[" \
238                 "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::test_abi_tag_struct\[abi:tag2\]()"
239         }
240     }
241
242     with_test_prefix "abi tag in parameters" {
243         foreach cmd_prefix {"b" "b -function"} {
244             # Complete all prefixes between "_funcio" and the full
245             # prototype.  The ABI tag is not considered for actual
246             # completion.
247
248             set completion_list {
249                 "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2])"
250                 "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2], abi_tag_param_struct2[abi:tag2])"
251             }
252             # If the input string does not include the ABI tag, then
253             # actual completion ignores it.
254             test_gdb_complete_multiple \
255                 "$cmd_prefix " "test_abi_tag_in_para" "ms(abi_tag_param_struct1" \
256                 $completion_list
257
258             # If OTOH the input string includes the ABI tag, then it
259             # is considered.
260             test_gdb_complete_multiple \
261                 "$cmd_prefix " "test_abi_tag_in_params(abi_tag_param_struct1\[ab" "i:tag2\]"\
262                 $completion_list
263
264             set location_list {
265                 "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2], abi_tag_param_struct2[abi:tag2])"
266             }
267
268             set tags {"" "\[abi:tag2\]"}
269             foreach tag1 $tags {
270                 foreach tag2 $tags {
271                     set linespec "test_abi_tag_in_params(abi_tag_param_struct1${tag1}, abi_tag_param_struct2${tag2})"
272                     check_bp_locations_match_list \
273                         "$cmd_prefix $linespec" $location_list
274                 }
275             }
276         }
277     }
278
279     # Check that the explicit location completer manages to find the
280     # option name after -function, when the -function's argument is a
281     # function with an ABI tag.
282     check_explicit_skips_function_argument \
283         "test_abi_tag_function\[abi:unknown\](int)"
284 }
285
286 test_abi_tag