xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.dwarf2/cpp-linkage-name.exp (revision 6db267571823ee3b0a1d61478df085a087f2e990)
1# Copyright 2020 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
21load_lib dwarf.exp
22
23# This test can only be run on targets which support DWARF-2 and use gas.
24if {![dwarf2_support]} {
25    return 0
26}
27
28standard_testfile cpp-linkage-name.c cpp-linkage-name-debug.S
29
30# Set up the DWARF for the test.
31set asm_file [standard_output_file $srcfile2]
32Dwarf::assemble $asm_file {
33    cu {} {
34	DW_TAG_compile_unit {
35	    {DW_AT_language @DW_LANG_C_plus_plus}
36	    {DW_AT_name     ada-linkage-name.c}
37	    {DW_AT_comp_dir /tmp}
38
39	} {
40	    declare_labels a_l b_l
41
42	    a_l: DW_TAG_base_type {
43		{DW_AT_byte_size 4 DW_FORM_sdata}
44		{DW_AT_encoding  @DW_ATE_signed}
45		{DW_AT_name      int}
46	    }
47
48	    # To expose the bug that existed at one point this
49	    # structure must have a linkage name, but no name, and the
50	    # linkage name is something that doesn't demangle.
51	    b_l: DW_TAG_structure_type {
52		{DW_AT_byte_size 8 DW_FORM_sdata}
53		{DW_AT_encoding  @DW_ATE_signed}
54		{DW_AT_linkage_name <anon>}
55	    } {
56		member {
57		    {name x}
58		    {type :$a_l}
59		    {data_member_location 0 data1}
60		}
61		member {
62		    {name y}
63		    {type :$a_l}
64		    {data_member_location 0 data1}
65		}
66	    }
67	    DW_TAG_subprogram {
68		{MACRO_AT_func {main}}
69		{type :$a_l}
70	    }
71	    DW_TAG_variable {
72		{type :$b_l}
73		{external 1 flag}
74		{DW_AT_name global_var}
75		{DW_AT_location {
76		    DW_OP_addr [gdb_target_symbol global_var]
77		} SPECIAL_expr}
78	    }
79	}
80    }
81}
82
83if { [prepare_for_testing "failed to prepare" ${testfile} \
84	  [list $srcfile $asm_file] {nodebug}] } {
85    return -1
86}
87
88gdb_assert [runto_main] "run to main"
89gdb_test "p global_var" " = {x = 0, y = 0}"
90