]>
Commit | Line | Data |
---|---|---|
8bfabb04 AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | # Copyright 2004-2024 Free Software Foundation, Inc. |
8bfabb04 AC |
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 | |
e22f8b7c | 7 | # the Free Software Foundation; either version 3 of the License, or |
8bfabb04 AC |
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 | |
e22f8b7c | 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
8bfabb04 AC |
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 | ||
450d26c8 | 30 | require {!target_info exists gdb,nosignals} |
5f579bc5 | 31 | |
8bfabb04 | 32 | |
0ab77f5f TT |
33 | standard_testfile .c |
34 | ||
8bfabb04 | 35 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
84c93cd5 | 36 | untested "failed to compile" |
b60f0898 | 37 | return -1 |
8bfabb04 AC |
38 | } |
39 | ||
0ab77f5f | 40 | clean_restart ${binfile} |
8bfabb04 AC |
41 | |
42 | # | |
43 | # Run to `main' where we begin our tests. | |
44 | # | |
45 | ||
65a33d75 | 46 | if {![runto_main]} { |
c8ee3f04 | 47 | return 0 |
8bfabb04 AC |
48 | } |
49 | ||
50 | # If we can examine what's at memory address 0, it is possible that we | |
51 | # could also execute it. This could probably make us run away, | |
52 | # executing random code, which could have all sorts of ill effects, | |
53 | # especially on targets without an MMU. Don't run the tests in that | |
54 | # case. | |
55 | ||
20c6f1e1 | 56 | if { [is_address_zero_readable] } { |
bc6c7af4 | 57 | untested "memory at address 0 is possibly executable" |
20c6f1e1 | 58 | return |
8bfabb04 AC |
59 | } |
60 | ||
61 | # If an attempt to call a NULL pointer leaves the inferior in main, | |
62 | # then function pointers are descriptors, probe this and remember the | |
63 | # result. | |
64 | ||
27d3a1a2 MS |
65 | gdb_test_no_output "set test = code_entry_point" \ |
66 | "set for function pointer probe" | |
8bfabb04 AC |
67 | set test "probe function pointer" |
68 | set function_pointer code_entry_point | |
aacd552b | 69 | set signame "SIGSEGV" |
8bfabb04 | 70 | gdb_test_multiple "continue" "$test" { |
9d9030bc | 71 | -re "Program received signal SIGSEGV.*bowler .*$gdb_prompt $" { |
8bfabb04 AC |
72 | set function_pointer code_descriptor |
73 | pass "$test (function descriptor)" | |
74 | } | |
75 | -re "Program received signal SIGSEGV.*0.*$gdb_prompt $" { | |
76 | pass "$test (function entry-point)" | |
77 | } | |
aacd552b TG |
78 | -re "Program received signal SIGBUS.*0.*$gdb_prompt $" { |
79 | set signame SIGBUS | |
80 | pass "$test (function entry-point)" | |
81 | } | |
8bfabb04 AC |
82 | } |
83 | ||
84 | # Re-start from scratch, breakpoint the bowler so that control is | |
85 | # regained after each test, and run up to that. | |
86 | rerun_to_main | |
87 | gdb_test "break bowler" | |
88 | gdb_test "break keeper" | |
89 | # By default Stop:Yes Print:Yes Pass:Yes | |
90 | gdb_test "handle SIGSEGV" "SIGSEGV.*Yes.*Yes.*Yes.*Segmentation fault" | |
aacd552b | 91 | gdb_test "handle SIGBUS" "SIGBUS.*Yes.*Yes.*Yes.*Bus error" |
8bfabb04 AC |
92 | |
93 | # For the given signal type, check that: the SIGSEGV occures; a | |
94 | # backtrace from the SEGV works; the sigsegv is delivered; a backtrace | |
95 | # through the SEGV works. | |
96 | ||
97 | proc test_segv { name tag bt_from_segv bt_from_keeper } { | |
aacd552b | 98 | global signame |
ec58997a AC |
99 | gdb_test continue "Breakpoint.* bowler.*" "${name}; start with the bowler" |
100 | # NB: Don't use $tag in the testname - changes across systems. | |
27d3a1a2 | 101 | gdb_test_no_output "set test = $tag" "${name}; select the pointer type" |
aacd552b TG |
102 | gdb_test continue "Program received signal ${signame}.*" \ |
103 | "${name}; take the ${signame}" | |
104 | gdb_test backtrace $bt_from_segv "${name}; backtrace from ${signame}" | |
ec58997a | 105 | gdb_test continue "Breakpoint.* keeper.*" "${name}; continue to the keeper" |
aacd552b | 106 | gdb_test backtrace $bt_from_keeper "${name}; backtrace from keeper through ${signame}" |
8bfabb04 AC |
107 | } |
108 | ||
ec58997a | 109 | test_segv "data read" data_read \ |
9d9030bc AC |
110 | {#0 .* bowler .*#1 .* main .*} \ |
111 | {#0 .* keeper .*#1 .* handler .*#2 .* bowler .*#3 .* main .*} | |
ec58997a | 112 | test_segv "data write" data_write \ |
8bfabb04 AC |
113 | {#0 .* bowler .*#1 .* main .*} \ |
114 | {#0 .* keeper .*#1 .* handler .*#2 .* bowler .*#3 .* main .*} | |
115 | test_segv code $function_pointer \ | |
116 | {#0 .* 0x0+ .*#1 .* bowler .*#2 .* main .*} \ | |
117 | {#0 .* keeper .*#1 .* handler .*#2 .* 0x0+ .*#3 .* bowler .*#4 .* main .*} |