1 # Copyright 2020-2023 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 # Setup a line table where:
18 # | Addr | File | Line | Stmt | Inline |
19 # |------|------|------|------|--------|
20 # | 1 | 1 | 16 | Y | |
21 # | 2 | 1 | 17 | Y | |
22 # | 3 | 2 | 21 | Y | X |
23 # | 4 | 2 | 22 | Y | X |
24 # | 4 | 1 | 18 | N | |
25 # | 5 | 1 | 19 | N | |
26 # | 6 | 1 | 20 | Y | |
27 # | 7 | 1 | END | Y | |
28 # |------|------|------|------|--------|
30 # Break at file 2, line 22, then single instruction step forward. We
31 # should pass through line 19 and then encounter line 20.
33 # Currently we don't expect GDB to see file 1, line 18, as this is a
34 # non-stmt line in a different file at the same address as the
35 # previous is-stmt line.
39 # This test can only be run on targets which support DWARF-2 and use gas.
40 if {![dwarf2_support]} {
44 # The .c files use __attribute__.
45 if ![is_c_compiler_gcc] {
49 standard_testfile dw2-inline-header-lbls.c dw2-inline-header.S \
50 dw2-inline-header.c dw2-inline-header.h
52 set build_options {nodebug optimize=-O1}
54 set asm_file [standard_output_file $srcfile2]
55 Dwarf::assemble $asm_file {
56 global srcdir subdir srcfile srcfile3 srcfile4
58 declare_labels lines_label callee_subprog_label
60 get_func_info main $build_options
68 {stmt_list ${lines_label} DW_FORM_sec_offset}
70 callee_subprog_label: subprogram {
78 {low_pc $main_start addr}
79 {high_pc "$main_start + $main_len" addr}
82 {abstract_origin %$callee_subprog_label}
83 {low_pc line_label_3 addr}
84 {high_pc line_label_5 addr}
92 lines {version 2 default_is_stmt 1} lines_label {
93 include_dir "${srcdir}/${subdir}"
94 file_name "$srcfile3" 1
95 file_name "$srcfile4" 1
98 DW_LNE_set_address line_label_1
99 DW_LNS_advance_line 15
102 DW_LNE_set_address line_label_2
103 DW_LNS_advance_line 1
107 DW_LNE_set_address line_label_3
108 DW_LNS_advance_line 4
111 DW_LNE_set_address line_label_4
112 DW_LNS_advance_line 1
115 DW_LNS_advance_line -4
120 DW_LNE_set_address line_label_5
121 DW_LNS_advance_line 1
124 DW_LNE_set_address line_label_6
125 DW_LNS_advance_line 1
129 DW_LNE_set_address line_label_7
135 if { [prepare_for_testing "failed to prepare" ${testfile} \
136 [list $srcfile $asm_file] $build_options] } {
144 # Delete all breakpoints so that the output of "info breakpoints"
145 # below will only contain a single breakpoint.
148 # Place a breakpoint within the function in the header file.
149 gdb_breakpoint "${srcfile4}:22"
151 # Check that the breakpoint was placed where we expected. It should
152 # appear at the requested line. When the bug in GDB was present the
153 # breakpoint would be placed on one of the following lines instead.
154 gdb_test "info breakpoints" \
155 ".* in callee at \[^\r\n\]+${srcfile4}:22\\y.*"
157 gdb_continue_to_breakpoint "${srcfile4}:22" \
158 ".* ${srcfile4} : 22 .*"
160 # Now single instruction step forward. Eventually we should hit
161 # ${srcfile3}:20, but before we do we should hit the non-statement
162 # line ${srcfile3}:19.
164 # We don't know how many instructions we'll need to step, but 100
165 # should be enough for everyone (surely), and this stops us looping
166 # forever if something goes wrong.
170 for { set i 0 } { $i < 100 && $keep_going } { incr i } {
172 gdb_test_multiple "stepi" "stepi ${i}" {
173 -re "${srcfile3} : 19 .*${gdb_prompt} " {
178 -re "${srcfile3} : 20 .*${gdb_prompt} " {
182 -re "${srcfile4} : 22 .*${gdb_prompt} " {
183 # Not left line 22 yet.
189 gdb_assert { $found_line_19 && $found_line_20 } \
190 "found line 19 and 20"