blob: 8a23c9b213f859cda5c6fc174ddb37460f7dd0a0 (
plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# Copyright 2024-2025 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 'edit' command.
# This relies on setting environment variables, so best to run on
# non-remote hosts.
require {!is_remote host}
standard_testfile
if {[prepare_for_testing "failed to prepare" $testfile $srcfile]} {
return
}
# Check that 'echo' is available in the shell.
gdb_test_multiple "shell echo test 1234 xyz" "check echo is available" {
-re -wrap "^test 1234 xyz" {
}
-re -wrap "" {
unsupported "shell cannot use echo command"
return
}
}
if {![runto_main]} {
return
}
# Are we using DWARF debug format?
get_debug_format
set non_dwarf [expr ! [test_debug_format "DWARF \[0-9\]"]]
# Find line numbers for use in tests.
set line_0 [gdb_get_line_number "prologue location"]
set line_1 [gdb_get_line_number "first location"]
set line_2 [gdb_get_line_number "second location"]
set line_3 [gdb_get_line_number "third location"]
set line_4 [gdb_get_line_number "fourth location"]
# Regexp to match SRCFILE.
set srcfile_re [string_to_regexp [file normalize $srcdir/$subdir]/$srcfile]
set srcfile_re_simple "\[^\r\n\]+/[string_to_regexp $srcfile]"
# Setup the EDITOR environment variable to run our helper script, and
# then run the tests.
save_vars { env(EDITOR) } {
set env(EDITOR) "echo"
# Start with no test binary loaded.
clean_restart
gdb_test "edit" \
"^No symbol table is loaded. Use the \"file\" command\\." \
"try edit when no symbol file is loaded"
# Now start with a test binary.
clean_restart $binfile
with_test_prefix "before starting inferior" {
# We should be able to find the default location (of main)
# even for non-dwarf debug formats, but this currently fails
# with the stabs board.
if { $non_dwarf } { setup_xfail *-*-* }
# Additionally, some targets will report the default location
# as the opening brace of main, while others report the first
# line of code inside main. For this test either will do.
gdb_test "edit" \
"\r\n\\+(?:$line_0|$line_1) $srcfile_re" \
"check edit of default location"
gdb_test "list $line_4" \
"\r\n$line_4\\s+\[^\r\n\]+/\\* fourth location \\*/\r\n.*" \
"list lines around the fourth location"
gdb_test "edit" \
"\r\n\\+$line_4 $srcfile_re" \
"check edit of fourth location after listing"
gdb_test "edit $line_2" \
"\r\n\\+$line_2 $srcfile_re" \
"check edit of second location"
gdb_test "edit xxx" \
"^Function \"xxx\" not defined\\." \
"try to edit an unknown function"
}
if {![runto_main]} {
return
}
set first_loc_pc [get_hexadecimal_valueof "\$pc" "*UNKNOWN*" \
"get \$pc at first location"]
with_test_prefix "stopped at first location" {
gdb_test "edit" \
"\r\n\\+$line_1 $srcfile_re" \
"check edit of current location"
}
gdb_breakpoint $line_2
gdb_continue_to_breakpoint "stop at second location"
with_test_prefix "at second location" {
gdb_test "edit" \
"\r\n\\+$line_2 $srcfile_re" \
"check edit current location results"
gdb_test "edit $line_3" \
"\r\n\\+$line_3 $srcfile_re" \
"check edit third location results"
}
with_test_prefix "list first location" {
gdb_test "list $line_1" \
"\r\n$line_1\\s+\[^\r\n\]+/\\* first location \\*/\r\n.*" \
"list lines around the first location"
gdb_test "edit" \
"\r\n\\+$line_1 $srcfile_re" \
"check edit current location results"
}
gdb_breakpoint $line_4
gdb_continue_to_breakpoint "stop at fourth location"
with_test_prefix "at fourth location" {
gdb_test "edit" \
"\r\n\\+$line_4 $srcfile_re" \
"check edit current location results"
gdb_test "edit $line_1" \
"\r\n\\+$line_1 $srcfile_re" \
"check edit first location results"
gdb_test "edit *$first_loc_pc" \
[multi_line \
"[string_to_regexp $first_loc_pc] is in main \\($srcfile_re_simple:$line_1\\)\\." \
"\\+$line_1 $srcfile_re"] \
"check edit first location by address results"
}
}
|