die.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* DWARF DIEs
  2. Copyright (C) 2003-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef GDB_DWARF2_DIE_H
  15. #define GDB_DWARF2_DIE_H
  16. #include "complaints.h"
  17. /* This data structure holds a complete die structure. */
  18. struct die_info
  19. {
  20. /* Return the named attribute or NULL if not there, but do not
  21. follow DW_AT_specification, etc. */
  22. struct attribute *attr (dwarf_attribute name)
  23. {
  24. for (unsigned i = 0; i < num_attrs; ++i)
  25. if (attrs[i].name == name)
  26. return &attrs[i];
  27. return NULL;
  28. }
  29. /* Return the address base of the compile unit, which, if exists, is
  30. stored either at the attribute DW_AT_GNU_addr_base, or
  31. DW_AT_addr_base. */
  32. gdb::optional<ULONGEST> addr_base ()
  33. {
  34. for (unsigned i = 0; i < num_attrs; ++i)
  35. if (attrs[i].name == DW_AT_addr_base
  36. || attrs[i].name == DW_AT_GNU_addr_base)
  37. {
  38. if (attrs[i].form_is_unsigned ())
  39. {
  40. /* If both exist, just use the first one. */
  41. return attrs[i].as_unsigned ();
  42. }
  43. complaint (_("address base attribute (offset %s) as wrong form"),
  44. sect_offset_str (sect_off));
  45. }
  46. return gdb::optional<ULONGEST> ();
  47. }
  48. /* Return the base address of the compile unit into the .debug_ranges section,
  49. which, if exists, is stored in the DW_AT_GNU_ranges_base attribute. This
  50. value is only relevant in pre-DWARF 5 split-unit scenarios. */
  51. ULONGEST gnu_ranges_base ()
  52. {
  53. for (unsigned i = 0; i < num_attrs; ++i)
  54. if (attrs[i].name == DW_AT_GNU_ranges_base)
  55. {
  56. if (attrs[i].form_is_unsigned ())
  57. return attrs[i].as_unsigned ();
  58. complaint (_("ranges base attribute (offset %s) has wrong form"),
  59. sect_offset_str (sect_off));
  60. }
  61. return 0;
  62. }
  63. /* Return the rnglists base of the compile unit, which, if exists, is stored
  64. in the DW_AT_rnglists_base attribute. */
  65. ULONGEST rnglists_base ()
  66. {
  67. for (unsigned i = 0; i < num_attrs; ++i)
  68. if (attrs[i].name == DW_AT_rnglists_base)
  69. {
  70. if (attrs[i].form_is_unsigned ())
  71. return attrs[i].as_unsigned ();
  72. complaint (_("rnglists base attribute (offset %s) has wrong form"),
  73. sect_offset_str (sect_off));
  74. }
  75. return 0;
  76. }
  77. /* DWARF-2 tag for this DIE. */
  78. ENUM_BITFIELD(dwarf_tag) tag : 16;
  79. /* Number of attributes */
  80. unsigned char num_attrs;
  81. /* True if we're presently building the full type name for the
  82. type derived from this DIE. */
  83. unsigned char building_fullname : 1;
  84. /* True if this die is in process. PR 16581. */
  85. unsigned char in_process : 1;
  86. /* True if this DIE has children. */
  87. unsigned char has_children : 1;
  88. /* Abbrev number */
  89. unsigned int abbrev;
  90. /* Offset in .debug_info or .debug_types section. */
  91. sect_offset sect_off;
  92. /* The dies in a compilation unit form an n-ary tree. PARENT
  93. points to this die's parent; CHILD points to the first child of
  94. this node; and all the children of a given node are chained
  95. together via their SIBLING fields. */
  96. struct die_info *child; /* Its first child, if any. */
  97. struct die_info *sibling; /* Its next sibling, if any. */
  98. struct die_info *parent; /* Its parent, if any. */
  99. /* An array of attributes, with NUM_ATTRS elements. There may be
  100. zero, but it's not common and zero-sized arrays are not
  101. sufficiently portable C. */
  102. struct attribute attrs[1];
  103. };
  104. #endif /* GDB_DWARF2_DIE_H */