gdb: Add support for tracking the DWARF line table is-stmt field
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-is-stmt-2.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 # 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
26 load_lib dwarf.exp
27
28 # This test can only be run on targets which support DWARF-2 and use gas.
29 if {![dwarf2_support]} {
30 return 0
31 }
32
33 # The .c files use __attribute__.
34 if [get_compiler_info] {
35 return -1
36 }
37 if !$gcc_compiled {
38 return 0
39 }
40
41 standard_testfile dw2-is-stmt-2.c dw2-is-stmt-2.S
42
43 # Extract the start, length, and end for function called NAME and
44 # create suitable variables in the callers scope.
45 proc get_func_info { name } {
46 global srcdir subdir srcfile
47
48 upvar 1 "${name}_start" func_start
49 upvar 1 "${name}_len" func_len
50 upvar 1 "${name}_end" func_end
51
52 lassign [function_range ${name} [list ${srcdir}/${subdir}/$srcfile]] \
53 func_start func_len
54 set func_end "$func_start + $func_len"
55 }
56
57 set asm_file [standard_output_file $srcfile2]
58 Dwarf::assemble $asm_file {
59 global srcdir subdir srcfile
60 declare_labels lines_label
61
62 get_func_info main
63
64 cu {} {
65 compile_unit {
66 {language @DW_LANG_C}
67 {name dw2-is-stmt.c}
68 {low_pc 0 addr}
69 {stmt_list ${lines_label} DW_FORM_sec_offset}
70 } {
71 subprogram {
72 {external 1 flag}
73 {name main}
74 {low_pc $main_start addr}
75 {high_pc "$main_start + $main_len" addr}
76 } {}
77 }
78 }
79
80 lines {version 2 default_is_stmt 1} lines_label {
81 include_dir "${srcdir}/${subdir}"
82 file_name "$srcfile" 1
83
84 program {
85 {DW_LNE_set_address main}
86 {DW_LNS_advance_line \
87 [expr [gdb_get_line_number "main prologue"] - 1]}
88 {DW_LNS_copy}
89
90 {DW_LNE_set_address line_label_0}
91 {DW_LNS_advance_line \
92 [expr [gdb_get_line_number "main start"] \
93 - [gdb_get_line_number "main prologue"]]}
94 {DW_LNS_copy}
95
96 {DW_LNE_set_address line_label_1}
97 {DW_LNS_advance_line \
98 [expr [gdb_get_line_number "Line 1"] \
99 - [gdb_get_line_number "main start"]]}
100 {DW_LNS_negate_stmt}
101 {DW_LNS_copy}
102
103 {DW_LNE_set_address line_label_2}
104 {DW_LNS_negate_stmt}
105 {DW_LNS_copy}
106
107 {DW_LNE_set_address line_label_3}
108 {DW_LNS_advance_line \
109 [expr [gdb_get_line_number "Line 2"] \
110 - [gdb_get_line_number "Line 1"]]}
111 {DW_LNS_negate_stmt}
112 {DW_LNS_copy}
113
114 {DW_LNE_set_address line_label_4}
115 {DW_LNS_advance_line \
116 [expr [gdb_get_line_number "Line 1"] \
117 - [gdb_get_line_number "Line 2"]]}
118 {DW_LNS_copy}
119
120 {DW_LNE_set_address line_label_5}
121 {DW_LNS_advance_line \
122 [expr [gdb_get_line_number "Line 3"] \
123 - [gdb_get_line_number "Line 1"]]}
124 {DW_LNS_copy}
125
126 {DW_LNE_set_address line_label_6}
127 {DW_LNS_advance_line \
128 [expr [gdb_get_line_number "Line 4"] \
129 - [gdb_get_line_number "Line 3"]]}
130 {DW_LNS_copy}
131
132 {DW_LNE_set_address line_label_7}
133 {DW_LNS_negate_stmt}
134 {DW_LNS_copy}
135
136 {DW_LNE_set_address line_label_8}
137 {DW_LNS_advance_line \
138 [expr [gdb_get_line_number "Line 2"] \
139 - [gdb_get_line_number "Line 4"]]}
140 {DW_LNS_copy}
141
142 {DW_LNE_set_address line_label_9}
143 {DW_LNS_negate_stmt}
144 {DW_LNS_copy}
145
146 {DW_LNE_set_address line_label_10}
147 {DW_LNS_advance_line \
148 [expr [gdb_get_line_number "Line 3"] \
149 - [gdb_get_line_number "Line 2"]]}
150 {DW_LNS_copy}
151
152 {DW_LNE_set_address line_label_11}
153 {DW_LNS_advance_line \
154 [expr [gdb_get_line_number "Line 5"] \
155 - [gdb_get_line_number "Line 3"]]}
156 {DW_LNS_copy}
157
158 {DW_LNE_set_address line_label_12}
159 {DW_LNS_negate_stmt}
160 {DW_LNS_copy}
161
162 {DW_LNE_set_address line_label_13}
163 {DW_LNS_advance_line \
164 [expr [gdb_get_line_number "Line 3"] \
165 - [gdb_get_line_number "Line 5"]]}
166 {DW_LNS_copy}
167
168 {DW_LNE_set_address line_label_14}
169 {DW_LNS_advance_line \
170 [expr [gdb_get_line_number "Line 4"] \
171 - [gdb_get_line_number "Line 3"]]}
172 {DW_LNS_negate_stmt}
173 {DW_LNS_copy}
174
175 {DW_LNE_set_address line_label_15}
176 {DW_LNS_advance_line \
177 [expr [gdb_get_line_number "Line 5"] \
178 - [gdb_get_line_number "Line 4"]]}
179 {DW_LNS_copy}
180
181 {DW_LNE_set_address line_label_16}
182 {DW_LNS_advance_line \
183 [expr [gdb_get_line_number "main end"] \
184 - [gdb_get_line_number "Line 5"]]}
185 {DW_LNS_negate_stmt}
186 {DW_LNS_copy}
187
188 {DW_LNE_set_address ${main_end}}
189 {DW_LNE_end_sequence}
190 }
191 }
192 }
193
194 if { [prepare_for_testing "failed to prepare" ${testfile} \
195 [list $srcfile $asm_file] {nodebug}] } {
196 return -1
197 }
198
199 if ![runto_main] {
200 return -1
201 }
202
203 # Check stepping through the out of order lines gives the experience
204 # we expect; lines in the correct order, and stop at the correct
205 # labels.Q
206 set locs { { "Line 1." "line_label_2" } \
207 { "Line 4." "line_label_7" } \
208 { "Line 2." "line_label_8" } \
209 { "Line 5." "line_label_12" } \
210 { "Line 3." "line_label_13" } }
211 foreach entry $locs {
212 set pattern [lindex $entry 0]
213 set label [lindex $entry 1]
214
215 set linum [gdb_get_line_number "$pattern"]
216 gdb_test "step" "\r\n$linum\[ \t\]+/\\* $pattern \\*/" \
217 "step to $pattern"
218
219 set pc [get_hexadecimal_valueof "\$pc" "NO-PC" \
220 "read \$pc at $pattern"]
221 set val [get_hexadecimal_valueof "&${label}" "INVALID"]
222 gdb_assert { $pc == $val } \
223 "check pc at $pattern"
224 }
225
226 # Now restart the test, and this time, single instruction step
227 # through. This is checking that the is-stmt marked lines are
228 # displayed differently (without addresses) to addresses that are
229 # mid-way through a line, or not marked as is-stmt.
230 clean_restart $binfile
231 runto_main
232
233 foreach entry $locs {
234 set pattern [lindex $entry 0]
235 set label [lindex $entry 1]
236
237 with_test_prefix "stepi to $label" {
238 # If can take many instruction steps to get to the next label.
239 set i 0
240 set pc [get_hexadecimal_valueof "\$pc" "NO-PC" ]
241 set val [get_hexadecimal_valueof "&${label}" "INVALID"]
242 while { $pc < $val } {
243 incr i
244 set line_changed -1
245 gdb_test_multiple "stepi" "stepi $i" {
246 -re "\r\n$hex\[ \t\]+$decimal\[^\r\n\]+\r\n$gdb_prompt" {
247 set line_changed 0
248 }
249 -re "\r\n$decimal\[ \t\]+/\\* $pattern \\*/\r\n$gdb_prompt" {
250 set line_changed 1
251 }
252 }
253 gdb_assert { $line_changed != -1 } \
254 "ensure we saw a valid pattern, $i"
255 set pc [get_hexadecimal_valueof "\$pc" "NO-PC" \
256 "get pc inside stepi loop, $i"]
257 if { $pc == $val } {
258 gdb_assert { $line_changed } \
259 "line must change at $label"
260 } else {
261 gdb_assert { !$line_changed } "same line $i"
262 }
263 }
264 }
265 }
This page took 0.035945 seconds and 4 git commands to generate.