[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / premature-dummy-frame-removal.exp
blobc813fbeb3d23f7d2b4fdac1d135f786ed95ce977
1 # Copyright 2021-2024 Free Software Foundation, Inc.
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.
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.
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/>.
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.
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.
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.
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.
37 standard_testfile .c
39 require allow_python_tests
41 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
42     return -1
45 if {![runto_main]} {
46     return 0
49 set pyfile [gdb_remote_download host ${srcdir}/${subdir}/${testfile}.py]
50 gdb_test_no_output "source ${pyfile}" "load python file"
52 set have_longjmp_probe [have_longjmp_probe]
54 set re_cannot_insert_bp \
55     [multi_line \
56          "Warning:" \
57          "Cannot insert breakpoint $::decimal\\." \
58          "Cannot access memory at address $::hex"]
60 gdb_test_multiple "p some_func ()" "" {
61     -re -wrap "\r\n$re_cannot_insert_bp\r\n.*" {
62         if { $have_longjmp_probe } {
63             fail $gdb_test_name
64         } else {
65             kfail gdb/26967 $gdb_test_name
66             return 0
67         }
68     }
69     -re -wrap " = 0" {
70         pass $gdb_test_name
71     }
74 # When frame debugging is turned on, this test has (previously)
75 # revealed some crashes due to the Python frame unwinder trying to
76 # read registers.
78 # Enable frame debug and rerun the test.  We don't bother checking the
79 # output of calling 'p some_func ()' as the output will be full of
80 # debug, to format of which isn't fixed.  All we care about is that
81 # GDB is still running afterwards.
83 gdb_test_no_output "set debug frame on"
84 gdb_test_lines "p some_func ()" \
85     "repeat p some_func () with frame debug on" \
86     ".*"
87 gdb_test_no_output "set debug frame off"
89 gdb_test "p 1 + 2 + 3" " = 6"