]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/dw2-inline-with-lexical-scope.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dw2-inline-with-lexical-scope.exp
1 # Copyright 2021-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 # Test that scoped local variables in an inlined function are printed
17 # properly.
18
19 load_lib dwarf.exp
20
21 # This test can only be run on targets that support DWARF-2 and use
22 # gas.
23 require dwarf2_support
24
25 standard_testfile .c .S
26
27 # Make some DWARF for the test. The concrete inlined instance
28 # (i.e. the DW_TAG_inlined_subroutine) has a DW_TAG_lexical_block that
29 # does not contain a DW_AT_abstract_origin attribute. This is
30 # deliberate. Bad GDB printed duplicate local variables with
31 # "optimized out" values in this case.
32
33 set asm_file [standard_output_file $srcfile2]
34 Dwarf::assemble $asm_file {
35 global srcfile srcdir subdir
36 declare_labels int_label func_label num_label value_label lines_label
37
38 get_func_info main
39 set func_call [gdb_get_line_number "func call"]
40
41 set global_num_addr [gdb_target_symbol global_num]
42 set global_value_addr [gdb_target_symbol global_value]
43
44 cu {} {
45 compile_unit {
46 {language @DW_LANG_C99}
47 {name $srcfile}
48 {low_pc $main_start addr}
49 {high_pc "$main_start + $main_len" addr}
50 {stmt_list ${lines_label} DW_FORM_sec_offset}
51 } {
52 int_label: base_type {
53 {name "int"}
54 {byte_size 4 sdata}
55 {encoding @DW_ATE_signed}
56 }
57
58 func_label: subprogram {
59 {name func}
60 {inline @DW_INL_declared_inlined}
61 } {
62 num_label: DW_TAG_variable {
63 {name num}
64 {type :$int_label}
65 }
66 lexical_block {
67 } {
68 value_label: DW_TAG_variable {
69 {name value}
70 {type :$int_label}
71 }
72 }
73 }
74
75 subprogram {
76 {name main}
77 {external 1 flag}
78 {low_pc $main_start addr}
79 {high_pc "$main_start + $main_len" addr}
80 } {
81 inlined_subroutine {
82 {abstract_origin %$func_label}
83 {low_pc main_label addr}
84 {high_pc main_label2 addr}
85 {call_file 1 data1}
86 {call_line $func_call data1}
87 } {
88 DW_TAG_variable {
89 {abstract_origin %$num_label}
90 {location {addr $global_num_addr} SPECIAL_expr}
91 }
92 lexical_block {
93 {low_pc scope_label1 addr}
94 {high_pc scope_label2 addr}
95 } {
96 DW_TAG_variable {
97 {abstract_origin %$value_label}
98 {location {addr $global_value_addr} SPECIAL_expr}
99 }
100 }
101 }
102 }
103 }
104 }
105
106 lines {version 2} lines_label {
107 include_dir "${srcdir}/${subdir}"
108 file_name "$srcfile" 1
109
110 program {
111 DW_LNE_set_address $main_start
112 line [gdb_get_line_number "main prologue"]
113 DW_LNS_copy
114 DW_LNE_set_address main_label
115 line [gdb_get_line_number "func call"]
116 DW_LNS_copy
117 DW_LNE_set_address main_label
118 line [gdb_get_line_number "func end"]
119 DW_LNS_copy
120 DW_LNE_set_address main_label2
121 line [gdb_get_line_number "main end"]
122 DW_LNS_copy
123 DW_LNE_set_address $main_end
124 DW_LNE_end_sequence
125 }
126 }
127 }
128
129 if {[prepare_for_testing "failed to prepare" ${testfile} \
130 [list $srcfile $asm_file] {nodebug}]} {
131 return -1
132 }
133
134 runto breakpoint_label
135
136 # Bad GDB was printing an additional "value = <optimized out>".
137 gdb_test "info locals" "value = 42\r\nnum = 42"