die.h revision 1.1.1.3 1 /* DWARF DIEs
2
3 Copyright (C) 2003-2024 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #ifndef GDB_DWARF2_DIE_H
21 #define GDB_DWARF2_DIE_H
22
23 #include "complaints.h"
24 #include "dwarf2/attribute.h"
25 #include "hashtab.h"
26
27 /* This data structure holds a complete die structure. */
28 struct die_info
29 {
30 /* Allocate a new die_info on OBSTACK. NUM_ATTRS is the number of
31 attributes that are needed. */
32 static die_info *allocate (struct obstack *obstack, int num_attrs);
33
34 /* Trivial hash function for die_info: the hash value of a DIE is
35 its offset in .debug_info for this objfile. */
36 static hashval_t hash (const void *item);
37
38 /* Trivial comparison function for die_info structures: two DIEs
39 are equal if they have the same offset. */
40 static int eq (const void *item_lhs, const void *item_rhs);
41
42 /* Dump this DIE and any children to MAX_LEVEL. They are written to
43 gdb_stdlog. Note this is called from the pdie user command in
44 gdb-gdb.gdb. */
45 void dump (int max_level);
46
47 /* Shallowly dump this DIE to gdb_stderr. */
48 void error_dump ();
49
50 /* Return the named attribute or NULL if not there, but do not
51 follow DW_AT_specification, etc. */
52 struct attribute *attr (dwarf_attribute name)
53 {
54 for (unsigned i = 0; i < num_attrs; ++i)
55 if (attrs[i].name == name)
56 return &attrs[i];
57 return NULL;
58 }
59
60 /* Return the address base of the compile unit, which, if exists, is
61 stored either at the attribute DW_AT_GNU_addr_base, or
62 DW_AT_addr_base. */
63 std::optional<ULONGEST> addr_base ()
64 {
65 for (unsigned i = 0; i < num_attrs; ++i)
66 if (attrs[i].name == DW_AT_addr_base
67 || attrs[i].name == DW_AT_GNU_addr_base)
68 {
69 if (attrs[i].form_is_unsigned ())
70 {
71 /* If both exist, just use the first one. */
72 return attrs[i].as_unsigned ();
73 }
74 complaint (_("address base attribute (offset %s) as wrong form"),
75 sect_offset_str (sect_off));
76 }
77 return std::optional<ULONGEST> ();
78 }
79
80 /* Return the base address of the compile unit into the .debug_ranges section,
81 which, if exists, is stored in the DW_AT_GNU_ranges_base attribute. This
82 value is only relevant in pre-DWARF 5 split-unit scenarios. */
83 ULONGEST gnu_ranges_base ()
84 {
85 for (unsigned i = 0; i < num_attrs; ++i)
86 if (attrs[i].name == DW_AT_GNU_ranges_base)
87 {
88 if (attrs[i].form_is_unsigned ())
89 return attrs[i].as_unsigned ();
90
91 complaint (_("ranges base attribute (offset %s) has wrong form"),
92 sect_offset_str (sect_off));
93 }
94
95 return 0;
96 }
97
98 /* Return the rnglists base of the compile unit, which, if exists, is stored
99 in the DW_AT_rnglists_base attribute. */
100 ULONGEST rnglists_base ()
101 {
102 for (unsigned i = 0; i < num_attrs; ++i)
103 if (attrs[i].name == DW_AT_rnglists_base)
104 {
105 if (attrs[i].form_is_unsigned ())
106 return attrs[i].as_unsigned ();
107
108 complaint (_("rnglists base attribute (offset %s) has wrong form"),
109 sect_offset_str (sect_off));
110 }
111
112 return 0;
113 }
114
115 /* DWARF-2 tag for this DIE. */
116 ENUM_BITFIELD(dwarf_tag) tag : 16;
117
118 /* Number of attributes */
119 unsigned char num_attrs;
120
121 /* True if we're presently building the full type name for the
122 type derived from this DIE. */
123 unsigned char building_fullname : 1;
124
125 /* True if this die is in process. PR 16581. */
126 unsigned char in_process : 1;
127
128 /* True if this DIE has children. */
129 unsigned char has_children : 1;
130
131 /* Abbrev number */
132 unsigned int abbrev;
133
134 /* Offset in .debug_info or .debug_types section. */
135 sect_offset sect_off;
136
137 /* The dies in a compilation unit form an n-ary tree. PARENT
138 points to this die's parent; CHILD points to the first child of
139 this node; and all the children of a given node are chained
140 together via their SIBLING fields. */
141 struct die_info *child; /* Its first child, if any. */
142 struct die_info *sibling; /* Its next sibling, if any. */
143 struct die_info *parent; /* Its parent, if any. */
144
145 /* An array of attributes, with NUM_ATTRS elements. There may be
146 zero, but it's not common and zero-sized arrays are not
147 sufficiently portable C. */
148 struct attribute attrs[1];
149 };
150
151 #endif /* GDB_DWARF2_DIE_H */
152