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