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