1 # Copyright 2021-2024 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 # Test that scoped local variables in an inlined function are printed
21 # This test can only be run on targets that support DWARF-2 and use
23 require dwarf2_support
25 standard_testfile .c .S
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.
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
39 set func_call [gdb_get_line_number "func call"]
41 set global_num_addr [gdb_target_symbol global_num]
42 set global_value_addr [gdb_target_symbol global_value]
46 {language @DW_LANG_C99}
48 {low_pc $main_start addr}
49 {high_pc "$main_start + $main_len" addr}
50 {stmt_list ${lines_label} DW_FORM_sec_offset}
52 int_label: base_type {
55 {encoding @DW_ATE_signed}
58 func_label: subprogram {
60 {inline @DW_INL_declared_inlined}
62 num_label: DW_TAG_variable {
68 value_label: DW_TAG_variable {
78 {low_pc $main_start addr}
79 {high_pc "$main_start + $main_len" addr}
82 {abstract_origin %$func_label}
83 {low_pc main_label addr}
84 {high_pc main_label2 addr}
86 {call_line $func_call data1}
89 {abstract_origin %$num_label}
90 {location {addr $global_num_addr} SPECIAL_expr}
93 {low_pc scope_label1 addr}
94 {high_pc scope_label2 addr}
97 {abstract_origin %$value_label}
98 {location {addr $global_value_addr} SPECIAL_expr}
106 lines {version 2} lines_label {
107 include_dir "${srcdir}/${subdir}"
108 file_name "$srcfile" 1
111 DW_LNE_set_address $main_start
112 line [gdb_get_line_number "main prologue"]
114 DW_LNE_set_address main_label
115 line [gdb_get_line_number "func call"]
117 DW_LNE_set_address main_label
118 line [gdb_get_line_number "func end"]
120 DW_LNE_set_address main_label2
121 line [gdb_get_line_number "main end"]
123 DW_LNE_set_address $main_end
129 if {[prepare_for_testing "failed to prepare" ${testfile} \
130 [list $srcfile $asm_file] {nodebug}]} {
134 runto breakpoint_label
136 # Bad GDB was printing an additional "value = <optimized out>".
137 gdb_test "info locals" "value = 42\r\nnum = 42"