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