gdb: Preserve is-stmt lines when switch between files
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-inline-header-1.exp
1 # Copyright 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 # Setup a line table where:
17 #
18 # | | | | | Inline | Inline |
19 # | Addr | File | Line | Stmt | Rng A | Rng B |
20 # |------|------|------|------|--------|--------|
21 # | 1 | 1 | 16 | Y | | |
22 # | 2 | 1 | 17 | Y | | |
23 # | 3 | 2 | 21 | Y | X | |
24 # | 4 | 2 | 22 | Y | X | |
25 # | 4 | 1 | 18 | N | X | |
26 # | 5 | 2 | 23 | N | X | X |
27 # | 6 | 1 | 24 | Y | | |
28 # | 7 | 1 | END | Y | | |
29 # |------|------|------|------|--------|--------|
30 #
31 # Places a brekpoint at file 2, line 22. Previously GDB would discard
32 # the line table entry for this line due to switching files for the
33 # file 1, line 18 non-statement line. After patching however, GDB now
34 # discards the file 1, line 18 entry instead, and the breakpoint at
35 # line 22 should succeed.
36 #
37 # The two inlined subroutine ranges 'A' and 'B' represent two possible
38 # ways that a compiler might represent this siuatio in the DWARF.
39 #
40 # Range 'B' is something that has been seen in the wild using GCC 8.2.
41 # In this case the compilers range information is clearly wrong, but
42 # this shouldn't impact the main point of the test.
43 #
44 # Range 'A' is a hypothetical case of how the compiler might choose to
45 # represent this range, this has never been seen in the wild, but is
46 # an improved debug experiece over range 'B'. However, if we ever run
47 # in to the situation where GDB can support the range 'A' test, or
48 # support some real DWARF seen in the wild, then the range 'A' case
49 # should be dropped in favour of supporting real world cases. This is
50 # included here as it "just worked" once the range 'B' case was
51 # working.
52
53 load_lib dwarf.exp
54
55 # This test can only be run on targets which support DWARF-2 and use gas.
56 if {![dwarf2_support]} {
57 return 0
58 }
59
60 # The .c files use __attribute__.
61 if [get_compiler_info] {
62 return -1
63 }
64 if !$gcc_compiled {
65 return 0
66 }
67
68 # Prepare and run the test.
69 proc do_test { start_label func_name tag } {
70 global srcfile srcfile2 srcfile3 srcfile4 testfile
71
72 standard_testfile dw2-inline-header-lbls.c dw2-inline-header-${tag}.S \
73 dw2-inline-header.c dw2-inline-header.h
74
75 set build_options {nodebug optimize=-O1}
76
77 set asm_file [standard_output_file $srcfile2]
78 Dwarf::assemble $asm_file {
79 global srcdir subdir srcfile srcfile3 srcfile4 testfile
80 upvar build_options build_options
81 upvar start_label start_label
82 declare_labels lines_label callee_subprog_label
83
84 get_func_info main $build_options
85
86 cu {} {
87 compile_unit {
88 {producer "gcc" }
89 {language @DW_LANG_C}
90 {name ${srcfile3}}
91 {low_pc 0 addr}
92 {stmt_list ${lines_label} DW_FORM_sec_offset}
93 } {
94 callee_subprog_label: subprogram {
95 {external 1 flag}
96 {name callee}
97 {inline 3 data1}
98 }
99 subprogram {
100 {external 1 flag}
101 {name main}
102 {low_pc $main_start addr}
103 {high_pc "$main_start + $main_len" addr}
104 } {
105 inlined_subroutine {
106 {abstract_origin %$callee_subprog_label}
107 {low_pc $start_label addr}
108 {high_pc line_label_6 addr}
109 {call_file 1 data1}
110 {call_line 18 data1}
111 }
112 }
113 }
114 }
115
116 lines {version 2 default_is_stmt 1} lines_label {
117 include_dir "${srcdir}/${subdir}"
118 file_name "$srcfile3" 1
119 file_name "$srcfile4" 1
120
121 program {
122 {DW_LNE_set_address line_label_1}
123 {DW_LNS_advance_line 15}
124 {DW_LNS_copy}
125
126 {DW_LNE_set_address line_label_2}
127 {DW_LNS_advance_line 1}
128 {DW_LNS_copy}
129
130 {DW_LNS_set_file 2}
131 {DW_LNE_set_address line_label_3}
132 {DW_LNS_advance_line 4}
133 {DW_LNS_copy}
134
135 {DW_LNE_set_address line_label_4}
136 {DW_LNS_advance_line 1}
137 {DW_LNS_copy}
138
139 {DW_LNS_advance_line -4}
140 {DW_LNS_set_file 1}
141 {DW_LNS_negate_stmt}
142 {DW_LNS_copy}
143
144 {DW_LNS_set_file 2}
145 {DW_LNE_set_address line_label_5}
146 {DW_LNS_advance_line 5}
147 {DW_LNS_copy}
148
149 {DW_LNS_negate_stmt}
150 {DW_LNS_set_file 1}
151 {DW_LNE_set_address line_label_6}
152 {DW_LNS_advance_line 1}
153 {DW_LNS_copy}
154
155 {DW_LNE_set_address line_label_7}
156 {DW_LNE_end_sequence}
157 }
158 }
159 }
160
161 if { [prepare_for_testing "failed to prepare" ${testfile}-${tag} \
162 [list $srcfile $asm_file] $build_options] } {
163 return -1
164 }
165
166 if ![runto_main] {
167 return -1
168 }
169
170 # Delete all breakpoints so that the output of "info breakpoints"
171 # below will only contain a single breakpoint.
172 delete_breakpoints
173
174 # Place a breakpoint within the function in the header file.
175 gdb_breakpoint "${srcfile4}:22"
176
177 # Check that the breakpoint was placed where we expected. It should
178 # appear at the requested line. When the bug in GDB was present the
179 # breakpoint would be placed on one of the following lines instead.
180 gdb_test "info breakpoints" \
181 ".* in $func_name at \[^\r\n\]+${srcfile4}:22\\y.*" \
182 "info breakpoints, $tag"
183 }
184
185 do_test line_label_3 "callee" "range-a"
186 do_test line_label_5 "main" "range-b"
This page took 0.034212 seconds and 4 git commands to generate.