[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / backtrace-through-cu-nodebug.exp
blob53bf642a92c6ec2870309db3b1fc9b5941a90d8d
1 # Copyright 2010-2025 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 # Test that GDB can generate accurate backtraces even if some of the stack
17 # trace goes through a function with no debug information.
19 standard_testfile -caller.c -main.c
20 set objmainfile [standard_output_file ${testfile}-main.o]
21 set objcallerfile [standard_output_file ${testfile}-caller.o]
23 # Recompile the inferior with or without CFI information, then run the
24 # inferior until the point where the important test starts.
25 # Returns FALSE on an ERROR.
26 proc prepare_test {has_cfi} {
27     global srcdir subdir srcfile srcfile2 objmainfile objcallerfile binfile
28     if {$has_cfi} {
29         set extension "cfi"
30         if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" \
31              "${objcallerfile}" \
32              object [list {additional_flags=-fomit-frame-pointer \
33                  -funwind-tables -fasynchronous-unwind-tables}]] != "" } {
34             untested "couldn't compile with cfi"
35             return false
36       }
37     } else {
38         set extension "no-cfi"
39         if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" \
40              "${objcallerfile}" \
41              object [list {additional_flags=-fomit-frame-pointer \
42                  -fno-unwind-tables \
43                  -fno-asynchronous-unwind-tables}]] != "" } {
44             untested "couldn't compile without cfi"
45             return false
46       }
47     }
48     if {[gdb_compile [list "${objmainfile}" \
49             "${objcallerfile}"] \
50             "${binfile}-${extension}" binfile {}] != ""} {
51         untested "couldn't link object files"
52         return false
53     }
55     clean_restart "$binfile-${extension}"
57     with_test_prefix "${extension}" {
59         if ![runto callback] then {
60            fail "has_cfi=$has_cfi: Can't run to callback"
61            return false
62         }
63         gdb_test_no_output "maint frame-unwinder disable ARCH"
64         return true
65     }
68 if {[gdb_compile "${srcdir}/${subdir}/${srcfile2}" \
69         "${objmainfile}" \
70         object {debug}] != "" } {
71     untested "couldn't compile main file"
72     return
75 if { [prepare_test false] } {
76     gdb_test "bt" \
77         [multi_line \
78              "\[^\r\n\]+Required frame unwinder may have been disabled, \[^\r\n\]+" \
79              "#0\\s+callback \\(\\) \[^\r\n\]+"] \
80         "verify unwind fail without CFI"
83 if { [prepare_test true] } {
84     if { [istarget "arm*-*-*"] } {
85         setup_kfail backtrace/31950 *-*-*
86     }
87     set text {[^\r\n]+}
88     # #0  callback () at ...
89     # #1  0x00000000004004e9 in caller ()
90     # #2  0x00000000004004cd in main () at ...
91     gdb_test "bt" \
92         "#0 +callback $text\r\n#1 $text in caller $text\r\n#2 $text in main $text" \
93         "Verify unwinding works based only on CFI information"