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 # Give the files a new name so we don't clobber the real one if
33 set remote_guile_file_1 [gdb_remote_download host \
34 ${srcdir}/${subdir}/${testfile}-1.scm \
35 ${subdir}/t-${testfile}-1.scm]
36 set remote_guile_file_2 [gdb_remote_download host \
37 ${srcdir}/${subdir}/${testfile}-2.scm \
38 ${subdir}/t-${testfile}-2.scm]
40 gdb_test "source $remote_guile_file_1" \
41 "(ERROR: )?In procedure \[+\]: Wrong type: #f.*" \
42 "error loading scm file caught"
44 gdb_test "p 1" " = 1" "no delayed error"
46 # Test setting/showing the various states for "guile print-stack".
48 gdb_test "show guile print-stack" \
49 "The mode of Guile exception printing on error is \"message\".*" \
50 "test print-stack show setting of default"
51 gdb_test_no_output "set guile print-stack full" \
52 "test print-stack full setting"
53 gdb_test "show guile print-stack" \
54 "The mode of Guile exception printing on error is \"full\".*" \
55 "test print-stack show setting to full"
56 gdb_test_no_output "set guile print-stack none" \
57 "test print-stack none setting"
58 gdb_test "show guile print-stack" \
59 "The mode of Guile exception printing on error is \"none\".*" \
60 "test print-stack show setting to none"
61 # Reset back to default, just in case.
62 gdb_test_no_output "set guile print-stack message" \
63 "reset print-stack to default, post set/show tests"
65 # Test "set guile print-stack none".
67 gdb_test_no_output "set guile print-stack none" \
68 "set print-stack to none, for error test"
70 set test_name "no error printed"
71 set command "guile (define x doesnt-exist)"
72 gdb_test_multiple $command $test_name {
73 -re "Backtrace.*$gdb_prompt $" { fail $test_name }
74 -re "ERROR.*$gdb_prompt $" { fail $test_name }
75 -re "$gdb_prompt $" { pass $test_name }
78 # Test "set guile print-stack message".
80 gdb_test_no_output "set guile print-stack message" \
81 "set print-stack to message, for error test"
83 set test_name "error message printed"
84 set command "guile (define x doesnt-exist)"
85 gdb_test_multiple $command $test_name {
86 -re "Backtrace.*$gdb_prompt $" { fail $test_name }
87 -re "ERROR.*$gdb_prompt $" { pass $test_name }
90 # Test "set guile print-stack full".
92 gdb_scm_test_silent_cmd "source $remote_guile_file_2" ""
94 gdb_test_no_output "set guile print-stack full" \
95 "set print-stack to full, for backtrace test"
97 gdb_test "guile (define x (top-func 42))" \
98 "Guile Backtrace:.*top-func 42.*middle-func 42.*bottom-func 42.*" \
101 # Verify gdb-specific errors are printed properly.
102 # i.e., each gdb error is registered to use init.scm:%error-printer.
104 gdb_test_no_output "set guile print-stack message" \
105 "set print-stack to message, for error printing tests"
107 gdb_test "guile (throw 'gdb:error \"subr\" \"misc error: ~a\" (list 42))" \
108 "ERROR: In procedure subr: misc error: 42.*"
110 gdb_test "guile (throw 'gdb:invalid-object-error \"subr\" \"invalid object error: ~a\" (list 42))" \
111 "ERROR: In procedure subr: invalid object error: 42.*"
113 gdb_test "guile (throw 'gdb:memory-error \"subr\" \"memory error: ~a\" (list 42))" \
114 "ERROR: In procedure subr: memory error: 42.*"
116 gdb_test "guile (throw 'gdb:pp-type-error \"subr\" \"pp-type error: ~a\" (list 42))" \
117 "ERROR: In procedure subr: pp-type error: 42.*"