scm-cmd.exp revision 1.7 1 1.7 christos # Copyright (C) 2009-2020 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.1 christos standard_testfile
22 1.1 christos
23 1.5 christos if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
24 1.1 christos return
25 1.1 christos }
26 1.1 christos
27 1.1 christos # Skip all tests if Guile scripting is not enabled.
28 1.1 christos if { [skip_guile_tests] } { continue }
29 1.1 christos
30 1.1 christos if ![gdb_guile_runto_main] {
31 1.5 christos fail "can't run to main"
32 1.1 christos return
33 1.1 christos }
34 1.1 christos
35 1.1 christos # Test a simple command, and command? while we're at it.
36 1.1 christos
37 1.1 christos gdb_test_multiline "input simple command" \
38 1.1 christos "guile" "" \
39 1.1 christos "(define test-cmd" "" \
40 1.1 christos " (make-command \"test-cmd\"" "" \
41 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
42 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
43 1.1 christos " (display (format #f \"test-cmd output, arg = ~a\\n\" arg)))))" "" \
44 1.1 christos "(register-command! test-cmd)" "" \
45 1.1 christos "end" ""
46 1.1 christos
47 1.1 christos gdb_test "guile (print (command? test-cmd))" "= #t"
48 1.1 christos gdb_test "guile (print (command? 42))" "= #f"
49 1.1 christos
50 1.1 christos gdb_test "test-cmd ugh" "test-cmd output, arg = ugh" "call simple command"
51 1.1 christos
52 1.1 christos # Test a prefix command, and a subcommand within it.
53 1.1 christos
54 1.1 christos gdb_test_multiline "input prefix command" \
55 1.1 christos "guile" "" \
56 1.1 christos "(register-command! (make-command \"prefix-cmd\"" "" \
57 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
58 1.1 christos " #:completer-class COMPLETE_NONE" "" \
59 1.1 christos " #:prefix? #t" "" \
60 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
61 1.1 christos " (display (format #f \"prefix-cmd output, arg = ~a\\n\" arg)))))" "" \
62 1.1 christos "end" ""
63 1.1 christos
64 1.1 christos gdb_test "prefix-cmd ugh" "prefix-cmd output, arg = ugh" "call prefix command"
65 1.1 christos
66 1.1 christos gdb_test_multiline "input subcommand" \
67 1.1 christos "guile" "" \
68 1.1 christos "(register-command! (make-command \"prefix-cmd subcmd\"" "" \
69 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
70 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
71 1.1 christos " (display (format #f \"subcmd output, arg = ~a\\n\" arg)))))" "" \
72 1.1 christos "end" ""
73 1.1 christos
74 1.1 christos gdb_test "prefix-cmd subcmd ugh" "subcmd output, arg = ugh" "call subcmd"
75 1.1 christos
76 1.1 christos # Test a subcommand in an existing GDB prefix.
77 1.1 christos
78 1.1 christos gdb_test_multiline "input new subcommand" \
79 1.1 christos "guile" "" \
80 1.1 christos "(register-command! (make-command \"info newsubcmd\"" "" \
81 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
82 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
83 1.1 christos " (display (format #f \"newsubcmd output, arg = ~a\\n\" arg)))))" "" \
84 1.1 christos "end" ""
85 1.1 christos
86 1.1 christos gdb_test "info newsubcmd ugh" "newsubcmd output, arg = ugh" "call newsubcmd"
87 1.1 christos
88 1.1 christos # Test a command that throws gdb:user-error.
89 1.1 christos
90 1.1 christos gdb_test_multiline "input command to throw error" \
91 1.1 christos "guile" "" \
92 1.1 christos "(register-command! (make-command \"test-error-cmd\"" "" \
93 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
94 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
95 1.1 christos " (throw-user-error \"you lose! ~a\" arg))))" "" \
96 1.1 christos "end" ""
97 1.1 christos
98 1.1 christos gdb_test "test-error-cmd ugh" "ERROR: you lose! ugh" "call error command"
99 1.1 christos
100 1.1 christos # Test string->argv.
101 1.1 christos
102 1.1 christos gdb_test "guile (raw-print (string->argv \"1 2 3\"))" \
103 1.1 christos {= \("1" "2" "3"\)} \
104 1.1 christos "(string->argv \"1 2 3\")"
105 1.1 christos
106 1.1 christos gdb_test "guile (raw-print (string->argv \"'1 2' 3\"))" \
107 1.1 christos {= \("1 2" "3"\)} \
108 1.1 christos "(string->argv \"'1 2' 3\")"
109 1.1 christos
110 1.1 christos gdb_test "guile (raw-print (string->argv \"\\\"1 2\\\" 3\"))" \
111 1.1 christos {= \("1 2" "3"\)} \
112 1.1 christos "(string->argv (\"\\\"1 2\\\" 3\")"
113 1.1 christos
114 1.1 christos gdb_test "guile (raw-print (string->argv \"1\\\\ 2 3\"))" \
115 1.1 christos {= \("1 2" "3"\)} \
116 1.1 christos "(string->argv \"1\\\\ 2 3\")"
117 1.1 christos
118 1.1 christos # Test user-defined guile commands.
119 1.1 christos
120 1.1 christos gdb_test_multiline "input simple user-defined command" \
121 1.1 christos "guile" "" \
122 1.1 christos "(register-command! (make-command \"test-help\"" "" \
123 1.1 christos " #:doc \"Docstring\"" "" \
124 1.1 christos " #:command-class COMMAND_USER" "" \
125 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
126 1.1 christos " (display (format #f \"test-cmd output, arg = ~a\\n\" arg)))))" "" \
127 1.1 christos "end" ""
128 1.1 christos
129 1.1 christos gdb_test "test-help ugh" "test-cmd output, arg = ugh" \
130 1.1 christos "call simple user-defined command"
131 1.1 christos
132 1.1 christos # Make sure the command shows up in `help user-defined`.
133 1.7 christos test_user_defined_class_help {"test-help -- Docstring[\r\n]"}
134 1.1 christos
135 1.1 christos # Make sure the command does not show up in `show user`.
136 1.1 christos gdb_test "show user test-help" "Not a user command\." \
137 1.1 christos "don't show user-defined scheme command in `show user command`"
138 1.1 christos
139 1.1 christos # Test expression completion on fields.
140 1.1 christos
141 1.1 christos gdb_test_multiline "expression completion command" \
142 1.1 christos "guile" "" \
143 1.1 christos "(register-command! (make-command \"expr-test\"" "" \
144 1.1 christos " #:command-class COMMAND_USER" ""\
145 1.1 christos " #:completer-class COMPLETE_EXPRESSION" "" \
146 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
147 1.1 christos " (display (format #f \"invoked on = ~a\\n\" arg)))))" "" \
148 1.1 christos "end" ""
149 1.1 christos
150 1.1 christos gdb_test "complete expr-test bar\." \
151 1.1 christos "expr-test bar\.bc.*expr-test bar\.ij.*" \
152 1.1 christos "test completion through complete command"
153 1.1 christos
154 1.1 christos set test "complete 'expr-test bar.i'"
155 1.1 christos send_gdb "expr-test bar\.i\t\t"
156 1.1 christos gdb_test_multiple "" "$test" {
157 1.1 christos -re "expr-test bar\.ij \\\x07$" {
158 1.1 christos send_gdb "\n"
159 1.1 christos gdb_test_multiple "" $test {
160 1.1 christos -re "invoked on = bar.ij.*$gdb_prompt $" {
161 1.1 christos pass "$test"
162 1.1 christos }
163 1.1 christos }
164 1.1 christos }
165 1.1 christos }
166 1.1 christos
167 1.1 christos # Test using a function for completion.
168 1.1 christos
169 1.1 christos gdb_test_multiline "completer-as-function command" \
170 1.1 christos "guile" "" \
171 1.1 christos "(register-command! (make-command \"completer-as-function\"" "" \
172 1.1 christos " #:command-class COMMAND_USER" ""\
173 1.1 christos " #:completer-class (lambda (self text word)" "" \
174 1.1 christos " (list \"1\" \"2\" \"3\"))" "" \
175 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
176 1.1 christos " (display (format #f \"invoked on = ~a\\n\" arg)))))" "" \
177 1.1 christos "end" ""
178 1.1 christos
179 1.1 christos gdb_test "complete completer-as-function 42\." \
180 1.1 christos "completer-as-function 42\.1.*completer-as-function 42\.2.*completer-as-function 42\.3" \
181 1.1 christos "test completion with completion function"
182 1.1 christos
183 1.1 christos # Test Scheme error in invoke function.
184 1.1 christos
185 1.1 christos gdb_test_multiline "input command with Scheme error" \
186 1.1 christos "guile" "" \
187 1.1 christos "(register-command! (make-command \"test-scheme-error-cmd\"" "" \
188 1.1 christos " #:command-class COMMAND_OBSCURE" "" \
189 1.1 christos " #:invoke (lambda (self arg from-tty)" "" \
190 1.1 christos " oops-bad-spelling)))" "" \
191 1.1 christos "end" ""
192 1.1 christos
193 1.1 christos gdb_test "test-scheme-error-cmd ugh" \
194 1.1 christos "Error occurred in Scheme-implemented GDB command." \
195 1.1 christos "call scheme-error command"
196 1.1 christos
197 1.1 christos # If there is a problem with object management, this can often trigger it.
198 1.1 christos # It is useful to do this last, after we've created a bunch of command objects.
199 1.1 christos
200 1.1 christos gdb_test_no_output "guile (gc)"
201