Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / gdb-guile.exp
CommitLineData
88b9d363 1# Copyright 2010-2022 Free Software Foundation, Inc.
ed3ef339
DE
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# Utilities for Guile-scripting related tests.
17
18# Guile doesn't print the 0x prefix on hex numbers.
19set ghex {[0-9a-f]+}
20
21# Return a 1 for configurations that do not support Guile scripting.
22
23proc skip_guile_tests {} {
24 global gdb_prompt
25
26 gdb_test_multiple "guile (display \"test\\n\")" "verify guile support" {
27 -re "Undefined command.*$gdb_prompt $" {
28 unsupported "Guile not supported."
29 return 1
30 }
31 -re "not supported.*$gdb_prompt $" {
32 unsupported "Guile support is disabled."
33 return 1
34 }
35 -re "$gdb_prompt $" {}
36 }
37
38 return 0
39}
40
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)".
45
46proc gdb_scm_test_silent_cmd { cmd name {report_pass 1} } {
47 global gdb_prompt
48
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 } }
54 }
55}
56
ed3ef339
DE
57# Load Scheme file FILE_NAME.
58# TEST_NAME can be used to specify the name of the test,
59# otherwise a standard test name is provided.
60#
61# Note: When Guile loads something and auto-compilation is enabled
62# (which is useful and the default), then the first time a file is loaded
63# Guile will compile the file and store the result somewhere
64# (e.g., $HOME/.cache/guile). Output of the compilation process will
65# appear in gdb.log. But since Guile only does this when necessary
66# don't be confused if you don't always see it - Guile just skipped it
67# because it thought it was unnecessary.
68
69proc gdb_scm_load_file { file_name {test_name ""} } {
70 if { $test_name == "" } {
71 set test_name "guile (load \"[file tail $file_name]\")"
72 }
73 # Note: This can produce output if Guile compiles the file.
74 gdb_scm_test_silent_cmd "guile (load \"$file_name\")" $test_name
75}
76
77# Install various utilities in Guile to simplify tests.
78#
79# print - combination of display + newline
80
81proc gdb_install_guile_utils { } {
82 # Define utilities in Guile to save needing (newline) all the time,
83 # and in the case of "print" add a prefix to help erroneous passes.
5c6f801d
AB
84 #
85 # Pass the empty string as the test name here, this means we don't
86 # get a pass/fail message for these tests, but also removes
87 # duplicate tests if this proc ends up getting called multiple
88 # times in a single test script.
89 gdb_test_no_output "guile (define (print x) (format #t \"= ~A\" x) (newline))" ""
90 gdb_test_no_output "guile (define (raw-print x) (format #t \"= ~S\" x) (newline))" ""
ed3ef339
DE
91}
92
93# Install the gdb module.
94
95proc gdb_install_guile_module { } {
5c6f801d
AB
96 # Pass the empty string as the test name here, this means we don't
97 # get a pass/fail message for these tests, but also removes
98 # duplicate tests if this proc ends up getting called multiple
99 # times in a single test script.
100 gdb_test_no_output "guile (use-modules (gdb))" ""
ed3ef339
DE
101}
102
103# Wrapper around runto_main that installs the guile utils and module.
104# The result is the same as for runto_main.
105
106proc gdb_guile_runto_main { } {
107 if ![runto_main] {
bc6c7af4 108 fail "can't run to main"
ed3ef339
DE
109 return 0
110 }
111
112 gdb_install_guile_utils
113 gdb_install_guile_module
114
115 return 1
116}
This page took 0.915119 seconds and 4 git commands to generate.