scm-cmd.exp revision 1.9 1 1.9 christos # Copyright (C) 2009-2024 Free Software Foundation, Inc.
2 1.1 christos
3 1.1 christos # This program is free software; you can redistribute it and/or modify
4 1.1 christos # it under the terms of the GNU General Public License as published by
5 1.1 christos # the Free Software Foundation; either version 3 of the License, or
6 1.1 christos # (at your option) any later version.
7 1.1 christos #
8 1.1 christos # This program is distributed in the hope that it will be useful,
9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 1.1 christos # GNU General Public License for more details.
12 1.1 christos #
13 1.1 christos # You should have received a copy of the GNU General Public License
14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 1.1 christos
16 1.1 christos # This file is part of the GDB testsuite. It tests the mechanism
17 1.1 christos # for defining new GDB commands in Scheme.
18 1.1 christos
19 1.1 christos load_lib gdb-guile.exp
20 1.1 christos
21 1.9 christos require allow_guile_tests
22 1.9 christos
23 1.1 christos standard_testfile
24 1.1 christos
25 1.5 christos if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
26 1.1 christos return
27 1.1 christos }
28 1.1 christos
29 1.1 christos if ![gdb_guile_runto_main] {
30 1.1 christos return
31 1.1 christos }
32 1.1 christos
33 1.1 christos # Test a simple command, and command? while we're at it.
34 1.1 christos
35 1.1 christos gdb_test_multiline "input simple command" \
36 1.1 christos "guile" "" \
37 1.1 christos "(define test-cmd" "" \
38 1.1 christos " (make-command \"test-cmd\"" "" \
39 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
40 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
41 1.1 christos " (display (format #f \"test-cmd output, arg = ~a\\n\" arg)))))" "" \
42 1.1 christos "(register-command! test-cmd)" "" \
43 1.1 christos "end" ""
44 1.1 christos
45 1.1 christos gdb_test "guile (print (command? test-cmd))" "= #t"
46 1.1 christos gdb_test "guile (print (command? 42))" "= #f"
47 1.1 christos
48 1.1 christos gdb_test "test-cmd ugh" "test-cmd output, arg = ugh" "call simple command"
49 1.1 christos
50 1.1 christos # Test a prefix command, and a subcommand within it.
51 1.1 christos
52 1.1 christos gdb_test_multiline "input prefix command" \
53 1.1 christos "guile" "" \
54 1.1 christos "(register-command! (make-command \"prefix-cmd\"" "" \
55 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
56 1.1 christos " #:completer-class COMPLETE_NONE" "" \
57 1.1 christos " #:prefix? #t" "" \
58 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
59 1.1 christos " (display (format #f \"prefix-cmd output, arg = ~a\\n\" arg)))))" "" \
60 1.1 christos "end" ""
61 1.1 christos
62 1.1 christos gdb_test "prefix-cmd ugh" "prefix-cmd output, arg = ugh" "call prefix command"
63 1.1 christos
64 1.1 christos gdb_test_multiline "input subcommand" \
65 1.1 christos "guile" "" \
66 1.1 christos "(register-command! (make-command \"prefix-cmd subcmd\"" "" \
67 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
68 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
69 1.1 christos " (display (format #f \"subcmd output, arg = ~a\\n\" arg)))))" "" \
70 1.1 christos "end" ""
71 1.1 christos
72 1.1 christos gdb_test "prefix-cmd subcmd ugh" "subcmd output, arg = ugh" "call subcmd"
73 1.1 christos
74 1.1 christos # Test a subcommand in an existing GDB prefix.
75 1.1 christos
76 1.1 christos gdb_test_multiline "input new subcommand" \
77 1.1 christos "guile" "" \
78 1.1 christos "(register-command! (make-command \"info newsubcmd\"" "" \
79 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
80 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
81 1.1 christos " (display (format #f \"newsubcmd output, arg = ~a\\n\" arg)))))" "" \
82 1.1 christos "end" ""
83 1.1 christos
84 1.1 christos gdb_test "info newsubcmd ugh" "newsubcmd output, arg = ugh" "call newsubcmd"
85 1.1 christos
86 1.1 christos # Test a command that throws gdb:user-error.
87 1.1 christos
88 1.1 christos gdb_test_multiline "input command to throw error" \
89 1.1 christos "guile" "" \
90 1.1 christos "(register-command! (make-command \"test-error-cmd\"" "" \
91 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
92 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
93 1.1 christos " (throw-user-error \"you lose! ~a\" arg))))" "" \
94 1.1 christos "end" ""
95 1.1 christos
96 1.9 christos gdb_test "test-error-cmd ugh" "ERROR: you lose! ugh\r\n" "call error command"
97 1.1 christos
98 1.1 christos # Test string->argv.
99 1.1 christos
100 1.1 christos gdb_test "guile (raw-print (string->argv \"1 2 3\"))" \
101 1.1 christos {= \("1" "2" "3"\)} \
102 1.1 christos "(string->argv \"1 2 3\")"
103 1.1 christos
104 1.1 christos gdb_test "guile (raw-print (string->argv \"'1 2' 3\"))" \
105 1.1 christos {= \("1 2" "3"\)} \
106 1.1 christos "(string->argv \"'1 2' 3\")"
107 1.1 christos
108 1.1 christos gdb_test "guile (raw-print (string->argv \"\\\"1 2\\\" 3\"))" \
109 1.1 christos {= \("1 2" "3"\)} \
110 1.1 christos "(string->argv (\"\\\"1 2\\\" 3\")"
111 1.1 christos
112 1.1 christos gdb_test "guile (raw-print (string->argv \"1\\\\ 2 3\"))" \
113 1.1 christos {= \("1 2" "3"\)} \
114 1.1 christos "(string->argv \"1\\\\ 2 3\")"
115 1.1 christos
116 1.1 christos # Test user-defined guile commands.
117 1.1 christos
118 1.1 christos gdb_test_multiline "input simple user-defined command" \
119 1.1 christos "guile" "" \
120 1.1 christos "(register-command! (make-command \"test-help\"" "" \
121 1.1 christos " #:doc \"Docstring\"" "" \
122 1.1 christos " #:command-class COMMAND_USER" "" \
123 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
124 1.1 christos " (display (format #f \"test-cmd output, arg = ~a\\n\" arg)))))" "" \
125 1.1 christos "end" ""
126 1.1 christos
127 1.1 christos gdb_test "test-help ugh" "test-cmd output, arg = ugh" \
128 1.1 christos "call simple user-defined command"
129 1.1 christos
130 1.1 christos # Make sure the command shows up in `help user-defined`.
131 1.7 christos test_user_defined_class_help {"test-help -- Docstring[\r\n]"}
132 1.1 christos
133 1.1 christos # Make sure the command does not show up in `show user`.
134 1.1 christos gdb_test "show user test-help" "Not a user command\." \
135 1.1 christos "don't show user-defined scheme command in `show user command`"
136 1.1 christos
137 1.1 christos # Test expression completion on fields.
138 1.1 christos
139 1.1 christos gdb_test_multiline "expression completion command" \
140 1.1 christos "guile" "" \
141 1.1 christos "(register-command! (make-command \"expr-test\"" "" \
142 1.1 christos " #:command-class COMMAND_USER" ""\
143 1.1 christos " #:completer-class COMPLETE_EXPRESSION" "" \
144 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
145 1.1 christos " (display (format #f \"invoked on = ~a\\n\" arg)))))" "" \
146 1.1 christos "end" ""
147 1.1 christos
148 1.1 christos gdb_test "complete expr-test bar\." \
149 1.1 christos "expr-test bar\.bc.*expr-test bar\.ij.*" \
150 1.1 christos "test completion through complete command"
151 1.1 christos
152 1.9 christos
153 1.9 christos if { [readline_is_used] } {
154 1.9 christos set test "complete 'expr-test bar.i'"
155 1.9 christos send_gdb "expr-test bar\.i\t\t"
156 1.9 christos gdb_test_multiple "" "$test" {
157 1.9 christos -re "expr-test bar\.ij \\\x07$" {
158 1.9 christos send_gdb "\n"
159 1.9 christos gdb_test_multiple "" $test {
160 1.9 christos -re "invoked on = bar.ij.*$gdb_prompt $" {
161 1.9 christos pass "$test"
162 1.9 christos }
163 1.1 christos }
164 1.1 christos }
165 1.1 christos }
166 1.1 christos }
167 1.1 christos
168 1.1 christos # Test using a function for completion.
169 1.1 christos
170 1.1 christos gdb_test_multiline "completer-as-function command" \
171 1.1 christos "guile" "" \
172 1.1 christos "(register-command! (make-command \"completer-as-function\"" "" \
173 1.1 christos " #:command-class COMMAND_USER" ""\
174 1.1 christos " #:completer-class (lambda (self text word)" "" \
175 1.1 christos " (list \"1\" \"2\" \"3\"))" "" \
176 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
177 1.1 christos " (display (format #f \"invoked on = ~a\\n\" arg)))))" "" \
178 1.1 christos "end" ""
179 1.1 christos
180 1.1 christos gdb_test "complete completer-as-function 42\." \
181 1.1 christos "completer-as-function 42\.1.*completer-as-function 42\.2.*completer-as-function 42\.3" \
182 1.1 christos "test completion with completion function"
183 1.1 christos
184 1.1 christos # Test Scheme error in invoke function.
185 1.1 christos
186 1.1 christos gdb_test_multiline "input command with Scheme error" \
187 1.1 christos "guile" "" \
188 1.1 christos "(register-command! (make-command \"test-scheme-error-cmd\"" "" \
189 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
190 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
191 1.1 christos " oops-bad-spelling)))" "" \
192 1.1 christos "end" ""
193 1.1 christos
194 1.1 christos gdb_test "test-scheme-error-cmd ugh" \
195 1.1 christos "Error occurred in Scheme-implemented GDB command." \
196 1.1 christos "call scheme-error command"
197 1.1 christos
198 1.1 christos # If there is a problem with object management, this can often trigger it.
199 1.1 christos # It is useful to do this last, after we've created a bunch of command objects.
200 1.1 christos
201 1.1 christos gdb_test_no_output "guile (gc)"
202