xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.dwarf2/frame-inlined-in-outer-frame.exp (revision c9055873d0546e63388f027d3d7f85381cde0545)
1# Copyright 2020-2023 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# Test unwinding when we have a frame inlined in the outer frame (in the sense
17# of frame.c:outer_frame_id).
18#
19# The conditions required to reproduce the original issue are:
20#
21#  1. Have an outer frame whose DWARF CFI explicitly says that the frame return
22#     address is undefined.
23#  2. A frame inlined in this other frame.
24#
25# Because of (1), the test has to be written in assembly with explicit CFI
26# directives.
27
28# Check if starti command is supported.
29require use_gdb_stub 0
30
31load_lib dwarf.exp
32
33if {![dwarf2_support]} {
34    return 0
35}
36
37standard_testfile .S
38
39set dwarf_asm [standard_output_file dwarf-asm.S]
40Dwarf::assemble $dwarf_asm {
41    global srcfile
42
43    declare_labels foo_subprogram bar_subprogram
44    declare_labels stmt_list
45
46    # See the comment in the .S file for the equivalent C program this is meant
47    # to represent.
48
49    cu { label cu_label addr_size 4 } {
50	DW_TAG_compile_unit {
51	    {DW_AT_name $srcfile}
52	    {DW_AT_stmt_list $stmt_list DW_FORM_sec_offset}
53	    {DW_AT_language @DW_LANG_C99}
54	    {DW_AT_low_pc __cu_low_pc DW_FORM_addr}
55	    {DW_AT_high_pc __cu_high_pc DW_FORM_addr}
56	} {
57	    DW_TAG_subprogram {
58		{DW_AT_name "_start"}
59		{DW_AT_low_pc __start_low_pc DW_FORM_addr}
60		{DW_AT_high_pc __start_high_pc DW_FORM_addr}
61	    } {
62		DW_TAG_inlined_subroutine {
63		    {DW_AT_abstract_origin :$foo_subprogram}
64		    {DW_AT_low_pc __foo_low_pc DW_FORM_addr}
65		    {DW_AT_high_pc __foo_high_pc DW_FORM_addr}
66		    {DW_AT_call_file 1 DW_FORM_data1}
67		    {DW_AT_call_line 13 DW_FORM_data1}
68		} {
69		    DW_TAG_inlined_subroutine {
70			{DW_AT_abstract_origin :$bar_subprogram}
71			{DW_AT_low_pc __bar_low_pc DW_FORM_addr}
72			{DW_AT_high_pc __bar_high_pc DW_FORM_addr}
73			{DW_AT_call_file 1 DW_FORM_data1}
74			{DW_AT_call_line 7 DW_FORM_data1}
75		    }
76		}
77	    }
78
79	    foo_subprogram: DW_TAG_subprogram {
80		{DW_AT_name "foo"}
81		{DW_AT_prototyped 1 DW_FORM_flag_present}
82		{DW_AT_inline 0x1 DW_FORM_data1}
83	    }
84
85	    bar_subprogram: DW_TAG_subprogram {
86		{DW_AT_name "bar"}
87		{DW_AT_prototyped 1 DW_FORM_flag_present}
88		{DW_AT_inline 0x1 DW_FORM_data1}
89	    }
90	}
91    }
92
93    lines { } stmt_list {
94	global srcdir subdir srcfile
95
96	include_dir "/some/directory"
97	file_name "/some/directory/file.c" 0
98    }
99
100    aranges {} cu_label {
101	arange {} __cu_low_pc __cu_high_pc
102    }
103}
104
105if { [build_executable ${testfile}.exp ${testfile} "$srcfile $dwarf_asm" \
106      {additional_flags=-nostdlib additional_flags=-static}] != 0 } {
107    untested "failed to compile"
108    return
109}
110
111clean_restart $binfile
112
113if { [gdb_starti_cmd] != 0 } {
114    fail "failed to run to first instruction"
115    return
116}
117gdb_test "" "Program stopped.*" "starti prompt"
118
119gdb_test "frame" "in _start .*"
120
121gdb_test "stepi" "in foo .*" "step into foo"
122gdb_test "stepi" "in bar .*" "step into bar"
123gdb_test "stepi" "in foo .*" "step back into foo"
124gdb_test "stepi" "in _start .*" "step back into _start"
125