]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/missing-type-name.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / missing-type-name.exp
1 # Copyright 2018-2022 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 # 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 srcfile
46
47 cu {} {
48 DW_TAG_compile_unit {
49 {DW_AT_producer "GNU C 8.1"}
50 {DW_AT_language @DW_LANG_C}
51 {DW_AT_name $srcfile}
52 {DW_AT_comp_dir /tmp}
53 } {
54 declare_labels main_type int_type ptr_type
55
56 main_type: DW_TAG_base_type {
57 {DW_AT_byte_size 4 DW_FORM_sdata}
58 {DW_AT_encoding @DW_ATE_signed}
59 }
60
61 int_type: DW_TAG_base_type {
62 {DW_AT_byte_size 0 DW_FORM_sdata}
63 {DW_AT_encoding @DW_ATE_signed}
64 }
65
66 ptr_type: DW_TAG_pointer_type {
67 {DW_AT_type :$int_type}
68 }
69
70 DW_TAG_subprogram {
71 {MACRO_AT_func func}
72 {type :$int_type}
73 }
74 DW_TAG_subprogram {
75 {MACRO_AT_func main}
76 {type :$main_type}
77 }
78
79 DW_TAG_variable {
80 {DW_AT_name "var_a"}
81 {DW_AT_type :$main_type}
82 {DW_AT_external 1 DW_FORM_flag}
83 {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_a"]} SPECIAL_expr}
84 }
85
86 DW_TAG_variable {
87 {DW_AT_name "var_ptr"}
88 {DW_AT_type :$ptr_type}
89 {DW_AT_external 1 DW_FORM_flag}
90 {DW_AT_location {DW_OP_addr [gdb_target_symbol "var_ptr"]} SPECIAL_expr}
91 }
92 }
93 }
94 }
95
96 if { [prepare_for_testing "failed to prepare" ${testfile} \
97 [list $srcfile $asm_file] {nodebug}] } {
98 return -1
99 }
100
101 if ![runto_main] {
102 return -1
103 }
104
105 # Use 'ptype' on two variables that are using DW_TAG_base_type types
106 # with missing DW_AT_name attributes.
107 gdb_test "ptype var_ptr" "type = <invalid type code $decimal> \\*" \
108 "ptype of a pointer to a basic type with missing name"
109
110 gdb_test "ptype var_a" "type = <invalid type code $decimal>" \
111 "ptype of a variable that is a basic type with a missing name"