]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/cpp-linkage-name.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / cpp-linkage-name.exp
1 # Copyright 2020-2023 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 # 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.
20
21 load_lib dwarf.exp
22
23 # This test can only be run on targets which support DWARF-2 and use gas.
24 if {![dwarf2_support]} {
25 return 0
26 }
27
28 standard_testfile .c -debug.S
29
30 # Set up the DWARF for the test.
31 set asm_file [standard_output_file $srcfile2]
32 Dwarf::assemble $asm_file {
33 global srcfile
34
35 cu {} {
36 DW_TAG_compile_unit {
37 {DW_AT_language @DW_LANG_C_plus_plus}
38 {DW_AT_name $srcfile}
39 {DW_AT_comp_dir /tmp}
40
41 } {
42 declare_labels a_l b_l
43
44 a_l: DW_TAG_base_type {
45 {DW_AT_byte_size 4 DW_FORM_sdata}
46 {DW_AT_encoding @DW_ATE_signed}
47 {DW_AT_name int}
48 }
49
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>}
57 } {
58 member {
59 {name x}
60 {type :$a_l}
61 {data_member_location 0 data1}
62 }
63 member {
64 {name y}
65 {type :$a_l}
66 {data_member_location 0 data1}
67 }
68 }
69 DW_TAG_subprogram {
70 {MACRO_AT_func {main}}
71 {type :$a_l}
72 }
73 DW_TAG_variable {
74 {type :$b_l}
75 {external 1 flag}
76 {DW_AT_name global_var}
77 {DW_AT_location {
78 DW_OP_addr [gdb_target_symbol global_var]
79 } SPECIAL_expr}
80 }
81 }
82 }
83 }
84
85 if { [prepare_for_testing "failed to prepare" ${testfile} \
86 [list $srcfile $asm_file] {nodebug}] } {
87 return -1
88 }
89
90 gdb_assert [runto_main] "run to main"
91 gdb_test "p global_var" " = {x = 0, y = 0}"