]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/dw2-inline-header-1.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-inline-header-1.exp
1 # Copyright 2020-2024 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 require dwarf2_support
57
58 # The .c files use __attribute__.
59 require is_c_compiler_gcc
60
61 # Prepare and run the test.
62 proc do_test { start_label func_name tag } {
63 global srcfile srcfile2 srcfile3 srcfile4 testfile
64
65 standard_testfile dw2-inline-header-lbls.c dw2-inline-header-${tag}.S \
66 dw2-inline-header.c dw2-inline-header.h
67
68 set build_options {nodebug optimize=-O1}
69
70 set asm_file [standard_output_file $srcfile2]
71 Dwarf::assemble $asm_file {
72 global srcdir subdir srcfile srcfile3 srcfile4 testfile
73 upvar build_options build_options
74 upvar start_label start_label
75 declare_labels lines_label callee_subprog_label
76
77 get_func_info main $build_options
78
79 cu {} {
80 compile_unit {
81 {producer "gcc" }
82 {language @DW_LANG_C}
83 {name ${srcfile3}}
84 {low_pc 0 addr}
85 {stmt_list ${lines_label} DW_FORM_sec_offset}
86 } {
87 callee_subprog_label: subprogram {
88 {external 1 flag}
89 {name callee}
90 {inline 3 data1}
91 }
92 subprogram {
93 {external 1 flag}
94 {name main}
95 {low_pc $main_start addr}
96 {high_pc "$main_start + $main_len" addr}
97 } {
98 inlined_subroutine {
99 {abstract_origin %$callee_subprog_label}
100 {low_pc $start_label addr}
101 {high_pc line_label_6 addr}
102 {call_file 1 data1}
103 {call_line 18 data1}
104 }
105 }
106 }
107 }
108
109 lines {version 2 default_is_stmt 1} lines_label {
110 include_dir "${srcdir}/${subdir}"
111 file_name "$srcfile3" 1
112 file_name "$srcfile4" 1
113
114 program {
115 DW_LNE_set_address line_label_1
116 DW_LNS_advance_line 15
117 DW_LNS_copy
118
119 DW_LNE_set_address line_label_2
120 DW_LNS_advance_line 1
121 DW_LNS_copy
122
123 DW_LNS_set_file 2
124 DW_LNE_set_address line_label_3
125 DW_LNS_advance_line 4
126 DW_LNS_copy
127
128 DW_LNE_set_address line_label_4
129 DW_LNS_advance_line 1
130 DW_LNS_copy
131
132 DW_LNS_advance_line -4
133 DW_LNS_set_file 1
134 DW_LNS_negate_stmt
135 DW_LNS_copy
136
137 DW_LNS_set_file 2
138 DW_LNE_set_address line_label_5
139 DW_LNS_advance_line 5
140 DW_LNS_copy
141
142 DW_LNS_negate_stmt
143 DW_LNS_set_file 1
144 DW_LNE_set_address line_label_6
145 DW_LNS_advance_line 1
146 DW_LNS_copy
147
148 DW_LNE_set_address line_label_7
149 DW_LNE_end_sequence
150 }
151 }
152 }
153
154 if { [prepare_for_testing "failed to prepare" ${testfile}-${tag} \
155 [list $srcfile $asm_file] $build_options] } {
156 return -1
157 }
158
159 if ![runto_main] {
160 return -1
161 }
162
163 # Delete all breakpoints so that the output of "info breakpoints"
164 # below will only contain a single breakpoint.
165 delete_breakpoints
166
167 # Place a breakpoint within the function in the header file.
168 gdb_breakpoint "${srcfile4}:22"
169
170 # Check that the breakpoint was placed where we expected. It should
171 # appear at the requested line. When the bug in GDB was present the
172 # breakpoint would be placed on one of the following lines instead.
173 gdb_test "info breakpoints" \
174 ".* in $func_name at \[^\r\n\]+${srcfile4}:22\\y.*" \
175 "info breakpoints, $tag"
176 }
177
178 do_test line_label_3 "callee" "range-a"
179 do_test line_label_5 "main" "range-b"