Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / missing-type-name.exp
CommitLineData
88b9d363 1# Copyright 2018-2022 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
33load_lib dwarf.exp
34
35# This test can only be run on targets which support DWARF-2 and use gas.
36if {![dwarf2_support]} {
37 return 0
38}
39
40standard_testfile void-type.c void-type.S
41
42# Make some DWARF for the test.
43set asm_file [standard_output_file $srcfile2]
44Dwarf::assemble $asm_file {
9476b583
TV
45 global srcfile
46
35ee2dc2
AB
47 cu {} {
48 DW_TAG_compile_unit {
49 {DW_AT_producer "GNU C 8.1"}
50 {DW_AT_language @DW_LANG_C}
9476b583 51 {DW_AT_name $srcfile}
35ee2dc2
AB
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 {
90c3ec2d 71 {MACRO_AT_func func}
35ee2dc2
AB
72 {type :$int_type}
73 }
74 DW_TAG_subprogram {
90c3ec2d 75 {MACRO_AT_func main}
35ee2dc2
AB
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
96if { [prepare_for_testing "failed to prepare" ${testfile} \
97 [list $srcfile $asm_file] {nodebug}] } {
98 return -1
99}
100
101if ![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.
107gdb_test "ptype var_ptr" "type = <invalid type code $decimal> \\*" \
108 "ptype of a pointer to a basic type with missing name"
109
110gdb_test "ptype var_a" "type = <invalid type code $decimal>" \
111 "ptype of a variable that is a basic type with a missing name"
This page took 0.396349 seconds and 4 git commands to generate.