1# This testcase is part of GDB, the GNU debugger. 2 3# Copyright 2004-2017 Free Software Foundation, Inc. 4 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18# Check that GDB can trigger and backtrace SIGSEGV signal stacks 19# caused by both accessing (data) and executing (code) at address 20# zero. 21 22# On function descriptor architectures, a zero descriptor, instead of 23# a NULL pointer, is used. That way the NULL code test always 24# contains a zero code reference. 25 26# For recovery, sigjmp/longjmp are used. 27 28# This also tests backtrace/gdb1476. 29 30if [target_info exists gdb,nosignals] { 31 verbose "Skipping signull.exp because of nosignals." 32 continue 33} 34 35 36standard_testfile .c 37 38if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { 39 untested "failed to compile" 40 return -1 41} 42 43clean_restart ${binfile} 44 45# 46# Run to `main' where we begin our tests. 47# 48 49if ![runto_main] then { 50 gdb_suppress_tests 51} 52 53# If we can examine what's at memory address 0, it is possible that we 54# could also execute it. This could probably make us run away, 55# executing random code, which could have all sorts of ill effects, 56# especially on targets without an MMU. Don't run the tests in that 57# case. 58 59if { [is_address_zero_readable] } { 60 untested "memory at address 0 is possibly executable" 61 return 62} 63 64# If an attempt to call a NULL pointer leaves the inferior in main, 65# then function pointers are descriptors, probe this and remember the 66# result. 67 68gdb_test_no_output "set test = code_entry_point" \ 69 "set for function pointer probe" 70set test "probe function pointer" 71set function_pointer code_entry_point 72set signame "SIGSEGV" 73gdb_test_multiple "continue" "$test" { 74 -re "Program received signal SIGSEGV.*bowler .*$gdb_prompt $" { 75 set function_pointer code_descriptor 76 pass "$test (function descriptor)" 77 } 78 -re "Program received signal SIGSEGV.*0.*$gdb_prompt $" { 79 pass "$test (function entry-point)" 80 } 81 -re "Program received signal SIGBUS.*0.*$gdb_prompt $" { 82 set signame SIGBUS 83 pass "$test (function entry-point)" 84 } 85} 86 87# Re-start from scratch, breakpoint the bowler so that control is 88# regained after each test, and run up to that. 89rerun_to_main 90gdb_test "break bowler" 91gdb_test "break keeper" 92# By default Stop:Yes Print:Yes Pass:Yes 93gdb_test "handle SIGSEGV" "SIGSEGV.*Yes.*Yes.*Yes.*Segmentation fault" 94gdb_test "handle SIGBUS" "SIGBUS.*Yes.*Yes.*Yes.*Bus error" 95 96# For the given signal type, check that: the SIGSEGV occures; a 97# backtrace from the SEGV works; the sigsegv is delivered; a backtrace 98# through the SEGV works. 99 100proc test_segv { name tag bt_from_segv bt_from_keeper } { 101 global signame 102 gdb_test continue "Breakpoint.* bowler.*" "${name}; start with the bowler" 103 # NB: Don't use $tag in the testname - changes across systems. 104 gdb_test_no_output "set test = $tag" "${name}; select the pointer type" 105 gdb_test continue "Program received signal ${signame}.*" \ 106 "${name}; take the ${signame}" 107 gdb_test backtrace $bt_from_segv "${name}; backtrace from ${signame}" 108 gdb_test continue "Breakpoint.* keeper.*" "${name}; continue to the keeper" 109 gdb_test backtrace $bt_from_keeper "${name}; backtrace from keeper through ${signame}" 110} 111 112test_segv "data read" data_read \ 113 {#0 .* bowler .*#1 .* main .*} \ 114 {#0 .* keeper .*#1 .* handler .*#2 .* bowler .*#3 .* main .*} 115test_segv "data write" data_write \ 116 {#0 .* bowler .*#1 .* main .*} \ 117 {#0 .* keeper .*#1 .* handler .*#2 .* bowler .*#3 .* main .*} 118test_segv code $function_pointer \ 119 {#0 .* 0x0+ .*#1 .* bowler .*#2 .* main .*} \ 120 {#0 .* keeper .*#1 .* handler .*#2 .* 0x0+ .*#3 .* bowler .*#4 .* main .*} 121