e0b59da6d12a747193a714970805e9a763368c8a
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / list-ambiguous.exp
1 # Copyright 2017-2021 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 the "list" command with linespecs that expand to multiple
17 # locations.
18
19 standard_testfile list-ambiguous0.c list-ambiguous1.c
20
21 # Set EDITOR to true to prevent that GDB's edit command starts an actual
22 # editor.
23 setenv EDITOR true
24
25 if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $srcfile2] \
26 {debug}]} {
27 return -1
28 }
29
30 # Build source listing pattern based on an inclusive line range.
31
32 proc line_range_pattern { range_start range_end } {
33 global line_re
34
35 for {set i $range_start} {$i <= $range_end} {incr i} {
36 append pattern "\r\n$i\[ \t\]\[^\r\n\]*"
37 }
38
39 verbose -log "pattern $pattern"
40 return $pattern
41 }
42
43 # Test the "list" command with linespecs that expand to multiple
44 # locations.
45
46 proc test_list_ambiguous_symbol {symbol_line symbol} {
47 global srcfile srcfile2
48
49 set lineno0 [gdb_get_line_number $symbol_line $srcfile]
50 set lineno1 [gdb_get_line_number $symbol_line $srcfile2]
51 set lines0_re [line_range_pattern [expr $lineno0 - 5] [expr $lineno0 + 4]]
52 set lines1_re [line_range_pattern [expr $lineno1 - 5] [expr $lineno1 + 4]]
53
54 set any "\[^\r\n\]*"
55 set h0_re "file: \"${any}list-ambiguous0.c\", line number: $lineno0, symbol: \"$symbol\""
56 set h1_re "file: \"${any}list-ambiguous1.c\", line number: $lineno1, symbol: \"$symbol\""
57 gdb_test "list $symbol" "${h0_re}${lines0_re}\r\n${h1_re}${lines1_re}"
58
59 gdb_test "list main,$symbol" \
60 "Specified last line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
61 gdb_test "list ,$symbol" \
62 "Specified last line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
63 gdb_test "list $symbol,main" \
64 "Specified first line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
65 gdb_test "list $symbol,$symbol" \
66 "Specified first line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
67 gdb_test "list $symbol," \
68 "Specified first line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
69
70 # While at it, test the "edit" command as well, since it shares
71 # code with "list".
72 gdb_test "edit $symbol" \
73 "Specified line is ambiguous:\r\n${h0_re}\r\n${h1_re}"
74 }
75
76 proc test_list_ambiguous_function {} {
77 test_list_ambiguous_symbol "ambiguous_fun (void)" "ambiguous_fun"
78 test_list_ambiguous_symbol "ambiguous_var" "ambiguous_var"
79 }
80
81 gdb_test_no_output "set listsize 10"
82
83 test_list_ambiguous_function
This page took 0.039063 seconds and 3 git commands to generate.