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
30 if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" \
32 object [list {additional_flags=-fomit-frame-pointer \
33 -funwind-tables -fasynchronous-unwind-tables}]] != "" } {
34 untested "couldn't compile with cfi"
38 set extension "no-cfi"
39 if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" \
41 object [list {additional_flags=-fomit-frame-pointer \
43 -fno-asynchronous-unwind-tables}]] != "" } {
44 untested "couldn't compile without cfi"
48 if {[gdb_compile [list "${objmainfile}" \
50 "${binfile}-${extension}" binfile {}] != ""} {
51 untested "couldn't link object files"
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"
63 gdb_test_no_output "maint frame-unwinder disable ARCH"
68 if {[gdb_compile "${srcdir}/${subdir}/${srcfile2}" \
70 object {debug}] != "" } {
71 untested "couldn't compile main file"
75 if { [prepare_test false] } {
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 *-*-*
88 # #0 callback () at ...
89 # #1 0x00000000004004e9 in caller ()
90 # #2 0x00000000004004cd in main () at ...
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"