1 # Copyright 2018-2020 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 # This tests some non-standard DWARF that we still expect GDB to be
19 # The DWARF standard (v5 5.1) says this:
21 # A base type is represented by a debugging information entry with
22 # the tag DW_TAG_base_type.
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.
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.
35 # This test can only be run on targets which support DWARF-2 and use gas.
36 if {![dwarf2_support]} {
40 standard_testfile void-type.c void-type.S
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
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]
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]
57 {DW_AT_producer "GNU C 8.1"}
58 {DW_AT_language @DW_LANG_C}
59 {DW_AT_name void-type.c}
62 declare_labels main_type int_type ptr_type
64 main_type: DW_TAG_base_type {
65 {DW_AT_byte_size 4 DW_FORM_sdata}
66 {DW_AT_encoding @DW_ATE_signed}
69 int_type: DW_TAG_base_type {
70 {DW_AT_byte_size 0 DW_FORM_sdata}
71 {DW_AT_encoding @DW_ATE_signed}
74 ptr_type: DW_TAG_pointer_type {
75 {DW_AT_type :$int_type}
80 {low_pc $func_start addr}
81 {high_pc "$func_start + $func_length" addr}
86 {low_pc $main_start addr}
87 {high_pc "$main_start + $main_length" addr}
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}
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}
108 if { [prepare_for_testing "failed to prepare" ${testfile} \
109 [list $srcfile $asm_file] {nodebug}] } {
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"
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"