]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/premature-dummy-frame-removal.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / premature-dummy-frame-removal.exp
1 # Copyright 2021-2024 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 # Make an inferior call to a function which uses longjmp. However,
17 # the backtrace for the function that is called is broken at the point
18 # where the longjmp is handled. This test is checking to see if the
19 # inferior call still completes successfully.
20 #
21 # This test forces a broken backtrace using Python, but in real life a
22 # broken backtrace can easily occur when calling through code for
23 # which there is no debug information if the prologue unwinder fails,
24 # which can often happen if the code has been optimized.
25 #
26 # The problem was that, due to the broken backtrace, GDB failed to
27 # find the inferior call's dummy frame. GDB then concluded that the
28 # inferior had longjmp'd backward past the dummy frame and so garbage
29 # collected the dummy frame, this causes the breakpoint within the
30 # dummy frame to be deleted.
31 #
32 # When the inferior continued, and eventually returned to the dummy
33 # frame, it would try to execute instruction from the dummy frame
34 # (which for most, or even all, targets, is on the stack), and then
35 # experience undefined behaviuor, often a SIGSEGV.
36
37 standard_testfile .c
38
39 require allow_python_tests
40
41 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
42 return -1
43 }
44
45 if {![runto_main]} {
46 return 0
47 }
48
49 set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
50 gdb_test_no_output "source ${pyfile}" "load python file"
51
52 gdb_test "p some_func ()" " = 0"
53
54 # When frame debugging is turned on, this test has (previously)
55 # revealed some crashes due to the Python frame unwinder trying to
56 # read registers.
57 #
58 # Enable frame debug and rerun the test. We don't bother checking the
59 # output of calling 'p some_func ()' as the output will be full of
60 # debug, to format of which isn't fixed. All we care about is that
61 # GDB is still running afterwards.
62 #
63 # All of the debug output makes this really slow when testing with the
64 # special read1 version of expect, hence the timeout factor.
65 with_read1_timeout_factor 10 {
66 gdb_test_no_output "set debug frame on"
67 gdb_test "p some_func ()" ".*" \
68 "repeat p some_func () with frame debug on"
69 gdb_test_no_output "set debug frame off"
70 }
71 gdb_test "p 1 + 2 + 3" " = 6"