Commit | Line | Data |
---|---|---|
bd360d30 AB |
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 | ||
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 cpp-linkage-name.c cpp-linkage-name-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 srcdir subdir srcfile | |
34 | ||
35 | lassign [function_range main ${srcdir}/${subdir}/${srcfile}] \ | |
36 | main_start main_length | |
37 | ||
38 | cu {} { | |
39 | DW_TAG_compile_unit { | |
40 | {DW_AT_language @DW_LANG_C_plus_plus} | |
41 | {DW_AT_name ada-linkage-name.c} | |
42 | {DW_AT_comp_dir /tmp} | |
43 | ||
44 | } { | |
45 | declare_labels a_l b_l | |
46 | ||
47 | a_l: DW_TAG_base_type { | |
48 | {DW_AT_byte_size 4 DW_FORM_sdata} | |
49 | {DW_AT_encoding @DW_ATE_signed} | |
50 | {DW_AT_name int} | |
51 | } | |
52 | ||
53 | # To expose the bug that existed at one point this | |
54 | # structure must have a linkage name, but no name, and the | |
55 | # linkage name is something that doesn't demangle. | |
56 | b_l: DW_TAG_structure_type { | |
57 | {DW_AT_byte_size 8 DW_FORM_sdata} | |
58 | {DW_AT_encoding @DW_ATE_signed} | |
59 | {DW_AT_linkage_name <anon>} | |
60 | } { | |
61 | member { | |
62 | {name x} | |
63 | {type :$a_l} | |
64 | {data_member_location 0 data1} | |
65 | } | |
66 | member { | |
67 | {name y} | |
68 | {type :$a_l} | |
69 | {data_member_location 0 data1} | |
70 | } | |
71 | } | |
72 | DW_TAG_subprogram { | |
73 | {name "main"} | |
74 | {low_pc $main_start addr} | |
75 | {high_pc "$main_start + $main_length" addr} | |
76 | {type :$a_l} | |
77 | } | |
78 | DW_TAG_variable { | |
79 | {type :$b_l} | |
80 | {external 1 flag} | |
81 | {DW_AT_name global_var} | |
82 | {DW_AT_location { | |
83 | DW_OP_addr [gdb_target_symbol global_var] | |
84 | } SPECIAL_expr} | |
85 | } | |
86 | } | |
87 | } | |
88 | } | |
89 | ||
90 | if { [prepare_for_testing "failed to prepare" ${testfile} \ | |
91 | [list $srcfile $asm_file] {nodebug}] } { | |
92 | return -1 | |
93 | } | |
94 | ||
95 | gdb_assert [runto_main] "run to main" | |
96 | gdb_test "p global_var" " = {x = 0, y = 0}" |