[1/3] gdb/dwarf: move cutu_reader to read.h

Message ID 20250306174143.53657-1-simon.marchi@polymtl.ca
State New
Headers
Series [1/3] gdb/dwarf: move cutu_reader to read.h |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Simon Marchi March 6, 2025, 5:41 p.m. UTC
  From: Simon Marchi <simon.marchi@polymtl.ca>

In order to move some things outside of read.c, cutu_reader needs to be
in a header file.

Change-Id: Ib26d7949c55867848d109332caf2efb1a6e72923
---
 gdb/dwarf2/read.c | 146 ---------------------------------------------
 gdb/dwarf2/read.h | 148 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 148 insertions(+), 146 deletions(-)


base-commit: ebb283e4ae23a647eaf4d6f417178e49f135f2e7
  

Comments

Tom Tromey March 6, 2025, 8:13 p.m. UTC | #1
>>>>> "Simon" == simon marchi <simon.marchi@polymtl.ca> writes:

Simon> From: Simon Marchi <simon.marchi@polymtl.ca>
Simon> In order to move some things outside of read.c, cutu_reader needs to be
Simon> in a header file.

Looks good.
Approved-By: Tom Tromey <tom@tromey.com>

Tom
  

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index dda925e43dbb..ccf532009686 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -626,152 +626,6 @@  struct dwp_file
   asection **elf_sections = nullptr;
 };
 
-class cutu_reader
-{
-public:
-
-  cutu_reader (dwarf2_per_cu *this_cu,
-	       dwarf2_per_objfile *per_objfile,
-	       const struct abbrev_table *abbrev_table,
-	       dwarf2_cu *existing_cu,
-	       bool skip_partial,
-	       enum language pretend_language,
-	       const abbrev_table_cache *cache = nullptr);
-
-  cutu_reader (dwarf2_per_cu *this_cu,
-	       dwarf2_per_objfile *per_objfile,
-	       enum language pretend_language,
-	       struct dwarf2_cu *parent_cu = nullptr,
-	       struct dwo_file *dwo_file = nullptr);
-
-  DISABLE_COPY_AND_ASSIGN (cutu_reader);
-
-  cutu_reader (cutu_reader &&) = default;
-
-  bool is_dummy () const { return m_dummy_p; }
-
-  dwarf2_cu *cu () const { return m_cu; }
-
-  die_info *comp_unit_die () const { return m_comp_unit_die; }
-
-  const gdb_byte *info_ptr () const { return m_info_ptr; }
-
-  bfd *abfd () const { return m_abfd; }
-
-  const gdb_byte *buffer () const { return m_buffer; }
-
-  const gdb_byte *buffer_end () const { return m_buffer_end; }
-
-  const dwarf2_section_info *section () const { return m_die_section; }
-
-  /* Release the new CU, putting it on the chain.  This cannot be done
-     for dummy CUs.  */
-  void keep ();
-
-  /* Release the abbrev table, transferring ownership to the
-     caller.  */
-  abbrev_table_up release_abbrev_table ()
-  {
-    return std::move (m_abbrev_table_holder);
-  }
-
-  die_info *read_die_and_siblings (const gdb_byte *info_ptr,
-				   const gdb_byte **new_info_ptr,
-				   die_info *parent);
-
-  const gdb_byte *read_attribute (attribute *attr, const attr_abbrev *abbrev,
-				  const gdb_byte *info_ptr,
-				  bool allow_reprocess = true);
-
-  const abbrev_info *peek_die_abbrev (const gdb_byte *info_ptr,
-				      unsigned int *bytes_read);
-
-  const gdb_byte *skip_one_die (const gdb_byte *info_ptr,
-				const abbrev_info *abbrev,
-				bool do_skip_children = true);
-
-  const gdb_byte *skip_children (const gdb_byte *info_ptr);
-
-private:
-  void init_cu_die_reader (dwarf2_cu *cu, dwarf2_section_info *section,
-			   struct dwo_file *dwo_file,
-			   const struct abbrev_table *abbrev_table);
-
-  void init_tu_and_read_dwo_dies (dwarf2_per_cu *this_cu,
-				  dwarf2_per_objfile *per_objfile,
-				  dwarf2_cu *existing_cu,
-				  enum language pretend_language);
-
-  int read_cutu_die_from_dwo (dwarf2_cu *cu, dwo_unit *dwo_unit,
-			      die_info *stub_comp_unit_die,
-			      const char *stub_comp_dir,
-			      const gdb_byte **result_info_ptr,
-			      die_info **result_comp_unit_die,
-			      abbrev_table_up *result_dwo_abbrev_table);
-
-  void prepare_one_comp_unit (struct dwarf2_cu *cu,
-			      enum language pretend_language);
-
-  const gdb_byte *read_toplevel_die (die_info **diep, const gdb_byte *info_ptr,
-				     gdb::array_view<attribute *> extra_attrs
-				     = {});
-
-  die_info *read_die_and_siblings_1 (const gdb_byte *, const gdb_byte **,
-				     die_info *);
-
-  die_info *read_die_and_children (const gdb_byte *info_ptr,
-				   const gdb_byte **new_info_ptr,
-				   die_info *parent);
-
-  const gdb_byte *read_full_die_1 (die_info **diep, const gdb_byte *info_ptr,
-				   int num_extra_attrs, bool allow_reprocess);
-
-  const gdb_byte *read_attribute_value (attribute *attr, unsigned form,
-					LONGEST implicit_const,
-					const gdb_byte *info_ptr,
-					bool allow_reprocess);
-
-  void read_attribute_reprocess (attribute *attr,
-				 dwarf_tag tag = DW_TAG_padding);
-
-  const char *read_dwo_str_index (ULONGEST str_index);
-
-  /* The bfd of die_section.  */
-  bfd *m_abfd;
-
-  /* The CU of the DIE we are parsing.  */
-  struct dwarf2_cu *m_cu;
-
-  /* Non-NULL if reading a DWO file (including one packaged into a DWP).  */
-  struct dwo_file *m_dwo_file;
-
-  /* The section the die comes from.
-    This is either .debug_info or .debug_types, or the .dwo variants.  */
-  struct dwarf2_section_info *m_die_section;
-
-  /* die_section->buffer.  */
-  const gdb_byte *m_buffer;
-
-  /* The end of the buffer.  */
-  const gdb_byte *m_buffer_end;
-
-  /* The abbreviation table to use when reading the DIEs.  */
-  const struct abbrev_table *m_abbrev_table;
-
-  const gdb_byte *m_info_ptr = nullptr;
-  struct die_info *m_comp_unit_die = nullptr;
-  bool m_dummy_p = false;
-
-  dwarf2_per_cu *m_this_cu;
-  dwarf2_cu_up m_new_cu;
-
-  /* The ordinary abbreviation table.  */
-  abbrev_table_up m_abbrev_table_holder;
-
-  /* The DWO abbreviation table.  */
-  abbrev_table_up m_dwo_abbrev_table;
-};
-
 /* 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.  */
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 44747bf7ccdd..dcaea14fb49b 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -21,6 +21,7 @@ 
 #define GDB_DWARF2_READ_H
 
 #include <queue>
+#include "dwarf2/abbrev.h"
 #include "dwarf2/comp-unit-head.h"
 #include "dwarf2/file-and-dir.h"
 #include "dwarf2/index-cache.h"
@@ -46,6 +47,7 @@  struct tu_stats
   int nr_tus = 0;
 };
 
+struct abbrev_table_cache;
 struct dwarf2_cu;
 struct dwarf2_debug_sections;
 struct dwarf2_per_bfd;
@@ -921,6 +923,152 @@  struct dwarf2_per_objfile
   gdb::unordered_map<dwarf2_per_cu *, dwarf2_cu_up> m_dwarf2_cus;
 };
 
+class cutu_reader
+{
+public:
+
+  cutu_reader (dwarf2_per_cu *this_cu,
+	       dwarf2_per_objfile *per_objfile,
+	       const struct abbrev_table *abbrev_table,
+	       dwarf2_cu *existing_cu,
+	       bool skip_partial,
+	       enum language pretend_language,
+	       const abbrev_table_cache *cache = nullptr);
+
+  cutu_reader (dwarf2_per_cu *this_cu,
+	       dwarf2_per_objfile *per_objfile,
+	       enum language pretend_language,
+	       struct dwarf2_cu *parent_cu = nullptr,
+	       struct dwo_file *dwo_file = nullptr);
+
+  DISABLE_COPY_AND_ASSIGN (cutu_reader);
+
+  cutu_reader (cutu_reader &&) = default;
+
+  bool is_dummy () const { return m_dummy_p; }
+
+  dwarf2_cu *cu () const { return m_cu; }
+
+  die_info *comp_unit_die () const { return m_comp_unit_die; }
+
+  const gdb_byte *info_ptr () const { return m_info_ptr; }
+
+  bfd *abfd () const { return m_abfd; }
+
+  const gdb_byte *buffer () const { return m_buffer; }
+
+  const gdb_byte *buffer_end () const { return m_buffer_end; }
+
+  const dwarf2_section_info *section () const { return m_die_section; }
+
+  /* Release the new CU, putting it on the chain.  This cannot be done
+     for dummy CUs.  */
+  void keep ();
+
+  /* Release the abbrev table, transferring ownership to the
+     caller.  */
+  abbrev_table_up release_abbrev_table ()
+  {
+    return std::move (m_abbrev_table_holder);
+  }
+
+  die_info *read_die_and_siblings (const gdb_byte *info_ptr,
+				   const gdb_byte **new_info_ptr,
+				   die_info *parent);
+
+  const gdb_byte *read_attribute (attribute *attr, const attr_abbrev *abbrev,
+				  const gdb_byte *info_ptr,
+				  bool allow_reprocess = true);
+
+  const abbrev_info *peek_die_abbrev (const gdb_byte *info_ptr,
+				      unsigned int *bytes_read);
+
+  const gdb_byte *skip_one_die (const gdb_byte *info_ptr,
+				const abbrev_info *abbrev,
+				bool do_skip_children = true);
+
+  const gdb_byte *skip_children (const gdb_byte *info_ptr);
+
+private:
+  void init_cu_die_reader (dwarf2_cu *cu, dwarf2_section_info *section,
+			   struct dwo_file *dwo_file,
+			   const struct abbrev_table *abbrev_table);
+
+  void init_tu_and_read_dwo_dies (dwarf2_per_cu *this_cu,
+				  dwarf2_per_objfile *per_objfile,
+				  dwarf2_cu *existing_cu,
+				  enum language pretend_language);
+
+  int read_cutu_die_from_dwo (dwarf2_cu *cu, dwo_unit *dwo_unit,
+			      die_info *stub_comp_unit_die,
+			      const char *stub_comp_dir,
+			      const gdb_byte **result_info_ptr,
+			      die_info **result_comp_unit_die,
+			      abbrev_table_up *result_dwo_abbrev_table);
+
+  void prepare_one_comp_unit (struct dwarf2_cu *cu,
+			      enum language pretend_language);
+
+  const gdb_byte *read_toplevel_die (die_info **diep, const gdb_byte *info_ptr,
+				     gdb::array_view<attribute *> extra_attrs
+				     = {});
+
+  die_info *read_die_and_siblings_1 (const gdb_byte *, const gdb_byte **,
+				     die_info *);
+
+  die_info *read_die_and_children (const gdb_byte *info_ptr,
+				   const gdb_byte **new_info_ptr,
+				   die_info *parent);
+
+  const gdb_byte *read_full_die_1 (die_info **diep, const gdb_byte *info_ptr,
+				   int num_extra_attrs, bool allow_reprocess);
+
+  const gdb_byte *read_attribute_value (attribute *attr, unsigned form,
+					LONGEST implicit_const,
+					const gdb_byte *info_ptr,
+					bool allow_reprocess);
+
+  void read_attribute_reprocess (attribute *attr,
+				 dwarf_tag tag = DW_TAG_padding);
+
+  const char *read_dwo_str_index (ULONGEST str_index);
+
+  /* The bfd of die_section.  */
+  bfd *m_abfd;
+
+  /* The CU of the DIE we are parsing.  */
+  struct dwarf2_cu *m_cu;
+
+  /* Non-NULL if reading a DWO file (including one packaged into a DWP).  */
+  struct dwo_file *m_dwo_file;
+
+  /* The section the die comes from.
+    This is either .debug_info or .debug_types, or the .dwo variants.  */
+  struct dwarf2_section_info *m_die_section;
+
+  /* die_section->buffer.  */
+  const gdb_byte *m_buffer;
+
+  /* The end of the buffer.  */
+  const gdb_byte *m_buffer_end;
+
+  /* The abbreviation table to use when reading the DIEs.  */
+  const struct abbrev_table *m_abbrev_table;
+
+  const gdb_byte *m_info_ptr = nullptr;
+  struct die_info *m_comp_unit_die = nullptr;
+  bool m_dummy_p = false;
+
+  dwarf2_per_cu *m_this_cu;
+  dwarf2_cu_up m_new_cu;
+
+  /* The ordinary abbreviation table.  */
+  abbrev_table_up m_abbrev_table_holder;
+
+  /* The DWO abbreviation table.  */
+  abbrev_table_up m_dwo_abbrev_table;
+};
+
 /* Converts DWARF language names to GDB language names.  */
 
 enum language dwarf_lang_to_enum_language (unsigned int lang);