Add dwarf2_per_bfd::start_reading
[binutils-gdb.git] / gdb / testsuite / lib / gdb-guile.exp
blob412dd564ab8c7d3b6812aa073dd17727093d45d6
1 # Copyright 2010-2024 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.
19 set ghex {[0-9a-f]+}
21 # Return a 1 for configurations that support Guile scripting.
23 gdb_caching_proc allow_guile_tests {} {
24     set output [remote_exec host $::GDB "$::INTERNAL_GDBFLAGS --configuration"]
25     return [expr {[string first "--with-guile" $output] != -1}]
28 # Run a command in GDB, and report a failure if a Scheme exception is thrown.
29 # If report_pass is true, report a pass if no exception is thrown.
30 # This also catches the "Undefined command" error that happens if the user
31 # passes, e.g., "(print foo)" instead of "guile (print foo)".
33 proc gdb_scm_test_silent_cmd { cmd name {report_pass 1} } {
34     global gdb_prompt
36     gdb_test_multiple $cmd $name {
37         -re "Backtrace.*$gdb_prompt $" { fail $name }
38         -re "ERROR.*$gdb_prompt $"     { fail $name }
39         -re "Undefined command: .*$gdb_prompt $" { fail $name }
40         -re "$gdb_prompt $"            { if $report_pass { pass $name } }
41     }
44 # Load Scheme file FILE_NAME.
45 # TEST_NAME can be used to specify the name of the test,
46 # otherwise a standard test name is provided.
48 # Note: When Guile loads something and auto-compilation is enabled
49 # (which is useful and the default), then the first time a file is loaded
50 # Guile will compile the file and store the result somewhere
51 # (e.g., $HOME/.cache/guile).  Output of the compilation process will
52 # appear in gdb.log.  But since Guile only does this when necessary
53 # don't be confused if you don't always see it - Guile just skipped it
54 # because it thought it was unnecessary.
56 proc gdb_scm_load_file { file_name {test_name ""} } {
57     if { $test_name == "" } {
58         set test_name "guile (load \"[file tail $file_name]\")"
59     }
60     # Note: This can produce output if Guile compiles the file.
61     gdb_scm_test_silent_cmd "guile (load \"$file_name\")" $test_name
64 # Install various utilities in Guile to simplify tests.
66 # print - combination of display + newline
68 proc gdb_install_guile_utils { } {
69     # Define utilities in Guile to save needing (newline) all the time,
70     # and in the case of "print" add a prefix to help erroneous passes.
71     #
72     gdb_test_no_output -nopass \
73         "guile (define (print x) (format #t \"= ~A\" x) (newline))"
74     gdb_test_no_output -nopass \
75         "guile (define (raw-print x) (format #t \"= ~S\" x) (newline))"
78 # Install the gdb module.
80 proc gdb_install_guile_module { } {
81     gdb_test_no_output -nopass "guile (use-modules (gdb))"
84 # Wrapper around runto_main that installs the guile utils and module.
85 # The result is the same as for runto_main.
87 proc gdb_guile_runto_main { } {
88     if ![runto_main] {
89         return 0
90     }
92     gdb_install_guile_utils
93     gdb_install_guile_module
95     return 1