Change two more functions to be methods on die_info
[deliverable/binutils-gdb.git] / gdb / dwarf2 / read.c
index dbd5b6a48022c4db062e0961ddb924fb7b8c4368..64e92ff92fea6dca0f998209826a6ca42db8fbf9 100644 (file)
@@ -39,6 +39,7 @@
 #include "dwarf2/line-header.h"
 #include "dwarf2/dwz.h"
 #include "dwarf2/macro.h"
+#include "dwarf2/die.h"
 #include "bfd.h"
 #include "elf-bfd.h"
 #include "symtab.h"
@@ -392,10 +393,7 @@ struct dwarf2_cu
   struct comp_unit_head header {};
 
   /* Base address of this compilation unit.  */
-  CORE_ADDR base_address = 0;
-
-  /* Non-zero if base_address has been set.  */
-  int base_known = 0;
+  gdb::optional<CORE_ADDR> base_address;
 
   /* The language we are debugging.  */
   enum language language = language_unknown;
@@ -1045,45 +1043,6 @@ struct partial_die_info : public allocate_on_obstack
     }
   };
 
-/* This data structure holds a complete die structure.  */
-struct die_info
-  {
-    /* DWARF-2 tag for this DIE.  */
-    ENUM_BITFIELD(dwarf_tag) tag : 16;
-
-    /* Number of attributes */
-    unsigned char num_attrs;
-
-    /* True if we're presently building the full type name for the
-       type derived from this DIE.  */
-    unsigned char building_fullname : 1;
-
-    /* True if this die is in process.  PR 16581.  */
-    unsigned char in_process : 1;
-
-    /* True if this DIE has children.  */
-    unsigned char has_children : 1;
-
-    /* Abbrev number */
-    unsigned int abbrev;
-
-    /* Offset in .debug_info or .debug_types section.  */
-    sect_offset sect_off;
-
-    /* The dies in a compilation unit form an n-ary tree.  PARENT
-       points to this die's parent; CHILD points to the first child of
-       this node; and all the children of a given node are chained
-       together via their SIBLING fields.  */
-    struct die_info *child;    /* Its first child, if any.  */
-    struct die_info *sibling;  /* Its next sibling, if any.  */
-    struct die_info *parent;   /* Its parent, if any.  */
-
-    /* An array of attributes, with NUM_ATTRS elements.  There may be
-       zero, but it's not common and zero-sized arrays are not
-       sufficiently portable C.  */
-    struct attribute attrs[1];
-  };
-
 /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte,
    but this would require a corresponding change in unpack_field_as_long
    and friends.  */
@@ -1239,10 +1198,6 @@ static void read_attribute_reprocess (const struct die_reader_specs *reader,
 
 static CORE_ADDR read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index);
 
-static LONGEST read_checked_initial_length_and_offset
-  (bfd *, const gdb_byte *, const struct comp_unit_head *,
-   unsigned int *, unsigned int *);
-
 static sect_offset read_abbrev_offset
   (struct dwarf2_per_objfile *dwarf2_per_objfile,
    struct dwarf2_section_info *, sect_offset);
@@ -1269,9 +1224,6 @@ static void set_cu_language (unsigned int, struct dwarf2_cu *);
 static struct attribute *dwarf2_attr (struct die_info *, unsigned int,
                                      struct dwarf2_cu *);
 
-static struct attribute *dwarf2_attr_no_follow (struct die_info *,
-                                               unsigned int);
-
 static const char *dwarf2_string_attr (struct die_info *die, unsigned int name,
                                        struct dwarf2_cu *cu);
 
@@ -1464,8 +1416,6 @@ static const char *dwarf_bool_name (unsigned int);
 
 static const char *dwarf_type_encoding_name (unsigned int);
 
-static struct die_info *sibling_die (struct die_info *);
-
 static void dump_die_shallow (struct ui_file *, int indent, struct die_info *);
 
 static void dump_die_for_error (struct die_info *);
@@ -1673,12 +1623,6 @@ static void free_line_header_voidp (void *arg);
 \f
 /* Various complaints about symbol reading that don't abort the process.  */
 
-static void
-dwarf2_statement_list_fits_in_line_number_section_complaint (void)
-{
-  complaint (_("statement list doesn't fit in .debug_line section"));
-}
-
 static void
 dwarf2_debug_line_missing_file_complaint (void)
 {
@@ -5831,23 +5775,16 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct attribute *attr;
 
-  cu->base_known = 0;
-  cu->base_address = 0;
+  cu->base_address.reset ();
 
   attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
   if (attr != nullptr)
-    {
-      cu->base_address = attr->value_as_address ();
-      cu->base_known = 1;
-    }
+    cu->base_address = attr->value_as_address ();
   else
     {
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
       if (attr != nullptr)
-       {
-         cu->base_address = attr->value_as_address ();
-         cu->base_known = 1;
-       }
+       cu->base_address = attr->value_as_address ();
     }
 }
 
@@ -6449,34 +6386,6 @@ lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
     }
 }
 
-/* Return the address base of the compile unit, which, if exists, is stored
-   either at the attribute DW_AT_GNU_addr_base, or DW_AT_addr_base.  */
-static gdb::optional<ULONGEST>
-lookup_addr_base (struct die_info *comp_unit_die)
-{
-  struct attribute *attr;
-  attr = dwarf2_attr_no_follow (comp_unit_die, DW_AT_addr_base);
-  if (attr == nullptr)
-    attr = dwarf2_attr_no_follow (comp_unit_die, DW_AT_GNU_addr_base);
-  if (attr == nullptr)
-    return gdb::optional<ULONGEST> ();
-  return DW_UNSND (attr);
-}
-
-/* Return range lists base of the compile unit, which, if exists, is stored
-   either at the attribute DW_AT_rnglists_base or DW_AT_GNU_ranges_base.  */
-static ULONGEST
-lookup_ranges_base (struct die_info *comp_unit_die)
-{
-  struct attribute *attr;
-  attr = dwarf2_attr_no_follow (comp_unit_die, DW_AT_rnglists_base);
-  if (attr == nullptr)
-    attr = dwarf2_attr_no_follow (comp_unit_die, DW_AT_GNU_ranges_base);
-  if (attr == nullptr)
-    return 0;
-  return DW_UNSND (attr);
-}
-
 /* Low level DIE reading support.  */
 
 /* Initialize a die_reader_specs struct from a dwarf2_cu struct.  */
@@ -6565,12 +6474,12 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
       ranges = dwarf2_attr (stub_comp_unit_die, DW_AT_ranges, cu);
       comp_dir = dwarf2_attr (stub_comp_unit_die, DW_AT_comp_dir, cu);
 
-      cu->addr_base = lookup_addr_base (stub_comp_unit_die);
+      cu->addr_base = stub_comp_unit_die->addr_base ();
 
       /* There should be a DW_AT_rnglists_base (DW_AT_GNU_ranges_base) attribute
         here (if needed). We need the value before we can process
         DW_AT_ranges.  */
-      cu->ranges_base = lookup_ranges_base (stub_comp_unit_die);
+      cu->ranges_base = stub_comp_unit_die->ranges_base ();
     }
   else if (stub_comp_dir != NULL)
     {
@@ -7457,7 +7366,7 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
   if (! type_unit_die->has_children)
     return;
 
-  attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
+  attr = type_unit_die->attr (DW_AT_stmt_list);
   tu_group = get_type_unit_group (cu, attr);
 
   if (tu_group->tus == nullptr)
@@ -10522,7 +10431,7 @@ read_import_statement (struct die_info *die, struct dwarf2_cu *cu)
 
   if (die->tag == DW_TAG_imported_module && cu->language == language_fortran)
     for (child_die = die->child; child_die && child_die->tag;
-        child_die = sibling_die (child_die))
+        child_die = child_die->sibling)
       {
        /* DWARF-4: A Fortran use statement with a “rename list” may be
           represented by an imported module entry with an import attribute
@@ -10800,7 +10709,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
       while (child_die && child_die->tag)
        {
          process_die (child_die, cu);
-         child_die = sibling_die (child_die);
+         child_die = child_die->sibling;
        }
     }
 
@@ -10968,7 +10877,7 @@ read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu)
       while (child_die && child_die->tag)
        {
          process_die (child_die, cu);
-         child_die = sibling_die (child_die);
+         child_die = child_die->sibling;
        }
     }
 }
@@ -12741,7 +12650,7 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
 
   for (child_die = die->child;
        child_die && child_die->tag;
-       child_die = sibling_die (child_die))
+       child_die = child_die->sibling)
     {
       struct die_info *child_origin_die;
       struct dwarf2_cu *child_origin_cu;
@@ -12818,7 +12727,7 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu)
          if (!origin_child_die->in_process)
            process_die (origin_child_die, origin_cu);
        }
-      origin_child_die = sibling_die (origin_child_die);
+      origin_child_die = origin_child_die->sibling;
     }
   origin_cu->list_in_scope = origin_previous_list_in_scope;
 
@@ -12887,7 +12796,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 
   /* If we have any template arguments, then we must allocate a
      different sort of symbol.  */
-  for (child_die = die->child; child_die; child_die = sibling_die (child_die))
+  for (child_die = die->child; child_die; child_die = child_die->sibling)
     {
       if (child_die->tag == DW_TAG_template_type_param
          || child_die->tag == DW_TAG_template_value_param)
@@ -12940,7 +12849,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
            }
          else
            process_die (child_die, cu);
-         child_die = sibling_die (child_die);
+         child_die = child_die->sibling;
        }
     }
 
@@ -12962,7 +12871,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
            {
              if (child_die->tag == DW_TAG_imported_module)
                process_die (child_die, spec_cu);
-             child_die = sibling_die (child_die);
+             child_die = child_die->sibling;
            }
 
          /* In some cases, GCC generates specification DIEs that
@@ -13051,7 +12960,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
         GCC does no longer produces such DWARF since GCC r224161.  */
       for (child_die = die->child;
           child_die != NULL && child_die->tag;
-          child_die = sibling_die (child_die))
+          child_die = child_die->sibling)
        process_die (child_die, cu);
       return;
     case PC_BOUNDS_INVALID:
@@ -13067,7 +12976,7 @@ read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
       while (child_die && child_die->tag)
        {
          process_die (child_die, cu);
-         child_die = sibling_die (child_die);
+         child_die = child_die->sibling;
        }
     }
   inherit_abstract_dies (die, cu);
@@ -13148,7 +13057,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 
   nparams = 0;
   for (child_die = die->child; child_die && child_die->tag;
-       child_die = sibling_die (child_die))
+       child_die = child_die->sibling)
     {
       if (child_die->tag != DW_TAG_call_site_parameter
           && child_die->tag != DW_TAG_GNU_call_site_parameter)
@@ -13293,7 +13202,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 
   for (child_die = die->child;
        child_die && child_die->tag;
-       child_die = sibling_die (child_die))
+       child_die = child_die->sibling)
     {
       struct call_site_parameter *parameter;
       struct attribute *loc, *origin;
@@ -13489,13 +13398,11 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   bfd *obfd = objfile->obfd;
   /* Base address selection entry.  */
-  CORE_ADDR base;
-  int found_base;
+  gdb::optional<CORE_ADDR> base;
   const gdb_byte *buffer;
   CORE_ADDR baseaddr;
   bool overflow = false;
 
-  found_base = cu->base_known;
   base = cu->base_address;
 
   dwarf2_per_objfile->rnglists.read (objfile);
@@ -13534,7 +13441,6 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
              break;
            }
          base = cu->header.read_address (obfd, buffer, &bytes_read);
-         found_base = 1;
          buffer += bytes_read;
          break;
        case DW_RLE_start_length:
@@ -13592,7 +13498,7 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
       if (rlet == DW_RLE_base_address)
        continue;
 
-      if (!found_base)
+      if (!base.has_value ())
        {
          /* We have no valid base address for the ranges
             data.  */
@@ -13611,8 +13517,8 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
       if (range_beginning == range_end)
        continue;
 
-      range_beginning += base;
-      range_end += base;
+      range_beginning += *base;
+      range_end += *base;
 
       /* A not-uncommon case of bad debug info.
         Don't pollute the addrmap with bad data.  */
@@ -13656,8 +13562,7 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
   unsigned int addr_size = cu_header->addr_size;
   CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
   /* Base address selection entry.  */
-  CORE_ADDR base;
-  int found_base;
+  gdb::optional<CORE_ADDR> base;
   unsigned int dummy;
   const gdb_byte *buffer;
   CORE_ADDR baseaddr;
@@ -13665,7 +13570,6 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
   if (cu_header->version >= 5)
     return dwarf2_rnglists_process (offset, cu, callback);
 
-  found_base = cu->base_known;
   base = cu->base_address;
 
   dwarf2_per_objfile->ranges.read (objfile);
@@ -13702,11 +13606,10 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
          /* If we found the largest possible address, then we already
             have the base address in range_end.  */
          base = range_end;
-         found_base = 1;
          continue;
        }
 
-      if (!found_base)
+      if (!base.has_value ())
        {
          /* We have no valid base address for the ranges
             data.  */
@@ -13725,8 +13628,8 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
       if (range_beginning == range_end)
        continue;
 
-      range_beginning += base;
-      range_end += base;
+      range_beginning += *base;
+      range_end += *base;
 
       /* A not-uncommon case of bad debug info.
         Don't pollute the addrmap with bad data.  */
@@ -13926,7 +13829,7 @@ dwarf2_get_subprogram_pc_bounds (struct die_info *die,
       if (child->tag == DW_TAG_subprogram
           || child->tag == DW_TAG_lexical_block)
         dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu);
-      child = sibling_die (child);
+      child = child->sibling;
     }
 }
 
@@ -13982,7 +13885,7 @@ get_scope_pc_bounds (struct die_info *die,
            break;
          }
 
-         child = sibling_die (child);
+         child = child->sibling;
        }
     }
 
@@ -15041,7 +14944,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
   /* If the definition of this type lives in .debug_types, read that type.
      Don't follow DW_AT_specification though, that will take us back up
      the chain and we want to go down.  */
-  attr = dwarf2_attr_no_follow (die, DW_AT_signature);
+  attr = die->attr (DW_AT_signature);
   if (attr != nullptr)
     {
       type = get_DW_AT_signature_type (die, attr, cu);
@@ -15220,7 +15123,7 @@ handle_struct_member_die (struct die_info *child_die, struct type *type,
 
       for (die_info *variant_child = child_die->child;
           variant_child != NULL;
-          variant_child = sibling_die (variant_child))
+          variant_child = variant_child->sibling)
        {
          if (variant_child->tag == DW_TAG_member)
            {
@@ -15310,7 +15213,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
          if (is_variant_part && discr_offset == child_die->sect_off)
            fi.fields.back ().variant.is_discriminant = true;
 
-         child_die = sibling_die (child_die);
+         child_die = child_die->sibling;
        }
 
       /* Attach template arguments to type.  */
@@ -15458,7 +15361,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
       else
        process_die (child_die, cu);
 
-      child_die = sibling_die (child_die);
+      child_die = child_die->sibling;
     }
 
   /* Do not consider external references.  According to the DWARF standard,
@@ -15519,7 +15422,7 @@ update_enumeration_type_from_children (struct die_info *die,
 
   for (child_die = die->child;
        child_die != NULL && child_die->tag;
-       child_die = sibling_die (child_die))
+       child_die = child_die->sibling)
     {
       struct attribute *attr;
       LONGEST value;
@@ -15577,7 +15480,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
   /* If the definition of this type lives in .debug_types, read that type.
      Don't follow DW_AT_specification though, that will take us back up
      the chain and we want to go down.  */
-  attr = dwarf2_attr_no_follow (die, DW_AT_signature);
+  attr = die->attr (DW_AT_signature);
   if (attr != nullptr)
     {
       type = get_DW_AT_signature_type (die, attr, cu);
@@ -15695,7 +15598,7 @@ process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu)
                }
            }
 
-         child_die = sibling_die (child_die);
+         child_die = child_die->sibling;
        }
 
       if (!fields.empty ())
@@ -15806,7 +15709,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
              range_types.push_back (child_type);
             }
        }
-      child_die = sibling_die (child_die);
+      child_die = child_die->sibling;
     }
 
   /* Dwarf2 dimensions are output from left to right, create the
@@ -16043,7 +15946,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
 
       for (child_die = die->child;
           child_die && child_die->tag;
-          child_die = sibling_die (child_die))
+          child_die = child_die->sibling)
        ++n_entries;
 
       size = (sizeof (struct common_block)
@@ -16056,7 +15959,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
 
       for (child_die = die->child;
           child_die && child_die->tag;
-          child_die = sibling_die (child_die))
+          child_die = child_die->sibling)
        {
          /* Create the symbol in the DW_TAG_common_block block in the current
             symbol scope.  */
@@ -16178,7 +16081,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu)
       while (child_die && child_die->tag)
        {
          process_die (child_die, cu);
-         child_die = sibling_die (child_die);
+         child_die = child_die->sibling;
        }
     }
 }
@@ -16214,7 +16117,7 @@ read_module (struct die_info *die, struct dwarf2_cu *cu)
   while (child_die && child_die->tag)
     {
       process_die (child_die, cu);
-      child_die = sibling_die (child_die);
+      child_die = child_die->sibling;
     }
 }
 
@@ -16713,7 +16616,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
            nparams++;
          else if (child_die->tag == DW_TAG_unspecified_parameters)
            TYPE_VARARGS (ftype) = 1;
-         child_die = sibling_die (child_die);
+         child_die = child_die->sibling;
        }
 
       /* Allocate storage for parameters and fill them in.  */
@@ -16784,7 +16687,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
              TYPE_FIELD_TYPE (ftype, iparams) = arg_type;
              iparams++;
            }
-         child_die = sibling_die (child_die);
+         child_die = child_die->sibling;
        }
     }
 
@@ -17603,11 +17506,11 @@ read_full_die_1 (const struct die_reader_specs *reader,
         indexes_that_need_reprocess.push_back (i);
     }
 
-  struct attribute *attr = dwarf2_attr_no_follow (die, DW_AT_str_offsets_base);
+  struct attribute *attr = die->attr (DW_AT_str_offsets_base);
   if (attr != nullptr)
     cu->str_offsets_base = DW_UNSND (attr);
 
-  auto maybe_addr_base = lookup_addr_base(die);
+  auto maybe_addr_base = die->addr_base ();
   if (maybe_addr_base.has_value ())
     cu->addr_base = *maybe_addr_base;
   for (int index : indexes_that_need_reprocess)
@@ -18730,33 +18633,6 @@ read_attribute (const struct die_reader_specs *reader,
                               need_reprocess);
 }
 
-/* Cover function for read_initial_length.
-   Returns the length of the object at BUF, and stores the size of the
-   initial length in *BYTES_READ and stores the size that offsets will be in
-   *OFFSET_SIZE.
-   If the initial length size is not equivalent to that specified in
-   CU_HEADER then issue a complaint.
-   This is useful when reading non-comp-unit headers.  */
-
-static LONGEST
-read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf,
-                                       const struct comp_unit_head *cu_header,
-                                       unsigned int *bytes_read,
-                                       unsigned int *offset_size)
-{
-  LONGEST length = read_initial_length (abfd, buf, bytes_read);
-
-  gdb_assert (cu_header->initial_length_size == 4
-             || cu_header->initial_length_size == 8
-             || cu_header->initial_length_size == 12);
-
-  if (cu_header->initial_length_size != *bytes_read)
-    complaint (_("intermixed 32-bit and 64-bit DWARF sections"));
-
-  *offset_size = (*bytes_read == 4) ? 4 : 8;
-  return length;
-}
-
 /* Return pointer to string at .debug_str offset STR_OFFSET.  */
 
 static const char *
@@ -19073,24 +18949,6 @@ dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu)
   return NULL;
 }
 
-/* Return the named attribute or NULL if not there,
-   but do not follow DW_AT_specification, etc.
-   This is for use in contexts where we're reading .debug_types dies.
-   Following DW_AT_specification, DW_AT_abstract_origin will take us
-   back up the chain, and we want to go down.  */
-
-static struct attribute *
-dwarf2_attr_no_follow (struct die_info *die, unsigned int name)
-{
-  unsigned int i;
-
-  for (i = 0; i < die->num_attrs; ++i)
-    if (die->attrs[i].name == name)
-      return &die->attrs[i];
-
-  return NULL;
-}
-
 /* Return the string associated with a string-typed attribute, or NULL if it
    is either not found or is of an incorrect type.  */
 
@@ -19217,140 +19075,6 @@ get_debug_line_section (struct dwarf2_cu *cu)
   return section;
 }
 
-/* Read directory or file name entry format, starting with byte of
-   format count entries, ULEB128 pairs of entry formats, ULEB128 of
-   entries count and the entries themselves in the described entry
-   format.  */
-
-static void
-read_formatted_entries (struct dwarf2_per_objfile *dwarf2_per_objfile,
-                       bfd *abfd, const gdb_byte **bufp,
-                       struct line_header *lh,
-                       const struct comp_unit_head *cu_header,
-                       void (*callback) (struct line_header *lh,
-                                         const char *name,
-                                         dir_index d_index,
-                                         unsigned int mod_time,
-                                         unsigned int length))
-{
-  gdb_byte format_count, formati;
-  ULONGEST data_count, datai;
-  const gdb_byte *buf = *bufp;
-  const gdb_byte *format_header_data;
-  unsigned int bytes_read;
-
-  format_count = read_1_byte (abfd, buf);
-  buf += 1;
-  format_header_data = buf;
-  for (formati = 0; formati < format_count; formati++)
-    {
-      read_unsigned_leb128 (abfd, buf, &bytes_read);
-      buf += bytes_read;
-      read_unsigned_leb128 (abfd, buf, &bytes_read);
-      buf += bytes_read;
-    }
-
-  data_count = read_unsigned_leb128 (abfd, buf, &bytes_read);
-  buf += bytes_read;
-  for (datai = 0; datai < data_count; datai++)
-    {
-      const gdb_byte *format = format_header_data;
-      struct file_entry fe;
-
-      for (formati = 0; formati < format_count; formati++)
-       {
-         ULONGEST content_type = read_unsigned_leb128 (abfd, format, &bytes_read);
-         format += bytes_read;
-
-         ULONGEST form  = read_unsigned_leb128 (abfd, format, &bytes_read);
-         format += bytes_read;
-
-         gdb::optional<const char *> string;
-         gdb::optional<unsigned int> uint;
-
-         switch (form)
-           {
-           case DW_FORM_string:
-             string.emplace (read_direct_string (abfd, buf, &bytes_read));
-             buf += bytes_read;
-             break;
-
-           case DW_FORM_line_strp:
-             string.emplace
-               (dwarf2_per_objfile->read_line_string (buf,
-                                                      cu_header,
-                                                      &bytes_read));
-             buf += bytes_read;
-             break;
-
-           case DW_FORM_data1:
-             uint.emplace (read_1_byte (abfd, buf));
-             buf += 1;
-             break;
-
-           case DW_FORM_data2:
-             uint.emplace (read_2_bytes (abfd, buf));
-             buf += 2;
-             break;
-
-           case DW_FORM_data4:
-             uint.emplace (read_4_bytes (abfd, buf));
-             buf += 4;
-             break;
-
-           case DW_FORM_data8:
-             uint.emplace (read_8_bytes (abfd, buf));
-             buf += 8;
-             break;
-
-           case DW_FORM_data16:
-             /*  This is used for MD5, but file_entry does not record MD5s. */
-             buf += 16;
-             break;
-
-           case DW_FORM_udata:
-             uint.emplace (read_unsigned_leb128 (abfd, buf, &bytes_read));
-             buf += bytes_read;
-             break;
-
-           case DW_FORM_block:
-             /* It is valid only for DW_LNCT_timestamp which is ignored by
-                current GDB.  */
-             break;
-           }
-
-         switch (content_type)
-           {
-           case DW_LNCT_path:
-             if (string.has_value ())
-               fe.name = *string;
-             break;
-           case DW_LNCT_directory_index:
-             if (uint.has_value ())
-               fe.d_index = (dir_index) *uint;
-             break;
-           case DW_LNCT_timestamp:
-             if (uint.has_value ())
-               fe.mod_time = *uint;
-             break;
-           case DW_LNCT_size:
-             if (uint.has_value ())
-               fe.length = *uint;
-             break;
-           case DW_LNCT_MD5:
-             break;
-           default:
-             complaint (_("Unknown format content type %s"),
-                        pulongest (content_type));
-           }
-       }
-
-      callback (lh, fe.name, fe.d_index, fe.mod_time, fe.length);
-    }
-
-  *bufp = buf;
-}
-
 /* Read the statement program header starting at OFFSET in
    .debug_line, or .debug_line.dwo.  Return a pointer
    to a struct line_header, allocated using xmalloc.
@@ -19364,12 +19088,7 @@ read_formatted_entries (struct dwarf2_per_objfile *dwarf2_per_objfile,
 static line_header_up
 dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
 {
-  const gdb_byte *line_ptr;
-  unsigned int bytes_read, offset_size;
-  int i;
-  const char *cur_dir, *cur_file;
   struct dwarf2_section_info *section;
-  bfd *abfd;
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = cu->per_cu->dwarf2_per_objfile;
 
@@ -19384,159 +19103,9 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
       return 0;
     }
 
-  /* We can't do this until we know the section is non-empty.
-     Only then do we know we have such a section.  */
-  abfd = section->get_bfd_owner ();
-
-  /* Make sure that at least there's room for the total_length field.
-     That could be 12 bytes long, but we're just going to fudge that.  */
-  if (to_underlying (sect_off) + 4 >= section->size)
-    {
-      dwarf2_statement_list_fits_in_line_number_section_complaint ();
-      return 0;
-    }
-
-  line_header_up lh (new line_header ());
-
-  lh->sect_off = sect_off;
-  lh->offset_in_dwz = cu->per_cu->is_dwz;
-
-  line_ptr = section->buffer + to_underlying (sect_off);
-
-  /* Read in the header.  */
-  lh->total_length =
-    read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header,
-                                           &bytes_read, &offset_size);
-  line_ptr += bytes_read;
-
-  const gdb_byte *start_here = line_ptr;
-
-  if (line_ptr + lh->total_length > (section->buffer + section->size))
-    {
-      dwarf2_statement_list_fits_in_line_number_section_complaint ();
-      return 0;
-    }
-  lh->statement_program_end = start_here + lh->total_length;
-  lh->version = read_2_bytes (abfd, line_ptr);
-  line_ptr += 2;
-  if (lh->version > 5)
-    {
-      /* This is a version we don't understand.  The format could have
-        changed in ways we don't handle properly so just punt.  */
-      complaint (_("unsupported version in .debug_line section"));
-      return NULL;
-    }
-  if (lh->version >= 5)
-    {
-      gdb_byte segment_selector_size;
-
-      /* Skip address size.  */
-      read_1_byte (abfd, line_ptr);
-      line_ptr += 1;
-
-      segment_selector_size = read_1_byte (abfd, line_ptr);
-      line_ptr += 1;
-      if (segment_selector_size != 0)
-       {
-         complaint (_("unsupported segment selector size %u "
-                      "in .debug_line section"),
-                    segment_selector_size);
-         return NULL;
-       }
-    }
-  lh->header_length = read_offset (abfd, line_ptr, offset_size);
-  line_ptr += offset_size;
-  lh->statement_program_start = line_ptr + lh->header_length;
-  lh->minimum_instruction_length = read_1_byte (abfd, line_ptr);
-  line_ptr += 1;
-  if (lh->version >= 4)
-    {
-      lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr);
-      line_ptr += 1;
-    }
-  else
-    lh->maximum_ops_per_instruction = 1;
-
-  if (lh->maximum_ops_per_instruction == 0)
-    {
-      lh->maximum_ops_per_instruction = 1;
-      complaint (_("invalid maximum_ops_per_instruction "
-                  "in `.debug_line' section"));
-    }
-
-  lh->default_is_stmt = read_1_byte (abfd, line_ptr);
-  line_ptr += 1;
-  lh->line_base = read_1_signed_byte (abfd, line_ptr);
-  line_ptr += 1;
-  lh->line_range = read_1_byte (abfd, line_ptr);
-  line_ptr += 1;
-  lh->opcode_base = read_1_byte (abfd, line_ptr);
-  line_ptr += 1;
-  lh->standard_opcode_lengths.reset (new unsigned char[lh->opcode_base]);
-
-  lh->standard_opcode_lengths[0] = 1;  /* This should never be used anyway.  */
-  for (i = 1; i < lh->opcode_base; ++i)
-    {
-      lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr);
-      line_ptr += 1;
-    }
-
-  if (lh->version >= 5)
-    {
-      /* Read directory table.  */
-      read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
-                             &cu->header,
-                             [] (struct line_header *header, const char *name,
-                                 dir_index d_index, unsigned int mod_time,
-                                 unsigned int length)
-       {
-         header->add_include_dir (name);
-       });
-
-      /* Read file name table.  */
-      read_formatted_entries (dwarf2_per_objfile, abfd, &line_ptr, lh.get (),
-                             &cu->header,
-                             [] (struct line_header *header, const char *name,
-                                 dir_index d_index, unsigned int mod_time,
-                                 unsigned int length)
-       {
-         header->add_file_name (name, d_index, mod_time, length);
-       });
-    }
-  else
-    {
-      /* Read directory table.  */
-      while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
-       {
-         line_ptr += bytes_read;
-         lh->add_include_dir (cur_dir);
-       }
-      line_ptr += bytes_read;
-
-      /* Read file name table.  */
-      while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL)
-       {
-         unsigned int mod_time, length;
-         dir_index d_index;
-
-         line_ptr += bytes_read;
-         d_index = (dir_index) read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
-         line_ptr += bytes_read;
-         mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
-         line_ptr += bytes_read;
-         length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
-         line_ptr += bytes_read;
-
-         lh->add_file_name (cur_file, d_index, mod_time, length);
-       }
-      line_ptr += bytes_read;
-    }
-
-  if (line_ptr > (section->buffer + section->size))
-    complaint (_("line number info header doesn't "
-                "fit in `.debug_line' section"));
-
-  return lh;
+  return dwarf_decode_line_header (sect_off, cu->per_cu->is_dwz,
+                                  dwarf2_per_objfile, section,
+                                  &cu->header);
 }
 
 /* Subroutine of dwarf_decode_lines to simplify it.
@@ -21637,14 +21206,6 @@ typename_concat (struct obstack *obs, const char *prefix, const char *suffix,
     }
 }
 
-/* Return sibling of die, NULL if no sibling.  */
-
-static struct die_info *
-sibling_die (struct die_info *die)
-{
-  return die->sibling;
-}
-
 /* Get name of a die, return NULL if not found.  */
 
 static const char *
@@ -23120,7 +22681,10 @@ fill_in_loclist_baton (struct dwarf2_cu *cu,
      don't run off the edge of the section.  */
   baton->size = section->size - DW_UNSND (attr);
   baton->data = section->buffer + DW_UNSND (attr);
-  baton->base_address = cu->base_address;
+  if (cu->base_address.has_value ())
+    baton->base_address = *cu->base_address;
+  else
+    baton->base_address = 0;
   baton->from_dwo = cu->dwo_unit != NULL;
 }
 
@@ -23145,7 +22709,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
 
       fill_in_loclist_baton (cu, baton, attr);
 
-      if (cu->base_known == 0)
+      if (!cu->base_address.has_value ())
        complaint (_("Location list used without "
                     "specifying the CU base address."));
 
This page took 0.051885 seconds and 4 git commands to generate.