1 # Copyright (C) 2010-2014 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 # Test various error conditions.
18 set testfile "scm-error"
20 load_lib gdb-guile.exp
22 # Start with a fresh gdb.
26 # Skip all tests if Guile scripting is not enabled.
27 if { [skip_guile_tests] } { continue }
29 # Test error while loading .scm.
31 set remote_guile_file_1 [gdb_remote_download host \
32 ${srcdir}/${subdir}/${testfile}-1.scm]
33 set remote_guile_file_2 [gdb_remote_download host \
34 ${srcdir}/${subdir}/${testfile}-2.scm]
36 gdb_test "source $remote_guile_file_1" \
37 "(ERROR: )?In procedure \[+\]: Wrong type: #f.*" \
38 "error loading scm file caught"
40 gdb_test "p 1" " = 1" "no delayed error"
42 # Test setting/showing the various states for "guile print-stack".
44 gdb_test "show guile print-stack" \
45 "The mode of Guile exception printing on error is \"message\".*" \
46 "test print-stack show setting of default"
47 gdb_test_no_output "set guile print-stack full" \
48 "test print-stack full setting"
49 gdb_test "show guile print-stack" \
50 "The mode of Guile exception printing on error is \"full\".*" \
51 "test print-stack show setting to full"
52 gdb_test_no_output "set guile print-stack none" \
53 "test print-stack none setting"
54 gdb_test "show guile print-stack" \
55 "The mode of Guile exception printing on error is \"none\".*" \
56 "test print-stack show setting to none"
57 # Reset back to default, just in case.
58 gdb_test_no_output "set guile print-stack message" \
59 "reset print-stack to default, post set/show tests"
61 # Test "set guile print-stack none".
63 gdb_test_no_output "set guile print-stack none" \
64 "set print-stack to none, for error test"
66 set test_name "no error printed"
67 set command "guile (define x doesnt-exist)"
68 gdb_test_multiple $command $test_name {
69 -re "Backtrace.*$gdb_prompt $" { fail $test_name }
70 -re "ERROR.*$gdb_prompt $" { fail $test_name }
71 -re "$gdb_prompt $" { pass $test_name }
74 # Test "set guile print-stack message".
76 gdb_test_no_output "set guile print-stack message" \
77 "set print-stack to message, for error test"
79 set test_name "error message printed"
80 set command "guile (define x doesnt-exist)"
81 gdb_test_multiple $command $test_name {
82 -re "Backtrace.*$gdb_prompt $" { fail $test_name }
83 -re "ERROR.*$gdb_prompt $" { pass $test_name }
86 # Test "set guile print-stack full".
88 gdb_scm_test_silent_cmd "source $remote_guile_file_2" ""
90 gdb_test_no_output "set guile print-stack full" \
91 "set print-stack to full, for backtrace test"
93 gdb_test "guile (define x (top-func 42))" \
94 "Guile Backtrace:.*top-func (42|_).*middle-func (42|_).*bottom-func (42|_).*" \
97 # Verify gdb-specific errors are printed properly.
98 # i.e., each gdb error is registered to use init.scm:%error-printer.
100 gdb_test_no_output "set guile print-stack message" \
101 "set print-stack to message, for error printing tests"
103 gdb_test "guile (throw 'gdb:error \"subr\" \"misc error: ~a\" (list 42))" \
104 "ERROR: In procedure subr: misc error: 42.*"
106 gdb_test "guile (throw 'gdb:invalid-object-error \"subr\" \"invalid object error: ~a\" (list 42))" \
107 "ERROR: In procedure subr: invalid object error: 42.*"
109 gdb_test "guile (throw 'gdb:memory-error \"subr\" \"memory error: ~a\" (list 42))" \
110 "ERROR: In procedure subr: memory error: 42.*"
112 gdb_test "guile (throw 'gdb:pp-type-error \"subr\" \"pp-type error: ~a\" (list 42))" \
113 "ERROR: In procedure subr: pp-type error: 42.*"