1 # Copyright 2020-2021 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 # Some compilers give anonymous structures a linkage name, and that
17 # linkage name doesn't demangle (within GDB calling gdb_demangle
18 # return NULL). At one point this caused GDB to crash due to
19 # dereferencing a NULL pointer.
23 # This test can only be run on targets which support DWARF-2 and use gas.
24 if {![dwarf2_support]} {
28 standard_testfile .c -debug.S
30 # Set up the DWARF for the test.
31 set asm_file [standard_output_file $srcfile2]
32 Dwarf::assemble $asm_file {
37 {DW_AT_language @DW_LANG_C_plus_plus}
42 declare_labels a_l b_l
44 a_l: DW_TAG_base_type {
45 {DW_AT_byte_size 4 DW_FORM_sdata}
46 {DW_AT_encoding @DW_ATE_signed}
50 # To expose the bug that existed at one point this
51 # structure must have a linkage name, but no name, and the
52 # linkage name is something that doesn't demangle.
53 b_l: DW_TAG_structure_type {
54 {DW_AT_byte_size 8 DW_FORM_sdata}
55 {DW_AT_encoding @DW_ATE_signed}
56 {DW_AT_linkage_name <anon>}
61 {data_member_location 0 data1}
66 {data_member_location 0 data1}
70 {MACRO_AT_func {main}}
76 {DW_AT_name global_var}
78 DW_OP_addr [gdb_target_symbol global_var]
85 if { [prepare_for_testing "failed to prepare" ${testfile} \
86 [list $srcfile $asm_file] {nodebug}] } {
90 gdb_assert [runto_main] "run to main"
91 gdb_test "p global_var" " = {x = 0, y = 0}"