Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / list-ambiguous.exp
blob61e08eb30503a90ac74b6e0c83b447c1da444700
1 # Copyright 2017-2023 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 # Test the "list" command with linespecs that expand to multiple
17 # locations.
19 standard_testfile list-ambiguous0.c list-ambiguous1.c
21 # Set EDITOR to true to prevent that GDB's edit command starts an actual
22 # editor.
23 setenv EDITOR true
25 if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $srcfile2] \
26          {debug}]} {
27     return -1
30 # Build source listing pattern based on an inclusive line range.
32 proc line_range_pattern { range_start range_end } {
33     global line_re
35     for {set i $range_start} {$i <= $range_end} {incr i} {
36         append pattern "\r\n$i\[ \t\]\[^\r\n\]*"
37     }
39     verbose -log "pattern $pattern"
40     return $pattern
43 # Test the "list" command with linespecs that expand to multiple
44 # locations.
46 proc test_list_ambiguous_symbol {symbol_line symbol} {
47     global srcfile srcfile2
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]]
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}"
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}"
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}"
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"
81 gdb_test_no_output "set listsize 10"
83 test_list_ambiguous_function