PR24704, Internal error building skiboot for powerpc64-linux-gnu
[binutils-gdb.git] / gdb / dwarf2read.h
index 24b5ff47e7eb6d05197fd078e10d203233216448..9251bde125926bcb7d5d81d0a664f2b65012f47c 100644 (file)
@@ -1,6 +1,6 @@
 /* DWARF 2 debugging format support for GDB.
 
-   Copyright (C) 1994-2018 Free Software Foundation, Inc.
+   Copyright (C) 1994-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #ifndef DWARF2READ_H
 #define DWARF2READ_H
 
+#include <unordered_map>
+#include "dwarf-index-cache.h"
 #include "filename-seen-cache.h"
 #include "gdb_obstack.h"
+#include "common/hash_enum.h"
+
+/* Hold 'maintenance (set|show) dwarf' commands.  */
+extern struct cmd_list_element *set_dwarf_cmdlist;
+extern struct cmd_list_element *show_dwarf_cmdlist;
 
 typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr;
 DEF_VEC_P (dwarf2_per_cu_ptr);
@@ -60,15 +67,12 @@ struct dwarf2_section_info
      Only valid if is_virtual.  */
   bfd_size_type virtual_offset;
   /* True if we have tried to read this section.  */
-  char readin;
+  bool readin;
   /* True if this is a virtual section, False otherwise.
      This specifies which of s.section and s.containing_section to use.  */
-  char is_virtual;
+  bool is_virtual;
 };
 
-typedef struct dwarf2_section_info dwarf2_section_info_def;
-DEF_VEC_O (dwarf2_section_info_def);
-
 /* Read the contents of the section INFO.
    OBJFILE is the main object file, but not necessarily the file where
    the section comes from.  E.g., for DWO files the bfd of INFO is the bfd
@@ -90,11 +94,13 @@ struct dwarf2_debug_sections;
 struct mapped_index;
 struct mapped_debug_names;
 struct signatured_type;
+struct die_info;
+typedef struct die_info *die_info_ptr;
 
 /* Collection of data recorded per objfile.
    This hangs off of dwarf2_objfile_data_key.  */
 
-struct dwarf2_per_objfile : public allocate_on_obstack
+struct dwarf2_per_objfile
 {
   /* Construct a dwarf2_per_objfile for OBJFILE.  NAMES points to the
      dwarf2 section names, or is NULL if the standard ELF names are
@@ -158,28 +164,17 @@ public:
   dwarf2_section_info debug_names {};
   dwarf2_section_info debug_aranges {};
 
-  VEC (dwarf2_section_info_def) *types = NULL;
+  std::vector<dwarf2_section_info> types;
 
   /* Back link.  */
   struct objfile *objfile = NULL;
 
   /* Table of all the compilation units.  This is used to locate
      the target compilation unit of a particular reference.  */
-  struct dwarf2_per_cu_data **all_comp_units = NULL;
-
-  /* The number of compilation units in ALL_COMP_UNITS.  */
-  int n_comp_units = 0;
-
-  /* The number of .debug_types-related CUs.  */
-  int n_type_units = 0;
-
-  /* The number of elements allocated in all_type_units.
-     If there are skeleton-less TUs, we add them to all_type_units lazily.  */
-  int n_allocated_type_units = 0;
+  std::vector<dwarf2_per_cu_data *> all_comp_units;
 
-  /* The .debug_types-related CUs (TUs).
-     This is stored in malloc space because we may realloc it.  */
-  struct signatured_type **all_type_units = NULL;
+  /* The .debug_types-related CUs (TUs).  */
+  std::vector<signatured_type *> all_type_units;
 
   /* Table of struct type_unit_group objects.
      The hash key is the DW_AT_stmt_list value.  */
@@ -199,17 +194,17 @@ public:
 
   /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
      This is NULL if the table hasn't been allocated yet.  */
-  htab_t dwo_files {};
+  htab_up dwo_files;
 
   /* True if we've checked for whether there is a DWP file.  */
   bool dwp_checked = false;
 
   /* The DWP file if there is one, or NULL.  */
-  struct dwp_file *dwp_file = NULL;
+  std::unique_ptr<struct dwp_file> dwp_file;
 
   /* The shared '.dwz' file, if one exists.  This is used when the
      original data was compressed using 'dwz -m'.  */
-  struct dwz_file *dwz_file = NULL;
+  std::unique_ptr<struct dwz_file> dwz_file;
 
   /* A flag indicating whether this objfile has a section loaded at a
      VMA of 0.  */
@@ -220,7 +215,7 @@ public:
   bool using_index = false;
 
   /* The mapped index, or NULL if .gdb_index is missing or not being used.  */
-  mapped_index *index_table = NULL;
+  std::unique_ptr<mapped_index> index_table;
 
   /* The mapped index, or NULL if .debug_names is missing or not being used.  */
   std::unique_ptr<mapped_debug_names> debug_names_table;
@@ -244,7 +239,7 @@ public:
   htab_t die_type_hash {};
 
   /* The CUs we recently read.  */
-  VEC (dwarf2_per_cu_ptr) *just_read_cus = NULL;
+  std::vector<dwarf2_per_cu_data *> just_read_cus;
 
   /* Table containing line_header indexed by offset and offset_in_dwz.  */
   htab_t line_header_hash {};
@@ -252,6 +247,16 @@ public:
   /* Table containing all filenames.  This is an optional because the
      table is lazily constructed on first access.  */
   gdb::optional<filename_seen_cache> filenames_cache;
+
+  /* If we loaded the index from an external file, this contains the
+     resources associated to the open file, memory mapping, etc.  */
+  std::unique_ptr<index_cache_resource> index_cache_res;
+
+  /* Mapping from abstract origin DIE to concrete DIEs that reference it as
+     DW_AT_abstract_origin.  */
+  std::unordered_map<sect_offset, std::vector<sect_offset>, \
+                    gdb::hash_enum<sect_offset>> \
+    abstract_to_concrete;
 };
 
 /* Get the dwarf2_per_objfile associated to OBJFILE.  */
@@ -397,4 +402,44 @@ struct signatured_type
 typedef struct signatured_type *sig_type_ptr;
 DEF_VEC_P (sig_type_ptr);
 
+ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
+
+/* This represents a '.dwz' file.  */
+
+struct dwz_file
+{
+  dwz_file (gdb_bfd_ref_ptr &&bfd)
+    : dwz_bfd (std::move (bfd))
+  {
+  }
+
+  const char *filename () const
+  {
+    return bfd_get_filename (this->dwz_bfd);
+  }
+
+  /* A dwz file can only contain a few sections.  */
+  struct dwarf2_section_info abbrev {};
+  struct dwarf2_section_info info {};
+  struct dwarf2_section_info str {};
+  struct dwarf2_section_info line {};
+  struct dwarf2_section_info macro {};
+  struct dwarf2_section_info gdb_index {};
+  struct dwarf2_section_info debug_names {};
+
+  /* The dwz's BFD.  */
+  gdb_bfd_ref_ptr dwz_bfd;
+
+  /* If we loaded the index from an external file, this contains the
+     resources associated to the open file, memory mapping, etc.  */
+  std::unique_ptr<index_cache_resource> index_cache_res;
+};
+
+/* Open the separate '.dwz' debug file, if needed.  Return NULL if
+   there is no .gnu_debugaltlink section in the file.  Error if there
+   is such a section but the file cannot be found.  */
+
+extern struct dwz_file *dwarf2_get_dwz_file
+    (struct dwarf2_per_objfile *dwarf2_per_objfile);
+
 #endif /* DWARF2READ_H */