]>
Commit | Line | Data |
---|---|---|
8bfabb04 AC |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
0fb0cc75 | 3 | # Copyright 2004, 2005, 2007, 2008, 2009 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 | ||
5f579bc5 | 30 | if [target_info exists gdb,nosignals] { |
446ab585 | 31 | verbose "Skipping signull.exp because of nosignals." |
5f579bc5 NS |
32 | continue |
33 | } | |
34 | ||
8bfabb04 AC |
35 | if $tracelevel { |
36 | strace $tracelevel | |
37 | } | |
38 | ||
39 | set prms_id 0 | |
40 | set bug_id 0 | |
41 | ||
42 | set testfile "signull" | |
43 | set srcfile ${testfile}.c | |
44 | set binfile ${objdir}/${subdir}/${testfile} | |
45 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
b60f0898 JB |
46 | untested signull.exp |
47 | return -1 | |
8bfabb04 AC |
48 | } |
49 | ||
50 | gdb_exit | |
51 | gdb_start | |
52 | gdb_reinitialize_dir $srcdir/$subdir | |
53 | gdb_load ${binfile} | |
54 | ||
55 | # | |
56 | # Run to `main' where we begin our tests. | |
57 | # | |
58 | ||
59 | if ![runto_main] then { | |
60 | gdb_suppress_tests | |
61 | } | |
62 | ||
63 | # If we can examine what's at memory address 0, it is possible that we | |
64 | # could also execute it. This could probably make us run away, | |
65 | # executing random code, which could have all sorts of ill effects, | |
66 | # especially on targets without an MMU. Don't run the tests in that | |
67 | # case. | |
68 | ||
69 | send_gdb "x 0\n" | |
70 | gdb_expect { | |
71 | -re "0x0:.*Cannot access memory at address 0x0.*$gdb_prompt $" { } | |
72 | -re "0x0:.*Error accessing memory address 0x0.*$gdb_prompt $" { } | |
73 | -re ".*$gdb_prompt $" { | |
74 | untested "Memory at address 0 is possibly executable" | |
75 | return | |
76 | } | |
77 | } | |
78 | ||
79 | # If an attempt to call a NULL pointer leaves the inferior in main, | |
80 | # then function pointers are descriptors, probe this and remember the | |
81 | # result. | |
82 | ||
83 | gdb_test "set test = code_entry_point" "" "set for function pointer probe" | |
84 | set test "probe function pointer" | |
85 | set function_pointer code_entry_point | |
86 | gdb_test_multiple "continue" "$test" { | |
9d9030bc | 87 | -re "Program received signal SIGSEGV.*bowler .*$gdb_prompt $" { |
8bfabb04 AC |
88 | set function_pointer code_descriptor |
89 | pass "$test (function descriptor)" | |
90 | } | |
91 | -re "Program received signal SIGSEGV.*0.*$gdb_prompt $" { | |
92 | pass "$test (function entry-point)" | |
93 | } | |
94 | } | |
95 | ||
96 | # Re-start from scratch, breakpoint the bowler so that control is | |
97 | # regained after each test, and run up to that. | |
98 | rerun_to_main | |
99 | gdb_test "break bowler" | |
100 | gdb_test "break keeper" | |
101 | # By default Stop:Yes Print:Yes Pass:Yes | |
102 | gdb_test "handle SIGSEGV" "SIGSEGV.*Yes.*Yes.*Yes.*Segmentation fault" | |
103 | ||
104 | # For the given signal type, check that: the SIGSEGV occures; a | |
105 | # backtrace from the SEGV works; the sigsegv is delivered; a backtrace | |
106 | # through the SEGV works. | |
107 | ||
108 | proc test_segv { name tag bt_from_segv bt_from_keeper } { | |
ec58997a AC |
109 | gdb_test continue "Breakpoint.* bowler.*" "${name}; start with the bowler" |
110 | # NB: Don't use $tag in the testname - changes across systems. | |
111 | gdb_test "set test = $tag" "" "${name}; select the pointer type" | |
112 | gdb_test continue "Program received signal SIGSEGV.*" \ | |
113 | "${name}; take the SIGSEGV" | |
114 | gdb_test backtrace $bt_from_segv "${name}; backtrace from SIGSEGV" | |
115 | gdb_test continue "Breakpoint.* keeper.*" "${name}; continue to the keeper" | |
116 | gdb_test backtrace $bt_from_keeper "${name}; backtrace from keeper through SIGSEGV" | |
8bfabb04 AC |
117 | } |
118 | ||
ec58997a | 119 | test_segv "data read" data_read \ |
9d9030bc AC |
120 | {#0 .* bowler .*#1 .* main .*} \ |
121 | {#0 .* keeper .*#1 .* handler .*#2 .* bowler .*#3 .* main .*} | |
ec58997a | 122 | test_segv "data write" data_write \ |
8bfabb04 AC |
123 | {#0 .* bowler .*#1 .* main .*} \ |
124 | {#0 .* keeper .*#1 .* handler .*#2 .* bowler .*#3 .* main .*} | |
125 | test_segv code $function_pointer \ | |
126 | {#0 .* 0x0+ .*#1 .* bowler .*#2 .* main .*} \ | |
127 | {#0 .* keeper .*#1 .* handler .*#2 .* 0x0+ .*#3 .* bowler .*#4 .* main .*} |