1 # Copyright 2017-2018 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the gdb testsuite.
18 # Test ABI tag support in linespecs.
20 load_lib completion-support.exp
22 standard_testfile cpls-abi-tag.cc
24 if {[prepare_for_testing "failed to prepare" $testfile \
25 [list $srcfile] {c++ debug}]} {
29 gdb_test_no_output "set max-completions unlimited"
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.
35 proc check_explicit_skips_function_argument {function} {
36 test_gdb_complete_unique \
37 "b -function $function -sour" \
38 "b -function $function -source"
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
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
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
67 # Same, but with extra spaces. Note that the original spaces in
68 # the input line are preserved after completion.
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)"
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 )"
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.
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 )"
97 foreach linespec $linespec_list {
98 check_bp_locations_match_list \
99 "$cmd_prefix $linespec" [list $location]
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
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 )"
115 foreach linespec $linespec_list {
116 check_setting_bp_fails "$cmd_prefix $linespec"
117 test_gdb_complete_none "$cmd_prefix $linespec"
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)"
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(" \
137 # Otherwise, it's considered.
138 test_gdb_complete_multiple \
139 "$cmd_prefix " "test_abi_tag_ovld_function\[" "abi:tag1\](" \
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)"
153 "test_abi_tag_ovld_function"
154 "test_abi_tag_ovld_function[abi:tag1]"
156 foreach linespec $location_list {
157 check_bp_locations_match_list \
158 "$cmd_prefix $linespec" $completion_list
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)"
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(" \
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)"
188 test_gdb_complete_multiple \
189 "$cmd_prefix " "test_abi_tag_ovld2_function\[" "abi:tag" \
192 # If you disambiguate, matches include only locations for
194 set completion_list {
195 "test_abi_tag_ovld2_function[abi:tag2](int)"
196 "test_abi_tag_ovld2_function[abi:tag2](long)"
198 test_gdb_complete_multiple \
199 "$cmd_prefix " "test_abi_tag_ovld2_function\[abi:tag2" "\](" \
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)"
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]()"
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::" \
222 # Otherwise, it's considered.
223 test_gdb_complete_multiple \
224 "$cmd_prefix " "test_abi_tag_struct\[" "abi:tag1\]::" \
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()"
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()"
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\]()"
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
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])"
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" \
258 # If OTOH the input string includes the ABI tag, then it
260 test_gdb_complete_multiple \
261 "$cmd_prefix " "test_abi_tag_in_params(abi_tag_param_struct1\[ab" "i:tag2\]"\
265 "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2], abi_tag_param_struct2[abi:tag2])"
268 set tags {"" "\[abi:tag2\]"}
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
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)"