]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/dwarf2/read.h
Add dwarf2_per_bfd field to dwarf2_per_cu_data
[thirdparty/binutils-gdb.git] / gdb / dwarf2 / read.h
index 00652c2b45a71dec209167c1df67bb6006bd35bc..02478d1aa84c0281159ad30fcc02974e453904f1 100644 (file)
@@ -66,32 +66,34 @@ struct dwarf2_queue_item
   enum language pretend_language;
 };
 
-/* Collection of data recorded per objfile.
-   This hangs off of dwarf2_objfile_data_key.  */
+/* Some DWARF data can be shared across objfiles who share the same BFD,
+   this data is stored in this object.
 
-struct dwarf2_per_objfile
+   Two dwarf2_per_objfile objects representing objfiles sharing the same BFD
+   will point to the same instance of dwarf2_per_bfd, unless the BFD requires
+   relocation.  */
+
+struct dwarf2_per_bfd
 {
-  /* Construct a dwarf2_per_objfile for OBJFILE.  NAMES points to the
+  /* Construct a dwarf2_per_bfd for OBFD.  NAMES points to the
      dwarf2 section names, or is NULL if the standard ELF names are
      used.  CAN_COPY is true for formats where symbol
      interposition is possible and so symbol values must follow copy
      relocation rules.  */
-  dwarf2_per_objfile (struct objfile *objfile,
-                     const dwarf2_debug_sections *names,
-                     bool can_copy);
+  dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names, bool can_copy);
 
-  ~dwarf2_per_objfile ();
+  ~dwarf2_per_bfd ();
 
-  DISABLE_COPY_AND_ASSIGN (dwarf2_per_objfile);
+  DISABLE_COPY_AND_ASSIGN (dwarf2_per_bfd);
 
   /* Return the CU/TU given its index.
 
      This is intended for loops like:
 
-     for (i = 0; i < (dwarf2_per_objfile->n_comp_units
-                     + dwarf2_per_objfile->n_type_units); ++i)
+     for (i = 0; i < (dwarf2_per_bfd->n_comp_units
+                     + dwarf2_per_bfd->n_type_units); ++i)
        {
-         dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);
+         dwarf2_per_cu_data *per_cu = dwarf2_per_bfd->get_cutu (i);
 
          ...;
        }
@@ -110,6 +112,22 @@ struct dwarf2_per_objfile
 
   /* Free all cached compilation units.  */
   void free_cached_comp_units ();
+
+  /* A convenience function to allocate a dwarf2_per_cu_data.  The
+     returned object has its "index" field set properly.  The object
+     is allocated on the dwarf2_per_bfd obstack.  */
+  dwarf2_per_cu_data *allocate_per_cu ();
+
+  /* A convenience function to allocate a signatured_type.  The
+     returned object has its "index" field set properly.  The object
+     is allocated on the dwarf2_per_bfd obstack.  */
+  signatured_type *allocate_signatured_type ();
+
+  /* Return the number of partial symtabs allocated with allocate_per_cu
+     and allocate_signatured_type so far.  */
+  int num_psymtabs () const
+  { return m_num_psymtabs; }
+
 private:
   /* This function is mapped across the sections and remembers the
      offset and size of each of the debugging sections we are
@@ -118,6 +136,11 @@ private:
                        const dwarf2_debug_sections &names);
 
 public:
+  /* Objects that can be shared across objfiles are stored in this
+     obstack or on the psymtab obstack, while objects that are
+     objfile-specific are stored on the objfile obstack.  */
+  auto_obstack obstack;
+
   dwarf2_section_info info {};
   dwarf2_section_info abbrev {};
   dwarf2_section_info line {};
@@ -139,9 +162,6 @@ public:
 
   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.  */
   std::vector<dwarf2_per_cu_data *> all_comp_units;
@@ -209,11 +229,6 @@ public:
      symbols.  */
   bool reading_partial_symbols = false;
 
-  /* Table mapping type DIEs to their struct type *.
-     This is NULL if not allocated yet.
-     The mapping is done via (CU/TU + DIE offset) -> type.  */
-  htab_up die_type_hash;
-
   /* The CUs we recently read.  */
   std::vector<dwarf2_per_cu_data *> just_read_cus;
 
@@ -236,28 +251,90 @@ public:
 
   /* CUs that are queued to be read.  */
   std::queue<dwarf2_queue_item> queue;
+
+private:
+
+  /* The total number of per_cu and signatured_type objects that have
+     been created so far for this reader.  */
+  size_t m_num_psymtabs = 0;
 };
 
-/* Get the dwarf2_per_objfile associated to OBJFILE.  */
+/* Collection of data recorded per objfile.
+   This hangs off of dwarf2_objfile_data_key.
 
-dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
+   Some DWARF data cannot (currently) be shared across objfiles.  Such
+   data is stored in this object.  */
 
-/* A partial symtab specialized for DWARF.  */
-struct dwarf2_psymtab : public standard_psymtab
+struct dwarf2_per_objfile
 {
-  dwarf2_psymtab (const char *filename, struct objfile *objfile)
-    : standard_psymtab (filename, objfile)
+  dwarf2_per_objfile (struct objfile *objfile, dwarf2_per_bfd *per_bfd)
+    : objfile (objfile), per_bfd (per_bfd)
+  {}
+
+  /* Return pointer to string at .debug_line_str offset as read from BUF.
+     BUF is assumed to be in a compilation unit described by CU_HEADER.
+     Return *BYTES_READ_PTR count of bytes read from BUF.  */
+  const char *read_line_string (const gdb_byte *buf,
+                               const struct comp_unit_head *cu_header,
+                               unsigned int *bytes_read_ptr);
+
+  /* Resize the M_SYMTABS vector to the needed size (the number of partial
+     symtabs allocated by the per-bfd).  */
+  void resize_symtabs ()
   {
+    /* The symtabs vector should only grow, not shrink.  */
+    gdb_assert (per_bfd->num_psymtabs () >= m_symtabs.size ());
+
+    m_symtabs.resize (per_bfd->num_psymtabs ());
   }
 
+  /* Return true if the symtab corresponding to PER_CU has been set,
+     false otherwise.  */
+  bool symtab_set_p (const dwarf2_per_cu_data *per_cu) const;
+
+  /* Return the compunit_symtab associated to PER_CU, if it has been created.  */
+  compunit_symtab *get_symtab (const dwarf2_per_cu_data *per_cu) const;
+
+  /* Set the compunit_symtab associated to PER_CU.  */
+  void set_symtab (const dwarf2_per_cu_data *per_cu, compunit_symtab *symtab);
+
+  /* Back link.  */
+  struct objfile *objfile;
+
+  /* Pointer to the data that is (possibly) shared between this objfile and
+     other objfiles backed by the same BFD.  */
+  struct dwarf2_per_bfd *per_bfd;
+
+  /* Table mapping type DIEs to their struct type *.
+     This is nullptr if not allocated yet.
+     The mapping is done via (CU/TU + DIE offset) -> type.  */
+  htab_up die_type_hash;
+
+private:
+  /* Hold the corresponding compunit_symtab for each CU or TU.  This
+     is indexed by dwarf2_per_cu_data::index.  A NULL value means
+     that the CU/TU has not been expanded yet.  */
+  std::vector<compunit_symtab *> m_symtabs;
+};
+
+/* Get the dwarf2_per_objfile associated to OBJFILE.  */
+
+dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
+
+/* A partial symtab specialized for DWARF.  */
+struct dwarf2_psymtab : public partial_symtab
+{
   dwarf2_psymtab (const char *filename, struct objfile *objfile,
-                 CORE_ADDR addr)
-    : standard_psymtab (filename, objfile, addr)
+                 dwarf2_per_cu_data *per_cu)
+    : partial_symtab (filename, objfile, 0),
+      per_cu_data (per_cu)
   {
   }
 
   void read_symtab (struct objfile *) override;
   void expand_psymtab (struct objfile *) override;
+  bool readin_p (struct objfile *) const override;
+  compunit_symtab *get_compunit_symtab (struct objfile *) const override;
 
   struct dwarf2_per_cu_data *per_cu_data;
 };
@@ -313,6 +390,9 @@ struct dwarf2_per_cu_data
      This flag is only valid if is_debug_types is true.  */
   unsigned int tu_read : 1;
 
+  /* Our index in the unshared "symtabs" vector.  */
+  unsigned index;
+
   /* The section this CU/TU lives in.
      If the DIE refers to a DWO file, this is always the original die,
      not the DWO file.  */
@@ -323,10 +403,19 @@ struct dwarf2_per_cu_data
      dummy CUs (a CU header, but nothing else).  */
   struct dwarf2_cu *cu;
 
+  /* The unit type of this CU.  */
+  enum dwarf_unit_type unit_type;
+
+  /* The language of this CU.  */
+  enum language lang;
+
   /* The corresponding dwarf2_per_objfile.  */
   struct dwarf2_per_objfile *dwarf2_per_objfile;
 
-  /* When dwarf2_per_objfile->using_index is true, the 'quick' field
+  /* Backlink to the owner of this.  */
+  dwarf2_per_bfd *per_bfd;
+
+  /* When dwarf2_per_bfd::using_index is true, the 'quick' field
      is active.  Otherwise, the 'psymtab' field is active.  */
   union
   {
@@ -485,37 +574,6 @@ struct signatured_type
   struct dwo_unit *dwo_unit;
 };
 
-/* 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.get ());
-  }
-
-  /* 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.  */