1# Copyright (C) 2010-2020 Free Software Foundation, Inc. 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# Test various error conditions. 17 18set testfile "scm-error" 19 20load_lib gdb-guile.exp 21 22# Start with a fresh gdb. 23gdb_exit 24gdb_start 25 26# Skip all tests if Guile scripting is not enabled. 27if { [skip_guile_tests] } { continue } 28 29# Test error while loading .scm. 30 31set remote_guile_file_1 [gdb_remote_download host \ 32 ${srcdir}/${subdir}/${testfile}-1.scm] 33set remote_guile_file_2 [gdb_remote_download host \ 34 ${srcdir}/${subdir}/${testfile}-2.scm] 35 36gdb_test "source $remote_guile_file_1" \ 37 "(ERROR: )?In procedure \[+\]: Wrong type.*: #f.*" \ 38 "error loading scm file caught" 39 40gdb_test "p 1" " = 1" "no delayed error" 41 42# Test setting/showing the various states for "guile print-stack". 43 44gdb_test "show guile print-stack" \ 45 "The mode of Guile exception printing on error is \"message\".*" \ 46 "test print-stack show setting of default" 47gdb_test_no_output "set guile print-stack full" \ 48 "test print-stack full setting" 49gdb_test "show guile print-stack" \ 50 "The mode of Guile exception printing on error is \"full\".*" \ 51 "test print-stack show setting to full" 52gdb_test_no_output "set guile print-stack none" \ 53 "test print-stack none setting" 54gdb_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. 58gdb_test_no_output "set guile print-stack message" \ 59 "reset print-stack to default, post set/show tests" 60 61# Test "set guile print-stack none". 62 63gdb_test_no_output "set guile print-stack none" \ 64 "set print-stack to none, for error test" 65 66set test_name "no error printed" 67set command "guile (define x doesnt-exist)" 68gdb_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 } 72} 73 74# Test "set guile print-stack message". 75 76gdb_test_no_output "set guile print-stack message" \ 77 "set print-stack to message, for error test" 78 79set test_name "error message printed" 80set command "guile (define x doesnt-exist)" 81gdb_test_multiple $command $test_name { 82 -re "Backtrace.*$gdb_prompt $" { fail $test_name } 83 -re "ERROR.*$gdb_prompt $" { pass $test_name } 84} 85 86# Test "set guile print-stack full". 87 88gdb_scm_test_silent_cmd "source $remote_guile_file_2" "" 89 90gdb_test_no_output "set guile print-stack full" \ 91 "set print-stack to full, for backtrace test" 92 93gdb_test "guile (define x (top-func 42))" \ 94 "Guile Backtrace:.*top-func (42|_).*middle-func (42|_).*bottom-func (42|_).*" \ 95 "backtrace printed" 96 97# Verify gdb-specific errors are printed properly. 98# i.e., each gdb error is registered to use init.scm:%error-printer. 99 100gdb_test_no_output "set guile print-stack message" \ 101 "set print-stack to message, for error printing tests" 102 103gdb_test "guile (throw 'gdb:error \"subr\" \"misc error: ~a\" (list 42))" \ 104 "ERROR: In procedure subr: misc error: 42.*" 105 106gdb_test "guile (throw 'gdb:invalid-object-error \"subr\" \"invalid object error: ~a\" (list 42))" \ 107 "ERROR: In procedure subr: invalid object error: 42.*" 108 109gdb_test "guile (throw 'gdb:memory-error \"subr\" \"memory error: ~a\" (list 42))" \ 110 "ERROR: In procedure subr: memory error: 42.*" 111 112gdb_test "guile (throw 'gdb:pp-type-error \"subr\" \"pp-type error: ~a\" (list 42))" \ 113 "ERROR: In procedure subr: pp-type error: 42.*" 114