1 # Copyright 2017-2020 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 # Tests below are about tab-completion, which doesn't work if readline
30 # library isn't used. Check it first.
32 if { ![readline_is_used] } {
33 untested "no tab completion support without readline"
37 gdb_test_no_output "set max-completions unlimited"
39 # Check that the explicit location completer manages to find the next
40 # option name after a -function option, when the -function's argument
41 # is a function with an ABI tag.
43 proc check_explicit_skips_function_argument {function} {
44 test_gdb_complete_unique \
45 "b -function $function -sour" \
46 "b -function $function -source"
51 proc_with_prefix test_abi_tag {} {
52 with_test_prefix "completion" {
53 foreach cmd_prefix {"b" "b -function"} {
54 # Complete all prefixes between "_funcio" and the full
55 # prototype. The ABI tag is not considered for actual
58 with_test_prefix "skip tag" {
59 # set location "test_abi_tag_function\[abi:tag1\](int)"
60 set location "test_abi_tag_function(int)"
61 set line "$cmd_prefix $location"
62 set start [index_after "_functio" $line]
63 test_complete_prefix_range $line $start
66 # Now the same, but start completing at the [. In that case,
67 # GDB considers the ABI tag as part of actual completion.
68 with_test_prefix "at tag" {
69 set location "test_abi_tag_function\[abi:tag1\](int)"
70 set line "$cmd_prefix $location"
71 set start [index_after "_function" $line]
72 test_complete_prefix_range $line $start
75 # Same, but with extra spaces. Note that the original spaces in
76 # the input line are preserved after completion.
78 with_test_prefix "spaces" {
79 test_gdb_complete_unique \
80 "$cmd_prefix test_abi_tag_function \[abi:tag1\] (" \
81 "$cmd_prefix test_abi_tag_function \[abi:tag1\] (int)"
83 test_gdb_complete_unique \
84 "$cmd_prefix test_abi_tag_function \[abi:tag1\] ( int " \
85 "$cmd_prefix test_abi_tag_function \[abi:tag1\] ( int )"
90 with_test_prefix "set breakpoints" {
91 foreach cmd_prefix {"b" "b -function"} {
92 # Test setting breakpoints. If the symbol name has an ABI
93 # tag, but the input linespec doesn't, then the ABI tag in the
94 # symbol name is ignored.
96 "test_abi_tag_function"
97 "test_abi_tag_function[abi:tag1]"
98 "test_abi_tag_function[abi:tag1](int)"
99 "test_abi_tag_function [abi:tag1]"
100 "test_abi_tag_function [abi:tag1] ( int )"
101 "test_abi_tag_function(int)"
102 "test_abi_tag_function (int)"
103 "test_abi_tag_function ( int )"
105 foreach linespec $linespec_list {
106 check_bp_locations_match_list \
107 "$cmd_prefix $linespec" [list $location]
112 with_test_prefix "set breakpoints wrong ABI tag" {
113 foreach cmd_prefix {"b" "b -function"} {
114 # Test setting breakpoints with the wrong ABI tag. Should
115 # fail to create the breakpoints. Completion should not find
118 "test_abi_tag_function[abi:tag2]"
119 "test_abi_tag_function[abi:tag2](int)"
120 "test_abi_tag_function [abi:tag2]"
121 "test_abi_tag_function [abi:tag2] ( int )"
123 foreach linespec $linespec_list {
124 check_setting_bp_fails "$cmd_prefix $linespec"
125 test_gdb_complete_none "$cmd_prefix $linespec"
131 # Test completion of overloaded functions with ABI tags.
132 with_test_prefix "completion of overloaded functions" {
133 foreach cmd_prefix {"b" "b -function"} {
134 set completion_list {
135 "test_abi_tag_ovld_function[abi:tag1]()"
136 "test_abi_tag_ovld_function[abi:tag1](int)"
139 # If the input string does not include the ABI tag, then
140 # actual completion ignores it.
141 test_gdb_complete_multiple \
142 "$cmd_prefix " "test_abi_tag_ovld_f" "unction(" \
145 # Otherwise, it's considered.
146 test_gdb_complete_multiple \
147 "$cmd_prefix " "test_abi_tag_ovld_function\[" "abi:tag1\](" \
153 # Test setting breakpoints on overloaded functions with ABI tags.
154 with_test_prefix "breakpoints on overloaded functions" {
155 foreach cmd_prefix {"b" "b -function"} {
156 set completion_list {
157 "test_abi_tag_ovld_function[abi:tag1]()"
158 "test_abi_tag_ovld_function[abi:tag1](int)"
161 "test_abi_tag_ovld_function"
162 "test_abi_tag_ovld_function[abi:tag1]"
164 foreach linespec $location_list {
165 check_bp_locations_match_list \
166 "$cmd_prefix $linespec" $completion_list
172 with_test_prefix "completion of overloaded functions different abi" {
173 foreach cmd_prefix {"b" "b -function"} {
174 # Test completion of overloaded functions with ABI tags.
175 set completion_list {
176 "test_abi_tag_ovld2_function()"
177 "test_abi_tag_ovld2_function[abi:tag1](short)"
178 "test_abi_tag_ovld2_function[abi:tag2](int)"
179 "test_abi_tag_ovld2_function[abi:tag2](long)"
182 # If the input string does not include the ABI tag, then
183 # actual completion ignores it.
184 test_gdb_complete_multiple \
185 "$cmd_prefix " "test_abi_tag_ovld2_f" "unction(" \
188 # Otherwise, it's considered. Match stops at the part of
189 # the tag that diverges, and the completion list only
190 # shows matches with ABI tags.
191 set completion_list {
192 "test_abi_tag_ovld2_function[abi:tag1](short)"
193 "test_abi_tag_ovld2_function[abi:tag2](int)"
194 "test_abi_tag_ovld2_function[abi:tag2](long)"
196 test_gdb_complete_multiple \
197 "$cmd_prefix " "test_abi_tag_ovld2_function\[" "abi:tag" \
200 # If you disambiguate, matches include only locations for
202 set completion_list {
203 "test_abi_tag_ovld2_function[abi:tag2](int)"
204 "test_abi_tag_ovld2_function[abi:tag2](long)"
206 test_gdb_complete_multiple \
207 "$cmd_prefix " "test_abi_tag_ovld2_function\[abi:tag2" "\](" \
210 test_gdb_complete_unique \
211 "$cmd_prefix test_abi_tag_ovld2_function\[abi:tag1" \
212 "$cmd_prefix test_abi_tag_ovld2_function\[abi:tag1\](short)"
216 with_test_prefix "completion of struct prefixes with tags" {
217 foreach cmd_prefix {"b" "b -function"} {
218 # Test completion of methods of structs with ABI tags.
219 set completion_list {
220 "test_abi_tag_struct[abi:tag1]::test_abi_tag_struct[abi:tag2]()"
221 "test_abi_tag_struct[abi:tag1]::~test_abi_tag_struct[abi:tag2]()"
224 # If the input string does not include the ABI tag, then
225 # actual completion ignores it.
226 test_gdb_complete_multiple \
227 "$cmd_prefix " "test_abi_tag_struc" "t::" \
230 # Otherwise, it's considered.
231 test_gdb_complete_multiple \
232 "$cmd_prefix " "test_abi_tag_struct\[" "abi:tag1\]::" \
235 # Mix and match different abi tag positions.
236 test_gdb_complete_unique \
237 "$cmd_prefix test_abi_tag_struct::t" \
238 "$cmd_prefix test_abi_tag_struct::test_abi_tag_struct()"
240 test_gdb_complete_unique \
241 "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::t" \
242 "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::test_abi_tag_struct()"
244 test_gdb_complete_unique \
245 "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::test_abi_tag_struct\[" \
246 "$cmd_prefix test_abi_tag_struct\[abi:tag1\]::test_abi_tag_struct\[abi:tag2\]()"
250 with_test_prefix "abi tag in parameters" {
251 foreach cmd_prefix {"b" "b -function"} {
252 # Complete all prefixes between "_funcio" and the full
253 # prototype. The ABI tag is not considered for actual
256 set completion_list {
257 "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2])"
258 "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2], abi_tag_param_struct2[abi:tag2])"
260 # If the input string does not include the ABI tag, then
261 # actual completion ignores it.
262 test_gdb_complete_multiple \
263 "$cmd_prefix " "test_abi_tag_in_para" "ms(abi_tag_param_struct1" \
266 # If OTOH the input string includes the ABI tag, then it
268 test_gdb_complete_multiple \
269 "$cmd_prefix " "test_abi_tag_in_params(abi_tag_param_struct1\[ab" "i:tag2\]"\
273 "test_abi_tag_in_params(abi_tag_param_struct1[abi:tag2], abi_tag_param_struct2[abi:tag2])"
276 set tags {"" "\[abi:tag2\]"}
279 set linespec "test_abi_tag_in_params(abi_tag_param_struct1${tag1}, abi_tag_param_struct2${tag2})"
280 check_bp_locations_match_list \
281 "$cmd_prefix $linespec" $location_list
287 # Check that the explicit location completer manages to find the
288 # option name after -function, when the -function's argument is a
289 # function with an ABI tag.
290 check_explicit_skips_function_argument \
291 "test_abi_tag_function\[abi:unknown\](int)"