Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / define-prefix.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2019-2022 Free Software Foundation, Inc.
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
19 # This test verifies the "define-prefix" command.
20
21 gdb_start
22
23 ####################
24 # Verify the definition of user defined prefix commands.
25 # Test the definition of a command using these prefixes.
26
27 # Define an empty prefix command.
28 gdb_test_no_output "define-prefix abc-prefix"
29
30 # Verify an empty prefix command cannot be used as a command.
31 gdb_test "abc-prefix" \
32 "\"abc-prefix\" must be followed by the name of a subcommand.*" \
33 "execute prefix command not followed by subcommand"
34
35 # Define a sub-prefix command.
36 gdb_test_no_output "define-prefix abc-prefix def-prefix"
37
38 # Define ghi-cmd using the prefixes.
39 gdb_test_multiple "define abc-prefix def-prefix ghi-cmd" \
40 "define user command: abc-prefix def-prefix ghi-cmd" {
41 -re "Type commands for definition of \"abc-prefix def-prefix ghi-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
42 gdb_test "echo command ghi-cmd\\n\nend" "" \
43 "define user command: ghi-cmd"
44 }
45 }
46 # Verify ghi-cmd works.
47 gdb_test "abc-prefix def-prefix ghi-cmd" \
48 "command ghi-cmd" \
49 "use user command: ghi-cmd"
50
51
52 ####################
53 # Verify an existing (empty) command can be marked as a prefix command.
54 # Then verify an empty prefix command can be transformed into an executable command.
55
56 # Define ghi-prefix-cmd as an empty command.
57 gdb_test_multiple "define abc-prefix def-prefix ghi-prefix-cmd" \
58 "define user command: abc-prefix def-prefix ghi-prefix-cmd" {
59 -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
60 gdb_test "end" "" \
61 "define user command: ghi-prefix-cmd"
62 }
63 }
64 gdb_test_no_output "define-prefix abc-prefix def-prefix ghi-prefix-cmd"
65
66 # Verify a sequence ending with an empty prefix command cannot be used as
67 # a command.
68 gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
69 "\"abc-prefix def-prefix ghi-prefix-cmd\" must be followed by the name of a subcommand.*" \
70 "execute sequence of prefix commands not followed by a subcommand"
71
72 # Define jkl-cmd command.
73 gdb_test_multiple "define abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
74 "define user command: abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" {
75 -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd jkl-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
76 gdb_test "echo command jkl-cmd\\n\nend" "" \
77 "define user command: jkl-cmd"
78 }
79 }
80 # Verify jkl-cmd command works.
81 gdb_test "abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
82 "command jkl-cmd" \
83 "use user command: jkl-cmd"
84
85 # Define alternate-jkl-cmd and check it works.
86 # Define alternate-jkl-cmd command.
87 gdb_test_multiple "define abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
88 "define user command: abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" {
89 -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
90 gdb_test "echo command alternate-jkl-cmd\\n\nend" "" \
91 "define user command: alternate-jkl-cmd"
92 }
93 }
94 # Verify alternate-jkl-cmd command works.
95 gdb_test "abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
96 "command alternate-jkl-cmd" \
97 "use user command: alternate-jkl-cmd"
98
99
100
101 # Now define ghi-prefix-cmd as a real command, and check it is working.
102 send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
103 gdb_expect {
104 -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
105 send_gdb "echo defined command ghi-prefix-cmd\\n\nend\n"
106 gdb_expect {
107 -re "$gdb_prompt $" {pass "define user command: ghi-prefix-cmd"}
108 timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
109 }
110 }
111 timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
112 }
113
114 # Verify ghi-prefix-cmd command works.
115 gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
116 "defined command ghi-prefix-cmd" \
117 "use defined user command: ghi-prefix-cmd"
118
119 # Now redefine ghi-prefix-cmd, and check it is working.
120 send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
121 gdb_expect {
122 -re "Keeping subcommands of prefix command \"ghi-prefix-cmd\"\.\r\nRedefine command \"ghi-prefix-cmd\".*y or n. $" {
123 send_gdb "y\n"
124 gdb_expect {
125 -re "Type commands for definition of \"abc-prefix def-prefix ghi-prefix-cmd\".\r\nEnd with a line saying just \"end\".\r\n>$" {
126 send_gdb "echo redefined command ghi-prefix-cmd\\n\nend\n"
127 gdb_expect {
128 -re "$gdb_prompt $" {pass "redefine user command: ghi-prefix-cmd"}
129 timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
130 }
131 }
132 timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
133 }
134 }
135 -re "$gdb_prompt $" {fail "redefine user command: ghi-prefix-cmd"}
136 timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
137 }
138
139 # Verify redefined ghi-prefix-cmd command works.
140 gdb_test "abc-prefix def-prefix ghi-prefix-cmd" \
141 "redefined command ghi-prefix-cmd" \
142 "use redefined user command: ghi-prefix-cmd"
143
144 # Check jkl-cmd still works.
145 gdb_test "abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
146 "command jkl-cmd" \
147 "use user command after redefining ghi-prefix-cmd: jkl-cmd"
148
149 # Check alternate-jkl-cmd still works.
150 gdb_test "abc-prefix def-prefix ghi-prefix-cmd alternate-jkl-cmd" \
151 "command alternate-jkl-cmd" \
152 "use user command after redefining ghi-prefix-cmd: alternate-jkl-cmd"
153
154 ####################
155 # Check error behaviour.
156
157 gdb_test "define-prefix print" ".* is built-in.*"
158
159 gdb_test "define-prefix something-not-existing something-else" \
160 "Undefined command: \"something-not-existing\".*"
161
162 gdb_test "define-prefix abc-prefix something-not-existing something-else" \
163 "Undefined abc-prefix command: \"something-not-existing\".*"
164
This page took 0.054835 seconds and 4 git commands to generate.