17d62b00eSchristos /* DWARF DIEs 27d62b00eSchristos 3*6881a400Schristos Copyright (C) 2003-2023 Free Software Foundation, Inc. 47d62b00eSchristos 57d62b00eSchristos This file is part of GDB. 67d62b00eSchristos 77d62b00eSchristos This program is free software; you can redistribute it and/or modify 87d62b00eSchristos it under the terms of the GNU General Public License as published by 97d62b00eSchristos the Free Software Foundation; either version 3 of the License, or 107d62b00eSchristos (at your option) any later version. 117d62b00eSchristos 127d62b00eSchristos This program is distributed in the hope that it will be useful, 137d62b00eSchristos but WITHOUT ANY WARRANTY; without even the implied warranty of 147d62b00eSchristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 157d62b00eSchristos GNU General Public License for more details. 167d62b00eSchristos 177d62b00eSchristos You should have received a copy of the GNU General Public License 187d62b00eSchristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 197d62b00eSchristos 207d62b00eSchristos #ifndef GDB_DWARF2_DIE_H 217d62b00eSchristos #define GDB_DWARF2_DIE_H 227d62b00eSchristos 23*6881a400Schristos #include "complaints.h" 24*6881a400Schristos 257d62b00eSchristos /* This data structure holds a complete die structure. */ 267d62b00eSchristos struct die_info 277d62b00eSchristos { 287d62b00eSchristos /* Return the named attribute or NULL if not there, but do not 297d62b00eSchristos follow DW_AT_specification, etc. */ 307d62b00eSchristos struct attribute *attr (dwarf_attribute name) 317d62b00eSchristos { 327d62b00eSchristos for (unsigned i = 0; i < num_attrs; ++i) 337d62b00eSchristos if (attrs[i].name == name) 347d62b00eSchristos return &attrs[i]; 357d62b00eSchristos return NULL; 367d62b00eSchristos } 377d62b00eSchristos 387d62b00eSchristos /* Return the address base of the compile unit, which, if exists, is 397d62b00eSchristos stored either at the attribute DW_AT_GNU_addr_base, or 407d62b00eSchristos DW_AT_addr_base. */ 417d62b00eSchristos gdb::optional<ULONGEST> addr_base () 427d62b00eSchristos { 437d62b00eSchristos for (unsigned i = 0; i < num_attrs; ++i) 447d62b00eSchristos if (attrs[i].name == DW_AT_addr_base 457d62b00eSchristos || attrs[i].name == DW_AT_GNU_addr_base) 467d62b00eSchristos { 47*6881a400Schristos if (attrs[i].form_is_unsigned ()) 48*6881a400Schristos { 497d62b00eSchristos /* If both exist, just use the first one. */ 50*6881a400Schristos return attrs[i].as_unsigned (); 51*6881a400Schristos } 52*6881a400Schristos complaint (_("address base attribute (offset %s) as wrong form"), 53*6881a400Schristos sect_offset_str (sect_off)); 547d62b00eSchristos } 557d62b00eSchristos return gdb::optional<ULONGEST> (); 567d62b00eSchristos } 577d62b00eSchristos 58*6881a400Schristos /* Return the base address of the compile unit into the .debug_ranges section, 59*6881a400Schristos which, if exists, is stored in the DW_AT_GNU_ranges_base attribute. This 60*6881a400Schristos value is only relevant in pre-DWARF 5 split-unit scenarios. */ 61*6881a400Schristos ULONGEST gnu_ranges_base () 627d62b00eSchristos { 637d62b00eSchristos for (unsigned i = 0; i < num_attrs; ++i) 64*6881a400Schristos if (attrs[i].name == DW_AT_GNU_ranges_base) 657d62b00eSchristos { 66*6881a400Schristos if (attrs[i].form_is_unsigned ()) 67*6881a400Schristos return attrs[i].as_unsigned (); 68*6881a400Schristos 69*6881a400Schristos complaint (_("ranges base attribute (offset %s) has wrong form"), 70*6881a400Schristos sect_offset_str (sect_off)); 717d62b00eSchristos } 72*6881a400Schristos 737d62b00eSchristos return 0; 747d62b00eSchristos } 757d62b00eSchristos 76*6881a400Schristos /* Return the rnglists base of the compile unit, which, if exists, is stored 77*6881a400Schristos in the DW_AT_rnglists_base attribute. */ 78*6881a400Schristos ULONGEST rnglists_base () 79*6881a400Schristos { 80*6881a400Schristos for (unsigned i = 0; i < num_attrs; ++i) 81*6881a400Schristos if (attrs[i].name == DW_AT_rnglists_base) 82*6881a400Schristos { 83*6881a400Schristos if (attrs[i].form_is_unsigned ()) 84*6881a400Schristos return attrs[i].as_unsigned (); 85*6881a400Schristos 86*6881a400Schristos complaint (_("rnglists base attribute (offset %s) has wrong form"), 87*6881a400Schristos sect_offset_str (sect_off)); 88*6881a400Schristos } 89*6881a400Schristos 90*6881a400Schristos return 0; 91*6881a400Schristos } 927d62b00eSchristos 937d62b00eSchristos /* DWARF-2 tag for this DIE. */ 947d62b00eSchristos ENUM_BITFIELD(dwarf_tag) tag : 16; 957d62b00eSchristos 967d62b00eSchristos /* Number of attributes */ 977d62b00eSchristos unsigned char num_attrs; 987d62b00eSchristos 997d62b00eSchristos /* True if we're presently building the full type name for the 1007d62b00eSchristos type derived from this DIE. */ 1017d62b00eSchristos unsigned char building_fullname : 1; 1027d62b00eSchristos 1037d62b00eSchristos /* True if this die is in process. PR 16581. */ 1047d62b00eSchristos unsigned char in_process : 1; 1057d62b00eSchristos 1067d62b00eSchristos /* True if this DIE has children. */ 1077d62b00eSchristos unsigned char has_children : 1; 1087d62b00eSchristos 1097d62b00eSchristos /* Abbrev number */ 1107d62b00eSchristos unsigned int abbrev; 1117d62b00eSchristos 1127d62b00eSchristos /* Offset in .debug_info or .debug_types section. */ 1137d62b00eSchristos sect_offset sect_off; 1147d62b00eSchristos 1157d62b00eSchristos /* The dies in a compilation unit form an n-ary tree. PARENT 1167d62b00eSchristos points to this die's parent; CHILD points to the first child of 1177d62b00eSchristos this node; and all the children of a given node are chained 1187d62b00eSchristos together via their SIBLING fields. */ 1197d62b00eSchristos struct die_info *child; /* Its first child, if any. */ 1207d62b00eSchristos struct die_info *sibling; /* Its next sibling, if any. */ 1217d62b00eSchristos struct die_info *parent; /* Its parent, if any. */ 1227d62b00eSchristos 1237d62b00eSchristos /* An array of attributes, with NUM_ATTRS elements. There may be 1247d62b00eSchristos zero, but it's not common and zero-sized arrays are not 1257d62b00eSchristos sufficiently portable C. */ 1267d62b00eSchristos struct attribute attrs[1]; 1277d62b00eSchristos }; 1287d62b00eSchristos 1297d62b00eSchristos #endif /* GDB_DWARF2_DIE_H */ 130