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