GDB (xrefs)
Loading...
Searching...
No Matches
die.h
Go to the documentation of this file.
1/* DWARF DIEs
2
3 Copyright (C) 2003-2023 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
26/* This data structure holds a complete die structure. */
28{
29 /* Allocate a new die_info on OBSTACK. NUM_ATTRS is the number of
30 attributes that are needed. */
31 static die_info *allocate (struct obstack *obstack, int num_attrs);
32
33 /* Trivial hash function for die_info: the hash value of a DIE is
34 its offset in .debug_info for this objfile. */
35 static hashval_t hash (const void *item);
36
37 /* Trivial comparison function for die_info structures: two DIEs
38 are equal if they have the same offset. */
39 static int eq (const void *item_lhs, const void *item_rhs);
40
41 /* Dump this DIE and any children to MAX_LEVEL. They are written to
42 gdb_stdlog. Note this is called from the pdie user command in
43 gdb-gdb.gdb. */
44 void dump (int max_level);
45
46 /* Shallowly dump this DIE to gdb_stderr. */
47 void error_dump ();
48
49 /* Return the named attribute or NULL if not there, but do not
50 follow DW_AT_specification, etc. */
51 struct attribute *attr (dwarf_attribute name)
52 {
53 for (unsigned i = 0; i < num_attrs; ++i)
54 if (attrs[i].name == name)
55 return &attrs[i];
56 return NULL;
57 }
58
59 /* Return the address base of the compile unit, which, if exists, is
60 stored either at the attribute DW_AT_GNU_addr_base, or
61 DW_AT_addr_base. */
62 gdb::optional<ULONGEST> addr_base ()
63 {
64 for (unsigned i = 0; i < num_attrs; ++i)
65 if (attrs[i].name == DW_AT_addr_base
66 || attrs[i].name == DW_AT_GNU_addr_base)
67 {
68 if (attrs[i].form_is_unsigned ())
69 {
70 /* If both exist, just use the first one. */
71 return attrs[i].as_unsigned ();
72 }
73 complaint (_("address base attribute (offset %s) as wrong form"),
75 }
76 return gdb::optional<ULONGEST> ();
77 }
78
79 /* Return the base address of the compile unit into the .debug_ranges section,
80 which, if exists, is stored in the DW_AT_GNU_ranges_base attribute. This
81 value is only relevant in pre-DWARF 5 split-unit scenarios. */
82 ULONGEST gnu_ranges_base ()
83 {
84 for (unsigned i = 0; i < num_attrs; ++i)
85 if (attrs[i].name == DW_AT_GNU_ranges_base)
86 {
87 if (attrs[i].form_is_unsigned ())
88 return attrs[i].as_unsigned ();
89
90 complaint (_("ranges base attribute (offset %s) has wrong form"),
92 }
93
94 return 0;
95 }
96
97 /* Return the rnglists base of the compile unit, which, if exists, is stored
98 in the DW_AT_rnglists_base attribute. */
99 ULONGEST rnglists_base ()
100 {
101 for (unsigned i = 0; i < num_attrs; ++i)
102 if (attrs[i].name == DW_AT_rnglists_base)
103 {
104 if (attrs[i].form_is_unsigned ())
105 return attrs[i].as_unsigned ();
106
107 complaint (_("rnglists base attribute (offset %s) has wrong form"),
109 }
110
111 return 0;
112 }
113
114 /* DWARF-2 tag for this DIE. */
115 ENUM_BITFIELD(dwarf_tag) tag : 16;
116
117 /* Number of attributes */
118 unsigned char num_attrs;
119
120 /* True if we're presently building the full type name for the
121 type derived from this DIE. */
122 unsigned char building_fullname : 1;
123
124 /* True if this die is in process. PR 16581. */
125 unsigned char in_process : 1;
126
127 /* True if this DIE has children. */
128 unsigned char has_children : 1;
129
130 /* Abbrev number */
131 unsigned int abbrev;
132
133 /* Offset in .debug_info or .debug_types section. */
134 sect_offset sect_off;
135
136 /* The dies in a compilation unit form an n-ary tree. PARENT
137 points to this die's parent; CHILD points to the first child of
138 this node; and all the children of a given node are chained
139 together via their SIBLING fields. */
140 struct die_info *child; /* Its first child, if any. */
141 struct die_info *sibling; /* Its next sibling, if any. */
142 struct die_info *parent; /* Its parent, if any. */
143
144 /* An array of attributes, with NUM_ATTRS elements. There may be
145 zero, but it's not common and zero-sized arrays are not
146 sufficiently portable C. */
147 struct attribute attrs[1];
148};
149
150#endif /* GDB_DWARF2_DIE_H */
const char *const name
#define complaint(FMT,...)
Definition complaints.h:47
ULONGEST as_unsigned() const
Definition attribute.h:88
Definition die.h:28
struct die_info * child
Definition die.h:140
static die_info * allocate(struct obstack *obstack, int num_attrs)
Definition die.c:27
unsigned char building_fullname
Definition die.h:122
void dump(int max_level)
Definition die.c:218
unsigned char in_process
Definition die.h:125
struct attribute attrs[1]
Definition die.h:147
struct attribute * attr(dwarf_attribute name)
Definition die.h:51
ULONGEST gnu_ranges_base()
Definition die.h:82
unsigned int abbrev
Definition die.h:131
void error_dump()
Definition die.c:226
static int eq(const void *item_lhs, const void *item_rhs)
Definition die.c:52
unsigned char has_children
Definition die.h:128
sect_offset sect_off
Definition die.h:134
struct die_info * parent
Definition die.h:142
__extension__ enum dwarf_tag tag
Definition die.h:115
ULONGEST rnglists_base()
Definition die.h:99
struct die_info * sibling
Definition die.h:141
static hashval_t hash(const void *item)
Definition die.c:42
gdb::optional< ULONGEST > addr_base()
Definition die.h:62
unsigned char num_attrs
Definition die.h:118
static char * sect_offset_str(sect_offset offset)
Definition types.h:35