1# Copyright 2019-2020 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# This test shows the importance of not corrupting the order of line
17# table information.  When multiple lines are given for the same
18# address the compiler usually lists these in the order in which we
19# would expect to encounter them.  When stepping through nested inline
20# frames the last line given for an address is assumed by GDB to be
21# the most inner frame, and this is what GDB displays.
22#
23# If we corrupt the order of the line table entries then GDB will
24# display the wrong line as being the inner most frame.
25
26load_lib dwarf.exp
27
28# This test can only be run on targets which support DWARF-2 and use gas.
29if {![dwarf2_support]} {
30    return 0
31}
32
33# The .c files use __attribute__.
34if [get_compiler_info] {
35    return -1
36}
37if !$gcc_compiled {
38    return 0
39}
40
41standard_testfile dw2-inline-stepping.c dw2-inline-stepping.S
42
43set asm_file [standard_output_file $srcfile2]
44Dwarf::assemble $asm_file {
45    global srcdir subdir srcfile srcfile2
46    declare_labels ranges_label lines_label foo_prog
47
48    lassign [function_range main [list ${srcdir}/${subdir}/$srcfile]] \
49	main_start main_len
50    set main_end "$main_start + $main_len"
51    lassign [function_range bar [list ${srcdir}/${subdir}/$srcfile]] \
52	bar_start bar_len
53    set bar_end "$bar_start + $bar_len"
54
55    set call_line [gdb_get_line_number "main call foo"]
56
57    cu {} {
58	compile_unit {
59	    {language @DW_LANG_C}
60	    {name dw2-inline-stepping.c}
61	    {low_pc 0 addr}
62	    {stmt_list ${lines_label} DW_FORM_sec_offset}
63	    {ranges ${ranges_label} DW_FORM_sec_offset}
64	} {
65	    subprogram {
66		{external 1 flag}
67		{name bar}
68		{low_pc $bar_start addr}
69		{high_pc "$bar_start + $bar_len" addr}
70	    }
71	    foo_prog: subprogram {
72		{name foo}
73		{inline 3 data1}
74	    }
75	    subprogram {
76		{external 1 flag}
77		{name main}
78		{low_pc $main_start addr}
79		{high_pc "$main_start + $main_len" addr}
80	    } {
81		inlined_subroutine {
82		    {abstract_origin %$foo_prog}
83		    {low_pc main_label2 addr}
84		    {high_pc main_label3 addr}
85		    {call_file 1 data1}
86		    {call_line $call_line data1}
87		}
88	    }
89	}
90    }
91
92    lines {version 2} lines_label {
93	include_dir "${srcdir}/${subdir}"
94	file_name "$srcfile" 1
95
96	program {
97	    {DW_LNE_set_address $main_start}
98	    {line [gdb_get_line_number "main prologue"]}
99	    {DW_LNS_copy}
100	    {DW_LNE_set_address main_label}
101	    {line [gdb_get_line_number "main set global_var"]}
102	    {DW_LNS_copy}
103	    {DW_LNE_set_address main_label2}
104	    {line [gdb_get_line_number "main call foo"]}
105	    {DW_LNS_copy}
106	    {DW_LNE_set_address main_label2}
107	    {line [gdb_get_line_number "foo call bar"]}
108	    {DW_LNS_copy}
109	    {DW_LNE_set_address $main_end}
110	    {DW_LNE_end_sequence}
111
112	    {DW_LNE_set_address $bar_start}
113	    {line [gdb_get_line_number "bar prologue"]}
114	    {DW_LNS_copy}
115	    {DW_LNE_set_address bar_label}
116	    {line [gdb_get_line_number "bar return global_var"]}
117	    {DW_LNS_copy}
118	    {DW_LNE_set_address $bar_end}
119	    {DW_LNE_end_sequence}
120	}
121    }
122
123    ranges {is_64 [is_64_target]} {
124	ranges_label: sequence {
125	    {range {${main_start}} ${main_end}}
126	    {range {${bar_start}} ${bar_end}}
127	}
128    }
129}
130
131if { [prepare_for_testing "failed to prepare" ${testfile} \
132	  [list $srcfile $asm_file] {nodebug}] } {
133    return -1
134}
135
136if ![runto_main] {
137    return -1
138}
139
140set patterns [list "main call foo" \
141		  "foo call bar" \
142		  "bar return global_var"]
143foreach p $patterns {
144    gdb_test "step" "/\\* $p \\*/" \
145	"step to '$p'"
146}
147