Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2018-2020 Free Software Foundation, Inc. |
35ee2dc2 AB |
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 | # This tests some non-standard DWARF that we still expect GDB to be | |
17 | # able to handle. | |
18 | # | |
19 | # The DWARF standard (v5 5.1) says this: | |
20 | # | |
21 | # A base type is represented by a debugging information entry with | |
22 | # the tag DW_TAG_base_type. | |
23 | # | |
24 | # A base type entry may have a DW_AT_name attribute whose value is | |
25 | # a null-terminated string containing the name of the base type as | |
26 | # recognized by the programming language of the compilation unit | |
27 | # containing the base type entry. | |
28 | # | |
29 | # So the DW_AT_name field for a DW_TAG_base_type is optional. This | |
30 | # test provides some basic checking that GDB doesn't crash when | |
31 | # presented with this situation. | |
32 | ||
33 | load_lib dwarf.exp | |
34 | ||
35 | # This test can only be run on targets which support DWARF-2 and use gas. | |
36 | if {![dwarf2_support]} { | |
37 | return 0 | |
38 | } | |
39 | ||
40 | standard_testfile void-type.c void-type.S | |
41 | ||
42 | # Make some DWARF for the test. | |
43 | set asm_file [standard_output_file $srcfile2] | |
44 | Dwarf::assemble $asm_file { | |
45 | global srcdir subdir srcfile | |
46 | ||
47 | set func_result [function_range func ${srcdir}/${subdir}/${srcfile}] | |
48 | set func_start [lindex $func_result 0] | |
49 | set func_length [lindex $func_result 1] | |
50 | ||
51 | set main_result [function_range main ${srcdir}/${subdir}/${srcfile}] | |
52 | set main_start [lindex $main_result 0] | |
53 | set main_length [lindex $main_result 1] | |
54 | ||
55 | cu {} { | |
56 | DW_TAG_compile_unit { | |
57 | {DW_AT_producer "GNU C 8.1"} | |
58 | {DW_AT_language @DW_LANG_C} | |
59 | {DW_AT_name void-type.c} | |
60 | {DW_AT_comp_dir /tmp} | |
61 | } { | |
62 | declare_labels main_type int_type ptr_type | |
63 | ||
64 | main_type: DW_TAG_base_type { | |
65 | {DW_AT_byte_size 4 DW_FORM_sdata} | |
66 | {DW_AT_encoding @DW_ATE_signed} | |
67 | } | |
68 | ||
69 | int_type: DW_TAG_base_type { | |
70 | {DW_AT_byte_size 0 DW_FORM_sdata} | |
71 | {DW_AT_encoding @DW_ATE_signed} | |
72 | } | |
73 | ||
74 | ptr_type: DW_TAG_pointer_type { | |
75 | {DW_AT_type :$int_type} | |
76 | } | |
77 | ||
78 | DW_TAG_subprogram { | |
79 | {name func} | |
80 | {low_pc $func_start addr} | |
81 | {high_pc "$func_start + $func_length" addr} | |
82 | {type :$int_type} | |
83 | } | |
84 | DW_TAG_subprogram { | |
85 | {name main} | |
86 | {low_pc $main_start addr} | |
87 | {high_pc "$main_start + $main_length" addr} | |
88 | {type :$main_type} | |
89 | } | |
90 | ||
91 | DW_TAG_variable { | |
92 | {DW_AT_name "var_a"} | |
93 | {DW_AT_type :$main_type} | |
94 | {DW_AT_external 1 DW_FORM_flag} | |
95 | {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_a"]} SPECIAL_expr} | |
96 | } | |
97 | ||
98 | DW_TAG_variable { | |
99 | {DW_AT_name "var_ptr"} | |
100 | {DW_AT_type :$ptr_type} | |
101 | {DW_AT_external 1 DW_FORM_flag} | |
102 | {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_ptr"]} SPECIAL_expr} | |
103 | } | |
104 | } | |
105 | } | |
106 | } | |
107 | ||
108 | if { [prepare_for_testing "failed to prepare" ${testfile} \ | |
109 | [list $srcfile $asm_file] {nodebug}] } { | |
110 | return -1 | |
111 | } | |
112 | ||
113 | if ![runto_main] { | |
114 | return -1 | |
115 | } | |
116 | ||
117 | # Use 'ptype' on two variables that are using DW_TAG_base_type types | |
118 | # with missing DW_AT_name attributes. | |
119 | gdb_test "ptype var_ptr" "type = <invalid type code $decimal> \\*" \ | |
120 | "ptype of a pointer to a basic type with missing name" | |
121 | ||
122 | gdb_test "ptype var_a" "type = <invalid type code $decimal>" \ | |
123 | "ptype of a variable that is a basic type with a missing name" |