1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# Copyright 2017-2020 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Test the "list" command with linespecs that expand to multiple
# locations.
standard_testfile list-ambiguous0.c list-ambiguous1.c
# Set EDITOR to true to prevent that GDB's edit command starts an actual
# editor.
setenv EDITOR true
if {[prepare_for_testing "failed to prepare" $testfile [list $srcfile $srcfile2] \
{debug}]} {
return -1
}
# Build source listing pattern based on an inclusive line range.
proc line_range_pattern { range_start range_end } {
global line_re
for {set i $range_start} {$i <= $range_end} {incr i} {
append pattern "\r\n$i\[ \t\]\[^\r\n\]*"
}
verbose -log "pattern $pattern"
return $pattern
}
# Test the "list" command with linespecs that expand to multiple
# locations.
proc test_list_ambiguous_symbol {symbol_line symbol} {
global srcfile srcfile2
set lineno0 [gdb_get_line_number $symbol_line $srcfile]
set lineno1 [gdb_get_line_number $symbol_line $srcfile2]
set lines0_re [line_range_pattern [expr $lineno0 - 5] [expr $lineno0 + 4]]
set lines1_re [line_range_pattern [expr $lineno1 - 5] [expr $lineno1 + 4]]
set any "\[^\r\n\]*"
set h0_re "file: \"${any}list-ambiguous0.c\", line number: $lineno0, symbol: \"$symbol\""
set h1_re "file: \"${any}list-ambiguous1.c\", line number: $lineno1, symbol: \"$symbol\""
gdb_test "list $symbol" "${h0_re}${lines0_re}\r\n${h1_re}${lines1_re}"
gdb_test "list main,$symbol" \
"Specified last line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
gdb_test "list ,$symbol" \
"Specified last line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
gdb_test "list $symbol,main" \
"Specified first line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
gdb_test "list $symbol,$symbol" \
"Specified first line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
gdb_test "list $symbol," \
"Specified first line '$symbol' is ambiguous:\r\n${h0_re}\r\n${h1_re}"
# While at it, test the "edit" command as well, since it shares
# code with "list".
gdb_test "edit $symbol" \
"Specified line is ambiguous:\r\n${h0_re}\r\n${h1_re}"
}
proc test_list_ambiguous_function {} {
test_list_ambiguous_symbol "ambiguous_fun (void)" "ambiguous_fun"
test_list_ambiguous_symbol "ambiguous_var" "ambiguous_var"
}
gdb_test_no_output "set listsize 10"
test_list_ambiguous_function
|