]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/dwarf2/die.c
3 Copyright (C) 1994-2024 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
21 #include "dwarf2/die.h"
22 #include "dwarf2/stringify.h"
27 die_info::allocate (struct obstack
*obstack
, int num_attrs
)
29 size_t size
= sizeof (struct die_info
);
32 size
+= (num_attrs
- 1) * sizeof (struct attribute
);
34 struct die_info
*die
= (struct die_info
*) obstack_alloc (obstack
, size
);
35 memset (die
, 0, size
);
42 die_info::hash (const void *item
)
44 const struct die_info
*die
= (const struct die_info
*) item
;
46 return to_underlying (die
->sect_off
);
52 die_info::eq (const void *item_lhs
, const void *item_rhs
)
54 const struct die_info
*die_lhs
= (const struct die_info
*) item_lhs
;
55 const struct die_info
*die_rhs
= (const struct die_info
*) item_rhs
;
57 return die_lhs
->sect_off
== die_rhs
->sect_off
;
61 dump_die_shallow (struct ui_file
*f
, int indent
, struct die_info
*die
)
65 gdb_printf (f
, "%*sDie: %s (abbrev %d, offset %s)\n",
67 dwarf_tag_name (die
->tag
), die
->abbrev
,
68 sect_offset_str (die
->sect_off
));
70 if (die
->parent
!= NULL
)
71 gdb_printf (f
, "%*s parent at offset: %s\n",
73 sect_offset_str (die
->parent
->sect_off
));
75 gdb_printf (f
, "%*s has children: %s\n",
77 dwarf_bool_name (die
->child
!= NULL
));
79 gdb_printf (f
, "%*s attributes:\n", indent
, "");
81 for (i
= 0; i
< die
->num_attrs
; ++i
)
83 gdb_printf (f
, "%*s %s (%s) ",
85 dwarf_attr_name (die
->attrs
[i
].name
),
86 dwarf_form_name (die
->attrs
[i
].form
));
88 switch (die
->attrs
[i
].form
)
92 case DW_FORM_GNU_addr_index
:
93 gdb_printf (f
, "address: ");
94 gdb_puts (hex_string ((CORE_ADDR
) die
->attrs
[i
].as_address ()), f
);
100 gdb_printf (f
, "block: size %s",
101 pulongest (die
->attrs
[i
].as_block ()->size
));
103 case DW_FORM_exprloc
:
104 gdb_printf (f
, "expression: size %s",
105 pulongest (die
->attrs
[i
].as_block ()->size
));
108 gdb_printf (f
, "constant of 16 bytes");
110 case DW_FORM_ref_addr
:
111 gdb_printf (f
, "ref address: ");
112 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
114 case DW_FORM_GNU_ref_alt
:
115 gdb_printf (f
, "alt ref address: ");
116 gdb_puts (hex_string (die
->attrs
[i
].as_unsigned ()), f
);
122 case DW_FORM_ref_udata
:
123 gdb_printf (f
, "constant ref: 0x%lx (adjusted)",
124 (long) (die
->attrs
[i
].as_unsigned ()));
131 gdb_printf (f
, "constant: %s",
132 pulongest (die
->attrs
[i
].as_unsigned ()));
134 case DW_FORM_sec_offset
:
135 gdb_printf (f
, "section offset: %s",
136 pulongest (die
->attrs
[i
].as_unsigned ()));
138 case DW_FORM_ref_sig8
:
139 gdb_printf (f
, "signature: %s",
140 hex_string (die
->attrs
[i
].as_signature ()));
144 case DW_FORM_line_strp
:
146 case DW_FORM_GNU_str_index
:
147 case DW_FORM_GNU_strp_alt
:
148 gdb_printf (f
, "string: \"%s\" (%s canonicalized)",
149 die
->attrs
[i
].as_string ()
150 ? die
->attrs
[i
].as_string () : "",
151 die
->attrs
[i
].canonical_string_p () ? "is" : "not");
154 if (die
->attrs
[i
].as_boolean ())
155 gdb_printf (f
, "flag: TRUE");
157 gdb_printf (f
, "flag: FALSE");
159 case DW_FORM_flag_present
:
160 gdb_printf (f
, "flag: TRUE");
162 case DW_FORM_indirect
:
163 /* The reader will have reduced the indirect form to
164 the "base form" so this form should not occur. */
166 "unexpected attribute form: DW_FORM_indirect");
169 case DW_FORM_implicit_const
:
170 gdb_printf (f
, "constant: %s",
171 plongest (die
->attrs
[i
].as_signed ()));
174 gdb_printf (f
, "unsupported attribute form: %d.",
178 gdb_printf (f
, "\n");
183 dump_die_1 (struct ui_file
*f
, int level
, int max_level
, struct die_info
*die
)
185 int indent
= level
* 4;
187 gdb_assert (die
!= NULL
);
189 if (level
>= max_level
)
192 dump_die_shallow (f
, indent
, die
);
194 if (die
->child
!= NULL
)
196 gdb_printf (f
, "%*s Children:", indent
, "");
197 if (level
+ 1 < max_level
)
199 gdb_printf (f
, "\n");
200 dump_die_1 (f
, level
+ 1, max_level
, die
->child
);
205 " [not printed, max nesting level reached]\n");
209 if (die
->sibling
!= NULL
&& level
> 0)
211 dump_die_1 (f
, level
, max_level
, die
->sibling
);
218 die_info::dump (int max_level
)
220 dump_die_1 (gdb_stdlog
, 0, max_level
, this);
226 die_info::error_dump ()
228 dump_die_shallow (gdb_stderr
, 0, this);