1 # Copyright 2010-2018 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Utilities for Guile-scripting related tests.
18 # Guile doesn't print the 0x prefix on hex numbers.
21 # Return a 1 for configurations that do not support Guile scripting.
23 proc skip_guile_tests {} {
26 gdb_test_multiple "guile (display \"test\\n\")" "verify guile support" {
27 -re "Undefined command.*$gdb_prompt $" {
28 unsupported "Guile not supported."
31 -re "not supported.*$gdb_prompt $" {
32 unsupported "Guile support is disabled."
35 -re "$gdb_prompt $" {}
41 # Run a command in GDB, and report a failure if a Scheme exception is thrown.
42 # If report_pass is true, report a pass if no exception is thrown.
43 # This also catches the "Undefined command" error that happens if the user
44 # passes, e.g., "(print foo)" instead of "guile (print foo)".
46 proc gdb_scm_test_silent_cmd { cmd name {report_pass 1} } {
49 gdb_test_multiple $cmd $name {
50 -re "Backtrace.*$gdb_prompt $" { fail $name }
51 -re "ERROR.*$gdb_prompt $" { fail $name }
52 -re "Undefined command: .*$gdb_prompt $" { fail $name }
53 -re "$gdb_prompt $" { if $report_pass { pass $name } }
57 # Usage: gdb_test_multiline NAME INPUT RESULT {INPUT RESULT} ...
58 # Run a test named NAME, consisting of multiple lines of input.
59 # After each input line INPUT, search for result line RESULT.
60 # Succeed if all results are seen; fail otherwise.
61 # FIXME: Move to gdb.exp and remove Python's gdb_py_test_multiple.
63 proc gdb_test_multiline { name args } {
65 foreach {input result} $args {
66 if {[gdb_test_multiple $input "$name - $input" {
67 -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
77 # Load Scheme file FILE_NAME.
78 # TEST_NAME can be used to specify the name of the test,
79 # otherwise a standard test name is provided.
81 # Note: When Guile loads something and auto-compilation is enabled
82 # (which is useful and the default), then the first time a file is loaded
83 # Guile will compile the file and store the result somewhere
84 # (e.g., $HOME/.cache/guile). Output of the compilation process will
85 # appear in gdb.log. But since Guile only does this when necessary
86 # don't be confused if you don't always see it - Guile just skipped it
87 # because it thought it was unnecessary.
89 proc gdb_scm_load_file { file_name {test_name ""} } {
90 if { $test_name == "" } {
91 set test_name "guile (load \"[file tail $file_name]\")"
93 # Note: This can produce output if Guile compiles the file.
94 gdb_scm_test_silent_cmd "guile (load \"$file_name\")" $test_name
97 # Install various utilities in Guile to simplify tests.
99 # print - combination of display + newline
101 proc gdb_install_guile_utils { } {
102 # Define utilities in Guile to save needing (newline) all the time,
103 # and in the case of "print" add a prefix to help erroneous passes.
104 gdb_test_no_output "guile (define (print x) (format #t \"= ~A\" x) (newline))"
105 gdb_test_no_output "guile (define (raw-print x) (format #t \"= ~S\" x) (newline))"
108 # Install the gdb module.
110 proc gdb_install_guile_module { } {
111 gdb_test_no_output "guile (use-modules (gdb))"
114 # Wrapper around runto_main that installs the guile utils and module.
115 # The result is the same as for runto_main.
117 proc gdb_guile_runto_main { } {
119 fail "can't run to main"
123 gdb_install_guile_utils
124 gdb_install_guile_module