1 # Copyright 2020 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 # 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.
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.
28 # This test can only be run on targets which support DWARF-2 and use gas.
29 if {![dwarf2_support]} {
33 # The .c files use __attribute__.
34 if [get_compiler_info] {
41 standard_testfile dw2-is-stmt-2.c dw2-is-stmt-2.S
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
48 upvar 1 "${name}_start" func_start
49 upvar 1 "${name}_len" func_len
50 upvar 1 "${name}_end" func_end
52 lassign [function_range ${name} [list ${srcdir}/${subdir}/$srcfile]] \
54 set func_end "$func_start + $func_len"
57 set asm_file [standard_output_file $srcfile2]
58 Dwarf::assemble $asm_file {
59 global srcdir subdir srcfile
60 declare_labels lines_label
69 {stmt_list ${lines_label} DW_FORM_sec_offset}
74 {low_pc $main_start addr}
75 {high_pc "$main_start + $main_len" addr}
80 lines {version 2 default_is_stmt 1} lines_label {
81 include_dir "${srcdir}/${subdir}"
82 file_name "$srcfile" 1
85 {DW_LNE_set_address main}
86 {DW_LNS_advance_line \
87 [expr [gdb_get_line_number "main prologue"] - 1]}
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"]]}
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"]]}
103 {DW_LNE_set_address line_label_2}
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"]]}
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"]]}
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"]]}
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"]]}
132 {DW_LNE_set_address line_label_7}
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"]]}
142 {DW_LNE_set_address line_label_9}
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"]]}
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"]]}
158 {DW_LNE_set_address line_label_12}
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"]]}
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"]]}
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"]]}
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"]]}
188 {DW_LNE_set_address ${main_end}}
189 {DW_LNE_end_sequence}
194 if { [prepare_for_testing "failed to prepare" ${testfile} \
195 [list $srcfile $asm_file] {nodebug}] } {
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
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]
215 set linum [gdb_get_line_number "$pattern"]
216 gdb_test "step" "\r\n$linum\[ \t\]+/\\* $pattern \\*/" \
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"
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
233 foreach entry $locs {
234 set pattern [lindex $entry 0]
235 set label [lindex $entry 1]
237 with_test_prefix "stepi to $label" {
238 # If can take many instruction steps to get to the next label.
240 set pc [get_hexadecimal_valueof "\$pc" "NO-PC" ]
241 set val [get_hexadecimal_valueof "&${label}" "INVALID"]
242 while { $pc < $val } {
245 gdb_test_multiple "stepi" "stepi $i" {
246 -re "\r\n$hex\[ \t\]+$decimal\[^\r\n\]+\r\n$gdb_prompt" {
249 -re "\r\n$decimal\[ \t\]+/\\* $pattern \\*/\r\n$gdb_prompt" {
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"]
258 gdb_assert { $line_changed } \
259 "line must change at $label"
261 gdb_assert { !$line_changed } "same line $i"