Clarify "list" output when specified lines are ambiguous
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / define.exp
CommitLineData
61baf725 1# Copyright 1998-2017 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Elena Zannoni. (ezannoni@cygnus.com)
17
c906108c
SS
18
19#
20# test running programs
21#
c906108c 22
f76495c8 23standard_testfile break.c break1.c
c906108c 24
5b362f04 25if {[prepare_for_testing "failed to prepare" ${testfile} \
f76495c8
TT
26 [list $srcfile $srcfile2] {debug nowarnings}]} {
27 return -1
a1dea79a
FF
28}
29
a1dea79a
FF
30set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
31set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
32
c906108c
SS
33if ![runto_main] then { fail "define tests suppressed" }
34
35# Verify that GDB allows a user to define their very own commands.
36#
a76e022a
MS
37gdb_test_multiple "define nextwhere" "define user command: nextwhere" {
38 -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$" {
39 gdb_test "next\nbt\nend" "" \
40 "define user command: nextwhere"
41 }
c906108c
SS
42}
43
44# Verify that those commands work as gdb_expected.
45#
a76e022a
MS
46gdb_test "nextwhere" \
47 "$bp_location1\[ \t\]*printf.*#0\[ \t\]*main.*:$bp_location1.*" \
48 "use user command: nextwhere"
c906108c
SS
49
50# Verify that a user can define a command whose spelling is a
51# proper substring of another user-defined command.
52#
a76e022a
MS
53gdb_test_multiple "define nextwh" "define user command: nextwh" {
54 -re "Type commands for definition of \"nextwh\".\r\nEnd with a line saying just \"end\".\r\n>$" {
55 gdb_test "next 2\nbt\nend" "" \
56 "define user command: nextwh"
57 }
c906108c
SS
58}
59
60# Verify that a user can redefine their commands. (Test both the
61# confirmed and unconfirmed cases.)
62#
a76e022a
MS
63gdb_test "define nextwhere" \
64 "Command \"nextwhere\" not redefined.*" \
65 "redefine user command aborted: nextwhere" \
66 "Redefine command \"nextwhere\".*y or n. $" \
67 "n"
c906108c
SS
68
69send_gdb "define nextwhere\n"
70gdb_expect {
71 -re "Redefine command \"nextwhere\".*y or n. $"\
72 {send_gdb "y\n"
73 gdb_expect {
74 -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
75 {send_gdb "bt\nnext\nend\n"
76 gdb_expect {
77 -re "$gdb_prompt $"\
78 {pass "redefine user command: nextwhere"}
79 timeout {fail "(timeout) redefine user command: nextwhere"}
80 }
81 }
82 timeout {fail "(timeout) redefine user command: nextwhere"}
83 }
84 }
85 -re "$gdb_prompt $"\
86 {fail "redefine user command: nextwhere"}
87 timeout {fail "(timeout) redefine user command: nextwhere"}
88}
89
90# Verify that GDB gracefully handles an attempt to redefine the
91# help text for a builtin command.
92#
a76e022a
MS
93gdb_test "document step" "Command \"step\" is built-in.*" \
94 "redocumenting builtin command disallowed"
c906108c
SS
95
96# Verify that a user can document their own commands. (And redocument
97# them.)
98#
a76e022a
MS
99gdb_test_multiple "document nextwhere" "document user command: nextwhere" {
100 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$" {
101 gdb_test "A next command that first shows you where you're stepping from.\nend" \
102 "" \
103 "document user command: nextwhere"
104 }
c906108c
SS
105}
106
a76e022a
MS
107gdb_test_multiple "document nextwhere" "re-document user command: nextwhere" {
108 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$" {
109 gdb_test "A next command that first shows you where you're stepping from.\nend" \
110 "" \
111 "re-document user command: nextwhere"
112 }
c906108c
SS
113}
114
a76e022a
MS
115gdb_test "help nextwhere" \
116 "A next command that first shows you where you're stepping from.*" \
117 "help user command: nextwhere"
c906108c 118
311a4e6b
TJB
119# Verify that the document command preserves whitespace in the beginning of the line.
120#
a76e022a
MS
121gdb_test_multiple "document nextwhere" "set up whitespace in help string" {
122 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$" {
123 gdb_test " A next command that first shows you where you're stepping from.\nend" \
124 "" \
125 "set up whitespace in help string"
126 }
311a4e6b
TJB
127}
128
a76e022a
MS
129gdb_test "help nextwhere" \
130 " A next command that first shows you where you're stepping from.*" \
131 "preserve whitespace in help string"
311a4e6b 132
33f2d567
JM
133# Verify that the command parser doesn't require a space after an 'if'
134# command in a user defined function.
135#
136gdb_test_multiple "define ifnospace" "define user command: ifnospace" \
137{
138 -re "Type commands for definition of \"ifnospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
139 {
140 gdb_test_multiple "if(3<4)\nprint \"hi there\\n\"\nend\nend" "send body of ifnospace" \
141 {
142 -re "$gdb_prompt $"\
143 {pass "define user command: ifnospace"}
144 }
145 }
146}
147
148gdb_test "ifnospace" ".*hi there.*" "test ifnospace is parsed correctly"
149
604c4576
JG
150# Verify that the command parser properly handles command abbreviations.
151with_test_prefix "command abbreviations in define" {
152 set test "define user command: breakmain"
153 gdb_test_multiple "define breakmain" "$test" {
154 -re "Type commands for definition of \"breakmain\".\r\nEnd with a line saying just \"end\".\r\n>$" {
155 pass "$test"
156 set test "send body of breakmain"
157 gdb_test_multiple "break main\ncommand\necho\nend\nend" "$test" {
158 -re "$gdb_prompt $"\
159 {pass "$test"}
160 }
161 }
162 }
163
164 gdb_test "breakmain" ".*Breakpoint .*" "run user command"
165
166 # If GDB fails to interpret properly the abbrev "command", the last "end"
167 # will be missing. Issue it to avoid a desync that would break the other
168 # tests in this file.
169 gdb_test "end" \
170 "This command cannot be used at the top level.*" \
171 "additional end command"
172
173 gdb_test "info break \$bpnum" \
174 [multi_line \
175 "Num Type\[ \]+Disp Enb Address\[ \]+What.*" \
176 "\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*" \
177 "\[\t \]+echo.*"] \
178 "info break shows echo command"
179}
180
181
33f2d567
JM
182# Verify that the command parser doesn't require a space after an 'while'
183# command in a user defined function.
184#
185gdb_test_multiple "define whilenospace" "define user command: whilenospace" \
186{
187 -re "Type commands for definition of \"whilenospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
188 {
189 gdb_test_multiple "set \$i=1\nwhile(\$i<2)\nset \$i=2\nprint \"hi there\\n\"\nend\nend" "send body of whilenospace" \
190 {
191 -re "$gdb_prompt $" \
192 {pass "define user command: whilenospace"}
193 }
194 }
195}
196
197gdb_test "whilenospace" ".*hi there.*" "test whilenospace is parsed correctly"
198
c906108c
SS
199# Verify that the user can "hook" a builtin command. We choose to
200# hook the "stop" pseudo command, and we'll define it to use a user-
201# define command.
202#
a76e022a
MS
203gdb_test_multiple "define user-bt" "define user command: user-bt" {
204 -re "Type commands for definition of \"user-bt\".\r\nEnd with a line saying just \"end\".\r\n>$" {
205 gdb_test "bt\nend" \
206 "" \
207 "define user command: user-bt"
208 }
c906108c
SS
209}
210
a76e022a
MS
211gdb_test_multiple "define hook-stop" "define hook-stop command" {
212 -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$" {
213 gdb_test "user-b\nend" \
214 "" \
215 "define hook-stop command"
216 }
c906108c
SS
217}
218
a76e022a
MS
219gdb_test "next" "#0\[ \t\]*main.*:$bp_location11.*" \
220 "use hook-stop command"
c906108c
SS
221
222# Verify that GDB responds gracefully to an attempt to define a "hook
223# command" which doesn't exist. (Test both the confirmed and unconfirmed
224# cases.)
225#
a76e022a
MS
226gdb_test "define hook-bar" \
227 "Not confirmed.*" \
228 "define hook undefined command aborted: bar" \
229 "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $" \
230 "n"
c906108c
SS
231
232send_gdb "define hook-bar\n"
233gdb_expect {
234 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
235 {send_gdb "y\n"
236 gdb_expect {
237 -re "Type commands for definition of \"hook-bar\".\r\nEnd with a line saying just \"end\".\r\n>$"\
238 {send_gdb "nextwhere\nend\n"
239 gdb_expect {
240 -re "$gdb_prompt $"\
241 {pass "define hook undefined command: bar"}
242 timeout {fail "(timeout) define hook undefined command: bar"}
243 }
244 }
245 -re "$gdb_prompt $"\
246 {fail "define hook undefined command: bar"}
247 timeout {fail "(timeout) define hook undefined command: bar"}
248 }
249 }
250 -re "$gdb_prompt $"\
251 {fail "define hook undefined command: bar"}
252 timeout {fail "(timeout) define hook undefined command: bar"}
253}
254
adb483fe
DJ
255# Test creation of an additional target subcommand.
256gdb_test_multiple "define target testsuite" "" {
257 -re "Type commands for definition of \"target testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" {
258 gdb_test "printf \"hello\\n\"\nend" "" "define target testsuite"
259 }
260}
261gdb_test_multiple "document target testsuite" "" {
262 -re "Type documentation for \"target testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" {
263 gdb_test "A test target.\nend" "" "document target testsuite"
264 }
265}
266
267gdb_test "help target" ".*A test target.*"
268gdb_test "target testsuite" "hello"
269gdb_test "show user target testsuite" "User command \"target testsuite\":\r\n printf \"hello\\\\n\"\r\n"
270
271# We should even be able to hook subcommands.
272gdb_test_multiple "define target hook-testsuite" "" {
273 -re "Type commands for definition of \"target hook-testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" {
274 gdb_test "printf \"one\\n\"\nend" "" "define target hook-testsuite"
275 }
276}
277
278gdb_test_multiple "define target hookpost-testsuite" "" {
279 -re "Type commands for definition of \"target hookpost-testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" {
280 gdb_test "printf \"two\\n\"\nend" "" "define target hookpost-testsuite"
281 }
282}
283
284gdb_test "target testsuite" "one\r\nhello\r\ntwo" "target testsuite with hooks"
285
c906108c
SS
286# This is a quasi-define command: Verify that the user can redefine
287# GDB's gdb_prompt.
288#
a76e022a
MS
289gdb_test_multiple "set prompt \\(blah\\) " "set gdb_prompt" {
290 -re "\\(blah\\) $" {
291 pass "set gdb_prompt"
292 }
c906108c
SS
293}
294
a76e022a
MS
295gdb_test_multiple "set prompt \\(gdb\\) " "reset gdb_prompt" {
296 -re "$gdb_prompt $" {
297 pass "reset gdb_prompt"
298 }
c906108c
SS
299}
300
301gdb_exit
302return 0
This page took 3.09423 seconds and 4 git commands to generate.