1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2019-2020 Free Software Foundation, Inc.
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.
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.
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/>.
19 # This test verifies the "define-prefix" command.
24 # Verify the definition of user defined prefix commands.
25 # Test the definition of a command using these prefixes.
27 # Define an empty prefix command.
28 gdb_test_no_output "define-prefix abc-prefix"
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"
35 # Define a sub-prefix command.
36 gdb_test_no_output "define-prefix abc-prefix def-prefix"
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"
46 # Verify ghi-cmd works.
47 gdb_test "abc-prefix def-prefix ghi-cmd" \
49 "use user command: ghi-cmd"
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.
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>$" {
61 "define user command: ghi-prefix-cmd"
64 gdb_test_no_output "define-prefix abc-prefix def-prefix ghi-prefix-cmd"
66 # Verify a sequence ending with an empty prefix command cannot be used as
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"
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"
80 # Verify jkl-cmd command works.
81 gdb_test "abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
83 "use user command: jkl-cmd"
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"
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"
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"
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"
107 -re "$gdb_prompt $" {pass "define user command: ghi-prefix-cmd"}
108 timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
111 timeout {fail "(timeout) define user command: ghi-prefix-cmd"}
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"
119 # Now redefine ghi-prefix-cmd, and check it is working.
120 send_gdb "define abc-prefix def-prefix ghi-prefix-cmd\n"
122 -re "Keeping subcommands of prefix command \"ghi-prefix-cmd\"\.\r\nRedefine command \"ghi-prefix-cmd\".*y or n. $" {
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"
128 -re "$gdb_prompt $" {pass "redefine user command: ghi-prefix-cmd"}
129 timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
132 timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
135 -re "$gdb_prompt $" {fail "redefine user command: ghi-prefix-cmd"}
136 timeout {fail "(timeout) redefine user command: ghi-prefix-cmd"}
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"
144 # Check jkl-cmd still works.
145 gdb_test "abc-prefix def-prefix ghi-prefix-cmd jkl-cmd" \
147 "use user command after redefining ghi-prefix-cmd: jkl-cmd"
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"
155 # Check error behaviour.
157 gdb_test "define-prefix print" ".* is built-in.*"
159 gdb_test "define-prefix something-not-existing something-else" \
160 "Undefined command: \"something-not-existing\".*"
162 gdb_test "define-prefix abc-prefix something-not-existing something-else" \
163 "Undefined abc-prefix command: \"something-not-existing\".*"