public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 33/38] Create dwarf2/comp-unit.[ch]
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (16 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 23/38] Change dwarf2_per_objfile::quick_file_names_table " Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 08/38] Remove die_info_ptr typedef Tom Tromey
                   ` (20 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This creates the new files dwarf2/comp-unit.[ch], moving
comp_unit_head and helpers to those files.  A couple of functions are
turned into methods, because it was convenient to do so now.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* Makefile.in (COMMON_SFILES): Add dwarf2/comp-unit.c.
	* dwarf2/read.c (struct comp_unit_head): Move to
	dwarf2/comp-unit.h.
	(enum class rcuh_kind): Move to comp-unit.h.
	(get_cu_length, offset_in_cu_p): Now methods on comp_unit_head.
	(read_comp_unit_head, error_check_comp_unit_head)
	(read_and_check_comp_unit_head): Move to comp-unit.c.
	(read_offset, dwarf_unit_type_name): Likewise.
	(create_debug_type_hash_table, read_cutu_die_from_dwo)
	(cutu_reader::cutu_reader, read_call_site_scope)
	(find_partial_die, follow_die_offset): Update.
	* dwarf2/comp-unit.h: New file, from dwarf2read.c.

Change-Id: Id961b9674c0081ed061083c8152c38b27b27388a
---
 gdb/ChangeLog          |  15 ++
 gdb/Makefile.in        |   1 +
 gdb/dwarf2/comp-unit.c | 237 ++++++++++++++++++++++++++++++++
 gdb/dwarf2/comp-unit.h | 114 ++++++++++++++++
 gdb/dwarf2/read.c      | 304 ++---------------------------------------
 5 files changed, 378 insertions(+), 293 deletions(-)
 create mode 100644 gdb/dwarf2/comp-unit.c
 create mode 100644 gdb/dwarf2/comp-unit.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index e4c2ebf968d..adb14fc1ce9 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -996,6 +996,7 @@ COMMON_SFILES = \
 	dummy-frame.c \
 	dwarf2/abbrev.c \
 	dwarf2/attribute.c \
+	dwarf2/comp-unit.c \
 	dwarf2/expr.c \
 	dwarf2/frame-tailcall.c \
 	dwarf2/frame.c \
diff --git a/gdb/dwarf2/comp-unit.c b/gdb/dwarf2/comp-unit.c
new file mode 100644
index 00000000000..03e804b7086
--- /dev/null
+++ b/gdb/dwarf2/comp-unit.c
@@ -0,0 +1,237 @@
+/* DWARF 2 debugging format support for GDB.
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "dwarf2/comp-unit.h"
+#include "dwarf2/leb.h"
+#include "dwarf2/read.h"
+#include "dwarf2/section.h"
+
+/* Convert a unit type to corresponding DW_UT name.  */
+
+static const char *
+dwarf_unit_type_name (int unit_type)
+{
+  switch (unit_type)
+    {
+      case 0x01:
+	return "DW_UT_compile (0x01)";
+      case 0x02:
+	return "DW_UT_type (0x02)";
+      case 0x03:
+	return "DW_UT_partial (0x03)";
+      case 0x04:
+	return "DW_UT_skeleton (0x04)";
+      case 0x05:
+	return "DW_UT_split_compile (0x05)";
+      case 0x06:
+	return "DW_UT_split_type (0x06)";
+      case 0x80:
+	return "DW_UT_lo_user (0x80)";
+      case 0xff:
+	return "DW_UT_hi_user (0xff)";
+      default:
+	return nullptr;
+    }
+}
+
+/* See comp-unit.h.  */
+
+const gdb_byte *
+read_comp_unit_head (struct comp_unit_head *cu_header,
+		     const gdb_byte *info_ptr,
+		     struct dwarf2_section_info *section,
+		     rcuh_kind section_kind)
+{
+  int signed_addr;
+  unsigned int bytes_read;
+  const char *filename = section->get_file_name ();
+  bfd *abfd = section->get_bfd_owner ();
+
+  cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
+  cu_header->initial_length_size = bytes_read;
+  cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
+  info_ptr += bytes_read;
+  cu_header->version = read_2_bytes (abfd, info_ptr);
+  if (cu_header->version < 2 || cu_header->version > 5)
+    error (_("Dwarf Error: wrong version in compilation unit header "
+	   "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
+	   cu_header->version, filename);
+  info_ptr += 2;
+  if (cu_header->version < 5)
+    switch (section_kind)
+      {
+      case rcuh_kind::COMPILE:
+	cu_header->unit_type = DW_UT_compile;
+	break;
+      case rcuh_kind::TYPE:
+	cu_header->unit_type = DW_UT_type;
+	break;
+      default:
+	internal_error (__FILE__, __LINE__,
+			_("read_comp_unit_head: invalid section_kind"));
+      }
+  else
+    {
+      cu_header->unit_type = static_cast<enum dwarf_unit_type>
+						 (read_1_byte (abfd, info_ptr));
+      info_ptr += 1;
+      switch (cu_header->unit_type)
+	{
+	case DW_UT_compile:
+	case DW_UT_partial:
+	case DW_UT_skeleton:
+	case DW_UT_split_compile:
+	  if (section_kind != rcuh_kind::COMPILE)
+	    error (_("Dwarf Error: wrong unit_type in compilation unit header "
+		   "(is %s, should be %s) [in module %s]"),
+		   dwarf_unit_type_name (cu_header->unit_type),
+		   dwarf_unit_type_name (DW_UT_type), filename);
+	  break;
+	case DW_UT_type:
+	case DW_UT_split_type:
+	  section_kind = rcuh_kind::TYPE;
+	  break;
+	default:
+	  error (_("Dwarf Error: wrong unit_type in compilation unit header "
+		 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
+		 "[in module %s]"), cu_header->unit_type,
+		 dwarf_unit_type_name (DW_UT_compile),
+		 dwarf_unit_type_name (DW_UT_skeleton),
+		 dwarf_unit_type_name (DW_UT_split_compile),
+		 dwarf_unit_type_name (DW_UT_type),
+		 dwarf_unit_type_name (DW_UT_split_type), filename);
+	}
+
+      cu_header->addr_size = read_1_byte (abfd, info_ptr);
+      info_ptr += 1;
+    }
+  cu_header->abbrev_sect_off = (sect_offset) read_offset (abfd, info_ptr,
+							  cu_header,
+							  &bytes_read);
+  info_ptr += bytes_read;
+  if (cu_header->version < 5)
+    {
+      cu_header->addr_size = read_1_byte (abfd, info_ptr);
+      info_ptr += 1;
+    }
+  signed_addr = bfd_get_sign_extend_vma (abfd);
+  if (signed_addr < 0)
+    internal_error (__FILE__, __LINE__,
+		    _("read_comp_unit_head: dwarf from non elf file"));
+  cu_header->signed_addr_p = signed_addr;
+
+  bool header_has_signature = section_kind == rcuh_kind::TYPE
+    || cu_header->unit_type == DW_UT_skeleton
+    || cu_header->unit_type == DW_UT_split_compile;
+
+  if (header_has_signature)
+    {
+      cu_header->signature = read_8_bytes (abfd, info_ptr);
+      info_ptr += 8;
+    }
+
+  if (section_kind == rcuh_kind::TYPE)
+    {
+      LONGEST type_offset;
+      type_offset = read_offset (abfd, info_ptr, cu_header, &bytes_read);
+      info_ptr += bytes_read;
+      cu_header->type_cu_offset_in_tu = (cu_offset) type_offset;
+      if (to_underlying (cu_header->type_cu_offset_in_tu) != type_offset)
+	error (_("Dwarf Error: Too big type_offset in compilation unit "
+	       "header (is %s) [in module %s]"), plongest (type_offset),
+	       filename);
+    }
+
+  return info_ptr;
+}
+
+/* Subroutine of read_and_check_comp_unit_head and
+   read_and_check_type_unit_head to simplify them.
+   Perform various error checking on the header.  */
+
+static void
+error_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
+			    struct comp_unit_head *header,
+			    struct dwarf2_section_info *section,
+			    struct dwarf2_section_info *abbrev_section)
+{
+  const char *filename = section->get_file_name ();
+
+  if (to_underlying (header->abbrev_sect_off)
+      >= abbrev_section->get_size (dwarf2_per_objfile->objfile))
+    error (_("Dwarf Error: bad offset (%s) in compilation unit header "
+	   "(offset %s + 6) [in module %s]"),
+	   sect_offset_str (header->abbrev_sect_off),
+	   sect_offset_str (header->sect_off),
+	   filename);
+
+  /* Cast to ULONGEST to use 64-bit arithmetic when possible to
+     avoid potential 32-bit overflow.  */
+  if (((ULONGEST) header->sect_off + header->get_length ())
+      > section->size)
+    error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
+	   "(offset %s + 0) [in module %s]"),
+	   header->length, sect_offset_str (header->sect_off),
+	   filename);
+}
+
+/* See comp-unit.h.  */
+
+const gdb_byte *
+read_and_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
+			       struct comp_unit_head *header,
+			       struct dwarf2_section_info *section,
+			       struct dwarf2_section_info *abbrev_section,
+			       const gdb_byte *info_ptr,
+			       rcuh_kind section_kind)
+{
+  const gdb_byte *beg_of_comp_unit = info_ptr;
+
+  header->sect_off = (sect_offset) (beg_of_comp_unit - section->buffer);
+
+  info_ptr = read_comp_unit_head (header, info_ptr, section, section_kind);
+
+  header->first_die_cu_offset = (cu_offset) (info_ptr - beg_of_comp_unit);
+
+  error_check_comp_unit_head (dwarf2_per_objfile, header, section,
+			      abbrev_section);
+
+  return info_ptr;
+}
+
+/* See comp-unit.h.  */
+
+LONGEST
+read_offset (bfd *abfd, const gdb_byte *buf,
+	     const struct comp_unit_head *cu_header,
+             unsigned int *bytes_read)
+{
+  LONGEST offset = read_offset (abfd, buf, cu_header->offset_size);
+
+  *bytes_read = cu_header->offset_size;
+  return offset;
+}
diff --git a/gdb/dwarf2/comp-unit.h b/gdb/dwarf2/comp-unit.h
new file mode 100644
index 00000000000..b4483ac1f7a
--- /dev/null
+++ b/gdb/dwarf2/comp-unit.h
@@ -0,0 +1,114 @@
+/* Low-level DWARF 2 reading code
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_DWARF2_COMP_UNIT_H
+#define GDB_DWARF2_COMP_UNIT_H
+
+#include "gdbtypes.h"
+
+/* The data in a compilation unit header, after target2host
+   translation, looks like this.  */
+struct comp_unit_head
+{
+  unsigned int length;
+  short version;
+  unsigned char addr_size;
+  unsigned char signed_addr_p;
+  sect_offset abbrev_sect_off;
+
+  /* Size of file offsets; either 4 or 8.  */
+  unsigned int offset_size;
+
+  /* Size of the length field; either 4 or 12.  */
+  unsigned int initial_length_size;
+
+  enum dwarf_unit_type unit_type;
+
+  /* Offset to the first byte of this compilation unit header in the
+     .debug_info section, for resolving relative reference dies.  */
+  sect_offset sect_off;
+
+  /* Offset to first die in this cu from the start of the cu.
+     This will be the first byte following the compilation unit header.  */
+  cu_offset first_die_cu_offset;
+
+
+  /* 64-bit signature of this unit. For type units, it denotes the signature of
+     the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
+     Also used in DWARF 5, to denote the dwo id when the unit type is
+     DW_UT_skeleton or DW_UT_split_compile.  */
+  ULONGEST signature;
+
+  /* For types, offset in the type's DIE of the type defined by this TU.  */
+  cu_offset type_cu_offset_in_tu;
+
+  /* Return the total length of the CU described by this header.  */
+  unsigned int get_length () const
+  {
+    return initial_length_size + length;
+  }
+
+  /* Return TRUE if OFF is within this CU.  */
+  bool offset_in_cu_p (sect_offset off) const
+  {
+    sect_offset bottom = sect_off;
+    sect_offset top = sect_off + get_length ();
+    return off >= bottom && off < top;
+  }
+};
+
+/* Expected enum dwarf_unit_type for read_comp_unit_head.  */
+enum class rcuh_kind { COMPILE, TYPE };
+
+/* Read in the comp unit header information from the debug_info at info_ptr.
+   Use rcuh_kind::COMPILE as the default type if not known by the caller.
+   NOTE: This leaves members offset, first_die_offset to be filled in
+   by the caller.  */
+extern const gdb_byte *read_comp_unit_head
+  (struct comp_unit_head *cu_header,
+   const gdb_byte *info_ptr,
+   struct dwarf2_section_info *section,
+   rcuh_kind section_kind);
+
+/* Read in a CU/TU header and perform some basic error checking.
+   The contents of the header are stored in HEADER.
+   The result is a pointer to the start of the first DIE.  */
+extern const gdb_byte *read_and_check_comp_unit_head
+  (struct dwarf2_per_objfile *dwarf2_per_objfile,
+   struct comp_unit_head *header,
+   struct dwarf2_section_info *section,
+   struct dwarf2_section_info *abbrev_section,
+   const gdb_byte *info_ptr,
+   rcuh_kind section_kind);
+
+/* Read an offset from the data stream.  The size of the offset is
+   given by cu_header->offset_size.  */
+
+extern LONGEST read_offset (bfd *abfd, const gdb_byte *buf,
+			    const struct comp_unit_head *cu_header,
+			    unsigned int *bytes_read);
+
+#endif /* GDB_DWARF2_COMP_UNIT_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 9ab3dc24938..b7401d408ce 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -32,6 +32,7 @@
 #include "dwarf2/read.h"
 #include "dwarf2/abbrev.h"
 #include "dwarf2/attribute.h"
+#include "dwarf2/comp-unit.h"
 #include "dwarf2/index-cache.h"
 #include "dwarf2/index-common.h"
 #include "dwarf2/leb.h"
@@ -340,43 +341,6 @@ dwop_section_names =
 
 /* local data types */
 
-/* The data in a compilation unit header, after target2host
-   translation, looks like this.  */
-struct comp_unit_head
-{
-  unsigned int length;
-  short version;
-  unsigned char addr_size;
-  unsigned char signed_addr_p;
-  sect_offset abbrev_sect_off;
-
-  /* Size of file offsets; either 4 or 8.  */
-  unsigned int offset_size;
-
-  /* Size of the length field; either 4 or 12.  */
-  unsigned int initial_length_size;
-
-  enum dwarf_unit_type unit_type;
-
-  /* Offset to the first byte of this compilation unit header in the
-     .debug_info section, for resolving relative reference dies.  */
-  sect_offset sect_off;
-
-  /* Offset to first die in this cu from the start of the cu.
-     This will be the first byte following the compilation unit header.  */
-  cu_offset first_die_cu_offset;
-
-
-  /* 64-bit signature of this unit. For type units, it denotes the signature of
-     the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
-     Also used in DWARF 5, to denote the dwo id when the unit type is
-     DW_UT_skeleton or DW_UT_split_compile.  */
-  ULONGEST signature;
-
-  /* For types, offset in the type's DIE of the type defined by this TU.  */
-  cu_offset type_cu_offset_in_tu;
-};
-
 /* Type used for delaying computation of method physnames.
    See comments for compute_delayed_physnames.  */
 struct delayed_method_info
@@ -1286,10 +1250,6 @@ static LONGEST read_checked_initial_length_and_offset
   (bfd *, const gdb_byte *, const struct comp_unit_head *,
    unsigned int *, unsigned int *);
 
-static LONGEST read_offset (bfd *, const gdb_byte *,
-			    const struct comp_unit_head *,
-			    unsigned int *);
-
 static sect_offset read_abbrev_offset
   (struct dwarf2_per_objfile *dwarf2_per_objfile,
    struct dwarf2_section_info *, sect_offset);
@@ -1517,8 +1477,6 @@ static const char *dwarf_tag_name (unsigned int);
 
 static const char *dwarf_attr_name (unsigned int);
 
-static const char *dwarf_unit_type_name (int unit_type);
-
 static const char *dwarf_form_name (unsigned int);
 
 static const char *dwarf_bool_name (unsigned int);
@@ -1702,16 +1660,6 @@ struct file_and_directory
 static file_and_directory find_file_and_directory (struct die_info *die,
 						   struct dwarf2_cu *cu);
 
-/* Expected enum dwarf_unit_type for read_comp_unit_head.  */
-enum class rcuh_kind { COMPILE, TYPE };
-
-static const gdb_byte *read_and_check_comp_unit_head
-  (struct dwarf2_per_objfile* dwarf2_per_objfile,
-   struct comp_unit_head *header,
-   struct dwarf2_section_info *section,
-   struct dwarf2_section_info *abbrev_section, const gdb_byte *info_ptr,
-   rcuh_kind section_kind);
-
 static htab_up allocate_signatured_type_table (struct objfile *objfile);
 
 static htab_up allocate_dwo_unit_table (struct objfile *objfile);
@@ -5885,25 +5833,6 @@ dwarf2_build_psymtabs (struct objfile *objfile)
     }
 }
 
-/* Return the total length of the CU described by HEADER.  */
-
-static unsigned int
-get_cu_length (const struct comp_unit_head *header)
-{
-  return header->initial_length_size + header->length;
-}
-
-/* Return TRUE if SECT_OFF is within CU_HEADER.  */
-
-static inline bool
-offset_in_cu_p (const comp_unit_head *cu_header, sect_offset sect_off)
-{
-  sect_offset bottom = cu_header->sect_off;
-  sect_offset top = cu_header->sect_off + get_cu_length (cu_header);
-
-  return sect_off >= bottom && sect_off < top;
-}
-
 /* Find the base address of the compilation unit for range lists and
    location lists.  It will normally be specified by DW_AT_low_pc.
    In DWARF-3 draft 4, the base address could be overridden by
@@ -5935,120 +5864,6 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
     }
 }
 
-/* Read in the comp unit header information from the debug_info at info_ptr.
-   Use rcuh_kind::COMPILE as the default type if not known by the caller.
-   NOTE: This leaves members offset, first_die_offset to be filled in
-   by the caller.  */
-
-static const gdb_byte *
-read_comp_unit_head (struct comp_unit_head *cu_header,
-		     const gdb_byte *info_ptr,
-		     struct dwarf2_section_info *section,
-		     rcuh_kind section_kind)
-{
-  int signed_addr;
-  unsigned int bytes_read;
-  const char *filename = section->get_file_name ();
-  bfd *abfd = section->get_bfd_owner ();
-
-  cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
-  cu_header->initial_length_size = bytes_read;
-  cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
-  info_ptr += bytes_read;
-  cu_header->version = read_2_bytes (abfd, info_ptr);
-  if (cu_header->version < 2 || cu_header->version > 5)
-    error (_("Dwarf Error: wrong version in compilation unit header "
-	   "(is %d, should be 2, 3, 4 or 5) [in module %s]"),
-	   cu_header->version, filename);
-  info_ptr += 2;
-  if (cu_header->version < 5)
-    switch (section_kind)
-      {
-      case rcuh_kind::COMPILE:
-	cu_header->unit_type = DW_UT_compile;
-	break;
-      case rcuh_kind::TYPE:
-	cu_header->unit_type = DW_UT_type;
-	break;
-      default:
-	internal_error (__FILE__, __LINE__,
-			_("read_comp_unit_head: invalid section_kind"));
-      }
-  else
-    {
-      cu_header->unit_type = static_cast<enum dwarf_unit_type>
-						 (read_1_byte (abfd, info_ptr));
-      info_ptr += 1;
-      switch (cu_header->unit_type)
-	{
-	case DW_UT_compile:
-	case DW_UT_partial:
-	case DW_UT_skeleton:
-	case DW_UT_split_compile:
-	  if (section_kind != rcuh_kind::COMPILE)
-	    error (_("Dwarf Error: wrong unit_type in compilation unit header "
-		   "(is %s, should be %s) [in module %s]"),
-		   dwarf_unit_type_name (cu_header->unit_type),
-		   dwarf_unit_type_name (DW_UT_type), filename);
-	  break;
-	case DW_UT_type:
-	case DW_UT_split_type:
-	  section_kind = rcuh_kind::TYPE;
-	  break;
-	default:
-	  error (_("Dwarf Error: wrong unit_type in compilation unit header "
-		 "(is %#04x, should be one of: %s, %s, %s, %s or %s) "
-		 "[in module %s]"), cu_header->unit_type,
-		 dwarf_unit_type_name (DW_UT_compile),
-		 dwarf_unit_type_name (DW_UT_skeleton),
-		 dwarf_unit_type_name (DW_UT_split_compile),
-		 dwarf_unit_type_name (DW_UT_type),
-		 dwarf_unit_type_name (DW_UT_split_type), filename);
-	}
-
-      cu_header->addr_size = read_1_byte (abfd, info_ptr);
-      info_ptr += 1;
-    }
-  cu_header->abbrev_sect_off = (sect_offset) read_offset (abfd, info_ptr,
-							  cu_header,
-							  &bytes_read);
-  info_ptr += bytes_read;
-  if (cu_header->version < 5)
-    {
-      cu_header->addr_size = read_1_byte (abfd, info_ptr);
-      info_ptr += 1;
-    }
-  signed_addr = bfd_get_sign_extend_vma (abfd);
-  if (signed_addr < 0)
-    internal_error (__FILE__, __LINE__,
-		    _("read_comp_unit_head: dwarf from non elf file"));
-  cu_header->signed_addr_p = signed_addr;
-
-  bool header_has_signature = section_kind == rcuh_kind::TYPE
-    || cu_header->unit_type == DW_UT_skeleton
-    || cu_header->unit_type == DW_UT_split_compile;
-
-  if (header_has_signature)
-    {
-      cu_header->signature = read_8_bytes (abfd, info_ptr);
-      info_ptr += 8;
-    }
-
-  if (section_kind == rcuh_kind::TYPE)
-    {
-      LONGEST type_offset;
-      type_offset = read_offset (abfd, info_ptr, cu_header, &bytes_read);
-      info_ptr += bytes_read;
-      cu_header->type_cu_offset_in_tu = (cu_offset) type_offset;
-      if (to_underlying (cu_header->type_cu_offset_in_tu) != type_offset)
-	error (_("Dwarf Error: Too big type_offset in compilation unit "
-	       "header (is %s) [in module %s]"), plongest (type_offset),
-	       filename);
-    }
-
-  return info_ptr;
-}
-
 /* Helper function that returns the proper abbrev section for
    THIS_CU.  */
 
@@ -6066,62 +5881,6 @@ get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
   return abbrev;
 }
 
-/* Subroutine of read_and_check_comp_unit_head and
-   read_and_check_type_unit_head to simplify them.
-   Perform various error checking on the header.  */
-
-static void
-error_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
-			    struct comp_unit_head *header,
-			    struct dwarf2_section_info *section,
-			    struct dwarf2_section_info *abbrev_section)
-{
-  const char *filename = section->get_file_name ();
-
-  if (to_underlying (header->abbrev_sect_off)
-      >= abbrev_section->get_size (dwarf2_per_objfile->objfile))
-    error (_("Dwarf Error: bad offset (%s) in compilation unit header "
-	   "(offset %s + 6) [in module %s]"),
-	   sect_offset_str (header->abbrev_sect_off),
-	   sect_offset_str (header->sect_off),
-	   filename);
-
-  /* Cast to ULONGEST to use 64-bit arithmetic when possible to
-     avoid potential 32-bit overflow.  */
-  if (((ULONGEST) header->sect_off + get_cu_length (header))
-      > section->size)
-    error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
-	   "(offset %s + 0) [in module %s]"),
-	   header->length, sect_offset_str (header->sect_off),
-	   filename);
-}
-
-/* Read in a CU/TU header and perform some basic error checking.
-   The contents of the header are stored in HEADER.
-   The result is a pointer to the start of the first DIE.  */
-
-static const gdb_byte *
-read_and_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
-			       struct comp_unit_head *header,
-			       struct dwarf2_section_info *section,
-			       struct dwarf2_section_info *abbrev_section,
-			       const gdb_byte *info_ptr,
-			       rcuh_kind section_kind)
-{
-  const gdb_byte *beg_of_comp_unit = info_ptr;
-
-  header->sect_off = (sect_offset) (beg_of_comp_unit - section->buffer);
-
-  info_ptr = read_comp_unit_head (header, info_ptr, section, section_kind);
-
-  header->first_die_cu_offset = (cu_offset) (info_ptr - beg_of_comp_unit);
-
-  error_check_comp_unit_head (dwarf2_per_objfile, header, section,
-			      abbrev_section);
-
-  return info_ptr;
-}
-
 /* Fetch the abbreviation table offset from a comp or type unit header.  */
 
 static sect_offset
@@ -6307,7 +6066,7 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
       ptr = read_and_check_comp_unit_head (dwarf2_per_objfile, &header, section,
 					   abbrev_section, ptr, section_kind);
 
-      length = get_cu_length (&header);
+      length = header.get_length ();
 
       /* Skip dummy type units.  */
       if (ptr >= info_ptr + length
@@ -6843,7 +6602,7 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
       gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
       /* For DWOs coming from DWP files, we don't know the CU length
 	 nor the type's offset in the TU until now.  */
-      dwo_unit->length = get_cu_length (&cu->header);
+      dwo_unit->length = cu->header.get_length ();
       dwo_unit->type_offset_in_tu = cu->header.type_cu_offset_in_tu;
 
       /* Establish the type offset that can be used to lookup the type.
@@ -6860,7 +6619,7 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
       gdb_assert (dwo_unit->sect_off == cu->header.sect_off);
       /* For DWOs coming from DWP files, we don't know the CU length
 	 until now.  */
-      dwo_unit->length = get_cu_length (&cu->header);
+      dwo_unit->length = cu->header.get_length ();
     }
 
   *result_dwo_abbrev_table
@@ -7124,7 +6883,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
 
 	  /* LENGTH has not been set yet for type units if we're
 	     using .gdb_index.  */
-	  this_cu->length = get_cu_length (&cu->header);
+	  this_cu->length = cu->header.get_length ();
 
 	  /* Establish the type offset that can be used to lookup the type.  */
 	  sig_type->type_offset_in_section =
@@ -7141,7 +6900,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
 						    rcuh_kind::COMPILE);
 
 	  gdb_assert (this_cu->sect_off == cu->header.sect_off);
-	  gdb_assert (this_cu->length == get_cu_length (&cu->header));
+	  gdb_assert (this_cu->length == cu->header.get_length ());
 	  this_cu->dwarf_version = cu->header.version;
 	}
     }
@@ -7297,7 +7056,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
       m_new_cu->str_offsets_base = parent_cu->str_offsets_base;
       m_new_cu->addr_base = parent_cu->addr_base;
     }
-  this_cu->length = get_cu_length (&m_new_cu->header);
+  this_cu->length = m_new_cu->header.get_length ();
 
   /* Skip dummy compilation units.  */
   if (info_ptr >= begin_info_ptr + this_cu->length
@@ -13593,7 +13352,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 
 	  sect_offset sect_off
 	    = (sect_offset) dwarf2_get_ref_die_offset (origin);
-	  if (!offset_in_cu_p (&cu->header, sect_off))
+	  if (!cu->header.offset_in_cu_p (sect_off))
 	    {
 	      /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
 		 binding can be done only inside one CU.  Such referenced DIE
@@ -18479,7 +18238,7 @@ find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
   struct partial_die_info *pd = NULL;
 
   if (offset_in_dwz == cu->per_cu->is_dwz
-      && offset_in_cu_p (&cu->header, sect_off))
+      && cu->header.offset_in_cu_p (sect_off))
     {
       pd = cu->find_partial_die (sect_off);
       if (pd != NULL)
@@ -19068,20 +18827,6 @@ read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf,
   return length;
 }
 
-/* Read an offset from the data stream.  The size of the offset is
-   given by cu_header->offset_size.  */
-
-static LONGEST
-read_offset (bfd *abfd, const gdb_byte *buf,
-	     const struct comp_unit_head *cu_header,
-             unsigned int *bytes_read)
-{
-  LONGEST offset = read_offset (abfd, buf, cu_header->offset_size);
-
-  *bytes_read = cu_header->offset_size;
-  return offset;
-}
-
 static const gdb_byte *
 read_n_bytes (bfd *abfd, const gdb_byte *buf, unsigned int size)
 {
@@ -22244,33 +21989,6 @@ dwarf_attr_name (unsigned attr)
   return name;
 }
 
-/* Convert a unit type to corresponding DW_UT name.  */
-
-static const char *
-dwarf_unit_type_name (int unit_type) {
-  switch (unit_type)
-    {
-      case 0x01:
-	return "DW_UT_compile (0x01)";
-      case 0x02:
-	return "DW_UT_type (0x02)";
-      case 0x03:
-	return "DW_UT_partial (0x03)";
-      case 0x04:
-	return "DW_UT_skeleton (0x04)";
-      case 0x05:
-	return "DW_UT_split_compile (0x05)";
-      case 0x06:
-	return "DW_UT_split_type (0x06)";
-      case 0x80:
-	return "DW_UT_lo_user (0x80)";
-      case 0xff:
-	return "DW_UT_hi_user (0xff)";
-      default:
-	return nullptr;
-    }
-}
-
 /* Convert a DWARF value form code into its string name.  */
 
 static const char *
@@ -22576,11 +22294,11 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
       /* .debug_types CUs cannot reference anything outside their CU.
 	 If they need to, they have to reference a signatured type via
 	 DW_FORM_ref_sig8.  */
-      if (!offset_in_cu_p (&cu->header, sect_off))
+      if (!cu->header.offset_in_cu_p (sect_off))
 	return NULL;
     }
   else if (offset_in_dwz != cu->per_cu->is_dwz
-	   || !offset_in_cu_p (&cu->header, sect_off))
+	   || !cu->header.offset_in_cu_p (sect_off))
     {
       struct dwarf2_per_cu_data *per_cu;
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 19/38] Change dwarf2_per_objfile::die_type_hash to htab_up
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (3 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 31/38] Convert dwarf2_section_size to a method Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 27/38] Move DWARF line_header to new file Tom Tromey
                   ` (33 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes dwarf2_per_objfile::die_type_hash to be an htab_up,
moving its contents off the objfile obstack.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (set_die_type, get_die_type_at_offset): Update.
	* dwarf2/read.h (struct dwarf2_per_objfile) <die_type_hash>: Now
	htab_up.

Change-Id: Ic651f99ebf71bf7ad2dc2880192adacf7b60964a
---
 gdb/ChangeLog     |  6 ++++++
 gdb/dwarf2/read.c | 19 +++++++------------
 gdb/dwarf2/read.h |  2 +-
 3 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 5becbd5ef9b..76651ac7a41 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -25229,22 +25229,17 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
     add_dyn_prop (DYN_PROP_DATA_LOCATION, prop, type);
 
   if (dwarf2_per_objfile->die_type_hash == NULL)
-    {
-      dwarf2_per_objfile->die_type_hash =
-	htab_create_alloc_ex (127,
-			      per_cu_offset_and_type_hash,
-			      per_cu_offset_and_type_eq,
-			      NULL,
-			      &objfile->objfile_obstack,
-			      hashtab_obstack_allocate,
-			      dummy_obstack_deallocate);
-    }
+    dwarf2_per_objfile->die_type_hash
+      = htab_up (htab_create_alloc (127,
+				    per_cu_offset_and_type_hash,
+				    per_cu_offset_and_type_eq,
+				    NULL, xcalloc, xfree));
 
   ofs.per_cu = cu->per_cu;
   ofs.sect_off = die->sect_off;
   ofs.type = type;
   slot = (struct dwarf2_per_cu_offset_and_type **)
-    htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT);
+    htab_find_slot (dwarf2_per_objfile->die_type_hash.get (), &ofs, INSERT);
   if (*slot)
     complaint (_("A problem internal to GDB: DIE %s has type already set"),
 	       sect_offset_str (die->sect_off));
@@ -25270,7 +25265,7 @@ get_die_type_at_offset (sect_offset sect_off,
   ofs.per_cu = per_cu;
   ofs.sect_off = sect_off;
   slot = ((struct dwarf2_per_cu_offset_and_type *)
-	  htab_find (dwarf2_per_objfile->die_type_hash, &ofs));
+	  htab_find (dwarf2_per_objfile->die_type_hash.get (), &ofs));
   if (slot)
     return slot->type;
   else
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 91d5c58faa0..92a5562e0e1 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -213,7 +213,7 @@ public:
   /* 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_t die_type_hash {};
+  htab_up die_type_hash;
 
   /* The CUs we recently read.  */
   std::vector<dwarf2_per_cu_data *> just_read_cus;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 13/38] Remove DWARF queue-related globals
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (9 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 22/38] Minor simplification in abbrev_table::read Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 02/38] Create dwarf2/section.[ch] Tom Tromey
                   ` (27 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes some queue-related globals from the DWARF reader, in
favor of a new member on dwarf2_per_objfile.  Globals must be avoided
in this code, because they prevent multi-threading the reader.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_queue_item): Move from
	dwarf2/read.c.  Remove "next" member.  Add constructor ntad
	destructor.
	(struct dwarf2_per_objfile) <queue>: New member.
	* dwarf2/read.c (struct dwarf2_queue_item): Move to
	dwarf2/read.h.
	(dwarf2_queue, dwarf2_queue_tail): Remove.
	(class dwarf2_queue_guard): Add parameter to constructor.  Use
	DISABLE_COPY_AND_ASSIGN.
	<m_per_objfile>: New member.
	<~dwarf2_queue_guard>: Rewrite.
	(dw2_do_instantiate_symtab, queue_comp_unit, process_queue):
	Update.
	(~dwarf2_queue_item): New.

Change-Id: Ied1f6ff3691352a66c4709b0b2cba0588f49f79a
---
 gdb/ChangeLog     | 17 +++++++++
 gdb/dwarf2/read.c | 96 ++++++++++++++++++-----------------------------
 gdb/dwarf2/read.h | 23 ++++++++++++
 3 files changed, 76 insertions(+), 60 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index a35a55673dc..1e64870678e 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1335,18 +1335,6 @@ struct field_info
     std::vector<struct decl_field> nested_types_list;
   };
 
-/* One item on the queue of compilation units to read in full symbols
-   for.  */
-struct dwarf2_queue_item
-{
-  struct dwarf2_per_cu_data *per_cu;
-  enum language pretend_language;
-  struct dwarf2_queue_item *next;
-};
-
-/* The current queue.  */
-static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail;
-
 /* Loaded secondary compilation units are kept in memory until they
    have not been referenced for the processing of this many
    compilation units.  Set this to zero to disable caching.  Cache
@@ -1818,35 +1806,38 @@ static struct type *dwarf2_per_cu_int_type
 class dwarf2_queue_guard
 {
 public:
-  dwarf2_queue_guard () = default;
+  explicit dwarf2_queue_guard (dwarf2_per_objfile *per_objfile)
+    : m_per_objfile (per_objfile)
+  {
+  }
 
   /* Free any entries remaining on the queue.  There should only be
      entries left if we hit an error while processing the dwarf.  */
   ~dwarf2_queue_guard ()
   {
-    struct dwarf2_queue_item *item, *last;
-
-    item = dwarf2_queue;
-    while (item)
-      {
-	/* Anything still marked queued is likely to be in an
-	   inconsistent state, so discard it.  */
-	if (item->per_cu->queued)
-	  {
-	    if (item->per_cu->cu != NULL)
-	      free_one_cached_comp_unit (item->per_cu);
-	    item->per_cu->queued = 0;
-	  }
+    /* Ensure that no memory is allocated by the queue.  */
+    std::queue<dwarf2_queue_item> empty;
+    std::swap (m_per_objfile->queue, empty);
+  }
 
-	last = item;
-	item = item->next;
-	xfree (last);
-      }
+  DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard);
 
-    dwarf2_queue = dwarf2_queue_tail = NULL;
-  }
+private:
+  dwarf2_per_objfile *m_per_objfile;
 };
 
+dwarf2_queue_item::~dwarf2_queue_item ()
+{
+  /* Anything still marked queued is likely to be in an
+     inconsistent state, so discard it.  */
+  if (per_cu->queued)
+    {
+      if (per_cu->cu != NULL)
+	free_one_cached_comp_unit (per_cu);
+      per_cu->queued = 0;
+    }
+}
+
 /* The return type of find_file_and_directory.  Note, the enclosed
    string pointers are only valid while this object is valid.  */
 
@@ -2582,7 +2573,7 @@ dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial)
   /* The destructor of dwarf2_queue_guard frees any entries left on
      the queue.  After this point we're guaranteed to leave this function
      with the dwarf queue empty.  */
-  dwarf2_queue_guard q_guard;
+  dwarf2_queue_guard q_guard (dwarf2_per_objfile);
 
   if (dwarf2_per_objfile->using_index
       ? per_cu->v.quick->compunit_symtab == NULL
@@ -9188,20 +9179,8 @@ static void
 queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
 		 enum language pretend_language)
 {
-  struct dwarf2_queue_item *item;
-
   per_cu->queued = 1;
-  item = XNEW (struct dwarf2_queue_item);
-  item->per_cu = per_cu;
-  item->pretend_language = pretend_language;
-  item->next = NULL;
-
-  if (dwarf2_queue == NULL)
-    dwarf2_queue = item;
-  else
-    dwarf2_queue_tail->next = item;
-
-  dwarf2_queue_tail = item;
+  per_cu->dwarf2_per_objfile->queue.emplace (per_cu, pretend_language);
 }
 
 /* If PER_CU is not yet queued, add it to the queue.
@@ -9256,8 +9235,6 @@ maybe_queue_comp_unit (struct dwarf2_cu *dependent_cu,
 static void
 process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
 {
-  struct dwarf2_queue_item *item, *next_item;
-
   if (dwarf_read_debug)
     {
       fprintf_unfiltered (gdb_stdlog,
@@ -9267,15 +9244,17 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   /* The queue starts out with one item, but following a DIE reference
      may load a new CU, adding it to the end of the queue.  */
-  for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item)
+  while (!dwarf2_per_objfile->queue.empty ())
     {
+      dwarf2_queue_item &item = dwarf2_per_objfile->queue.front ();
+
       if ((dwarf2_per_objfile->using_index
-	   ? !item->per_cu->v.quick->compunit_symtab
-	   : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin))
+	   ? !item.per_cu->v.quick->compunit_symtab
+	   : (item.per_cu->v.psymtab && !item.per_cu->v.psymtab->readin))
 	  /* Skip dummy CUs.  */
-	  && item->per_cu->cu != NULL)
+	  && item.per_cu->cu != NULL)
 	{
-	  struct dwarf2_per_cu_data *per_cu = item->per_cu;
+	  struct dwarf2_per_cu_data *per_cu = item.per_cu;
 	  unsigned int debug_print_threshold;
 	  char buf[100];
 
@@ -9302,21 +9281,18 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
 	    fprintf_unfiltered (gdb_stdlog, "Expanding symtab of %s\n", buf);
 
 	  if (per_cu->is_debug_types)
-	    process_full_type_unit (per_cu, item->pretend_language);
+	    process_full_type_unit (per_cu, item.pretend_language);
 	  else
-	    process_full_comp_unit (per_cu, item->pretend_language);
+	    process_full_comp_unit (per_cu, item.pretend_language);
 
 	  if (dwarf_read_debug >= debug_print_threshold)
 	    fprintf_unfiltered (gdb_stdlog, "Done expanding %s\n", buf);
 	}
 
-      item->per_cu->queued = 0;
-      next_item = item->next;
-      xfree (item);
+      item.per_cu->queued = 0;
+      dwarf2_per_objfile->queue.pop ();
     }
 
-  dwarf2_queue_tail = NULL;
-
   if (dwarf_read_debug)
     {
       fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n",
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 9752abc5e4c..9c671806479 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -20,6 +20,7 @@
 #ifndef DWARF2READ_H
 #define DWARF2READ_H
 
+#include <queue>
 #include <unordered_map>
 #include "dwarf2/index-cache.h"
 #include "dwarf2/section.h"
@@ -43,10 +44,29 @@ struct tu_stats
 };
 
 struct dwarf2_debug_sections;
+struct dwarf2_per_cu_data;
 struct mapped_index;
 struct mapped_debug_names;
 struct signatured_type;
 
+/* One item on the queue of compilation units to read in full symbols
+   for.  */
+struct dwarf2_queue_item
+{
+  dwarf2_queue_item (dwarf2_per_cu_data *cu, enum language lang)
+    : per_cu (cu),
+      pretend_language (lang)
+  {
+  }
+
+  ~dwarf2_queue_item ();
+
+  DISABLE_COPY_AND_ASSIGN (dwarf2_queue_item);
+
+  struct dwarf2_per_cu_data *per_cu;
+  enum language pretend_language;
+};
+
 /* Collection of data recorded per objfile.
    This hangs off of dwarf2_objfile_data_key.  */
 
@@ -214,6 +234,9 @@ public:
   std::unordered_map<sect_offset, std::vector<sect_offset>,
 		     gdb::hash_enum<sect_offset>>
     abstract_to_concrete;
+
+  /* CUs that are queued to be read.  */
+  std::queue<dwarf2_queue_item> queue;
 };
 
 /* Get the dwarf2_per_objfile associated to OBJFILE.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 00/38] Start reorganization of DWARF code
@ 2020-01-23  0:57 Tom Tromey
  2020-01-23  0:57 ` [PATCH 35/38] Convert read_address to a method on comp_unit_head Tom Tromey
                   ` (38 more replies)
  0 siblings, 39 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches

Most of the DWARF-related code in gdb is in one file, dwarf2read.c --
the single largest source file in gdb proper (I didn't check the
libraries).  As a consequence it is disorganized.

I've thought for a while that dwarf2read.c should be split up, and
this series is the start of this project.  This series does several
things:

* Splits some code out of dwarf2read.c into new files;
* In one or two cases, unifies code that is duplicated;
* Moves all the DWARF-related code to a subdirectory;
* Cleans up various APIs in small ways (like turning functions into
  methods on the appropriate class);
* Fixes a few minor bugs (I got distracted mid-series by moving hash
  tables off the objfile obstack, a gdb practice that's bothered me
  for years).

This series only shrinks dwarf2read.c from 26279 lines to 24744.  So,
there's clearly still much more to do.  The line number program state
machine or the macro-reading code seem like good candidates for
splitting out.

Tested by the buildbot.

Tom


^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 30/38] Unify read_initial_length implementations
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (30 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 20/38] Minor cleanups in abbrev_table Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-27 13:31   ` Christian Biesinger via gdb-patches
  2020-01-23  0:57 ` [PATCH 09/38] Don't declare die_info in dwarf2read.h Tom Tromey
                   ` (6 subsequent siblings)
  38 siblings, 1 reply; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

There are two implementations of read_initial_length in gdb.  This
merges them and moves the resulting function to leb.c.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_initial_length): Move to leb.c.
	* dwarf2/leb.h (read_initial_length): Declare.
	* dwarf2/leb.c (read_initial_length): Move from read.c.  Add
	handle_nonstd parameter.
	* dwarf2/frame.c (read_initial_length): Remove.
	(decode_frame_entry_1): Update.

Change-Id: I34d37bad0f8a584bfa781432cba25e05e1bd5750
---
 gdb/ChangeLog      |  9 +++++++
 gdb/dwarf2/frame.c | 20 +--------------
 gdb/dwarf2/leb.c   | 27 +++++++++++++++++++
 gdb/dwarf2/leb.h   | 41 +++++++++++++++++++++++++++++
 gdb/dwarf2/read.c  | 64 ----------------------------------------------
 5 files changed, 78 insertions(+), 83 deletions(-)

diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c
index 7f57c28be2c..2d928670c6b 100644
--- a/gdb/dwarf2/frame.c
+++ b/gdb/dwarf2/frame.c
@@ -1475,24 +1475,6 @@ const struct objfile_key<dwarf2_fde_table,
 			 gdb::noop_deleter<dwarf2_fde_table>>
   dwarf2_frame_objfile_data;
 
-
-static ULONGEST
-read_initial_length (bfd *abfd, const gdb_byte *buf,
-		     unsigned int *bytes_read_ptr)
-{
-  ULONGEST result;
-
-  result = bfd_get_32 (abfd, buf);
-  if (result == 0xffffffff)
-    {
-      result = bfd_get_64 (abfd, buf + 4);
-      *bytes_read_ptr = 12;
-    }
-  else
-    *bytes_read_ptr = 4;
-
-  return result;
-}
 \f
 
 /* Pointer encoding helper functions.  */
@@ -1744,7 +1726,7 @@ decode_frame_entry_1 (struct comp_unit *unit, const gdb_byte *start,
   uint64_t uleb128;
 
   buf = start;
-  length = read_initial_length (unit->abfd, buf, &bytes_read);
+  length = read_initial_length (unit->abfd, buf, &bytes_read, false);
   buf += bytes_read;
   end = buf + (size_t) length;
 
diff --git a/gdb/dwarf2/leb.c b/gdb/dwarf2/leb.c
index d26b48b381c..ef7314ed2b3 100644
--- a/gdb/dwarf2/leb.c
+++ b/gdb/dwarf2/leb.c
@@ -83,3 +83,30 @@ read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
   *bytes_read_ptr = num_read;
   return result;
 }
+
+/* See leb.h.  */
+
+LONGEST
+read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read,
+		     bool handle_nonstd)
+{
+  LONGEST length = bfd_get_32 (abfd, buf);
+
+  if (length == 0xffffffff)
+    {
+      length = bfd_get_64 (abfd, buf + 4);
+      *bytes_read = 12;
+    }
+  else if (handle_nonstd && length == 0)
+    {
+      /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX.  */
+      length = bfd_get_64 (abfd, buf);
+      *bytes_read = 8;
+    }
+  else
+    {
+      *bytes_read = 4;
+    }
+
+  return length;
+}
diff --git a/gdb/dwarf2/leb.h b/gdb/dwarf2/leb.h
index b17ab881ba2..29fdffebfec 100644
--- a/gdb/dwarf2/leb.h
+++ b/gdb/dwarf2/leb.h
@@ -89,4 +89,45 @@ extern LONGEST read_signed_leb128 (bfd *, const gdb_byte *, unsigned int *);
 
 extern ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
 
+/* Read the initial length from a section.  The (draft) DWARF 3
+   specification allows the initial length to take up either 4 bytes
+   or 12 bytes.  If the first 4 bytes are 0xffffffff, then the next 8
+   bytes describe the length and all offsets will be 8 bytes in length
+   instead of 4.
+
+   An older, non-standard 64-bit format is also handled by this
+   function.  The older format in question stores the initial length
+   as an 8-byte quantity without an escape value.  Lengths greater
+   than 2^32 aren't very common which means that the initial 4 bytes
+   is almost always zero.  Since a length value of zero doesn't make
+   sense for the 32-bit format, this initial zero can be considered to
+   be an escape value which indicates the presence of the older 64-bit
+   format.  As written, the code can't detect (old format) lengths
+   greater than 4GB.  If it becomes necessary to handle lengths
+   somewhat larger than 4GB, we could allow other small values (such
+   as the non-sensical values of 1, 2, and 3) to also be used as
+   escape values indicating the presence of the old format.
+
+   The value returned via bytes_read should be used to increment the
+   relevant pointer after calling read_initial_length().
+
+   [ Note:  read_initial_length() and read_offset() are based on the
+     document entitled "DWARF Debugging Information Format", revision
+     3, draft 8, dated November 19, 2001.  This document was obtained
+     from:
+
+	http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
+
+     This document is only a draft and is subject to change.  (So beware.)
+
+     Details regarding the older, non-standard 64-bit format were
+     determined empirically by examining 64-bit ELF files produced by
+     the SGI toolchain on an IRIX 6.5 machine.
+
+     - Kevin, July 16, 2002
+   ] */
+extern LONGEST read_initial_length (bfd *abfd, const gdb_byte *buf,
+				    unsigned int *bytes_read,
+				    bool handle_nonstd = true);
+
 #endif /* GDB_DWARF2_LEB_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index f0d39ddb7f8..65e39b22b4f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1282,8 +1282,6 @@ static CORE_ADDR read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index)
 static CORE_ADDR read_address (bfd *, const gdb_byte *ptr, struct dwarf2_cu *,
 			       unsigned int *);
 
-static LONGEST read_initial_length (bfd *, const gdb_byte *, unsigned int *);
-
 static LONGEST read_checked_initial_length_and_offset
   (bfd *, const gdb_byte *, const struct comp_unit_head *,
    unsigned int *, unsigned int *);
@@ -19061,68 +19059,6 @@ read_address (bfd *abfd, const gdb_byte *buf, struct dwarf2_cu *cu,
   return retval;
 }
 
-/* Read the initial length from a section.  The (draft) DWARF 3
-   specification allows the initial length to take up either 4 bytes
-   or 12 bytes.  If the first 4 bytes are 0xffffffff, then the next 8
-   bytes describe the length and all offsets will be 8 bytes in length
-   instead of 4.
-
-   An older, non-standard 64-bit format is also handled by this
-   function.  The older format in question stores the initial length
-   as an 8-byte quantity without an escape value.  Lengths greater
-   than 2^32 aren't very common which means that the initial 4 bytes
-   is almost always zero.  Since a length value of zero doesn't make
-   sense for the 32-bit format, this initial zero can be considered to
-   be an escape value which indicates the presence of the older 64-bit
-   format.  As written, the code can't detect (old format) lengths
-   greater than 4GB.  If it becomes necessary to handle lengths
-   somewhat larger than 4GB, we could allow other small values (such
-   as the non-sensical values of 1, 2, and 3) to also be used as
-   escape values indicating the presence of the old format.
-
-   The value returned via bytes_read should be used to increment the
-   relevant pointer after calling read_initial_length().
-
-   [ Note:  read_initial_length() and read_offset() are based on the
-     document entitled "DWARF Debugging Information Format", revision
-     3, draft 8, dated November 19, 2001.  This document was obtained
-     from:
-
-	http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
-
-     This document is only a draft and is subject to change.  (So beware.)
-
-     Details regarding the older, non-standard 64-bit format were
-     determined empirically by examining 64-bit ELF files produced by
-     the SGI toolchain on an IRIX 6.5 machine.
-
-     - Kevin, July 16, 2002
-   ] */
-
-static LONGEST
-read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read)
-{
-  LONGEST length = bfd_get_32 (abfd, buf);
-
-  if (length == 0xffffffff)
-    {
-      length = bfd_get_64 (abfd, buf + 4);
-      *bytes_read = 12;
-    }
-  else if (length == 0)
-    {
-      /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX.  */
-      length = bfd_get_64 (abfd, buf);
-      *bytes_read = 8;
-    }
-  else
-    {
-      *bytes_read = 4;
-    }
-
-  return length;
-}
-
 /* 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
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 09/38] Don't declare die_info in dwarf2read.h
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (31 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 30/38] Unify read_initial_length implementations Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 24/38] Move dwarf_always_disassemble to dwarf2/loc.c Tom Tromey
                   ` (5 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

There's no need to forward-declare struct die_info in dwarf2read.h.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (struct die_info): Don't declare.

Change-Id: I0b8dbf99558b9547d418cfd8ef387a21f7dfa660
---
 gdb/ChangeLog    | 4 ++++
 gdb/dwarf2read.h | 1 -
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 79e618e0a37..a2228200257 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -46,7 +46,6 @@ struct dwarf2_debug_sections;
 struct mapped_index;
 struct mapped_debug_names;
 struct signatured_type;
-struct die_info;
 
 /* Collection of data recorded per objfile.
    This hangs off of dwarf2_objfile_data_key.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 24/38] Move dwarf_always_disassemble to dwarf2/loc.c
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (32 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 09/38] Don't declare die_info in dwarf2read.h Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 17/38] Don't allocate DWO file hash on obstack Tom Tromey
                   ` (4 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

dwarf_always_disassemble is only used in dwarf2/loc.c, so move the
definition and the command infrastructure to that file.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf_always_disassemble)
	(show_dwarf_always_disassemble): Move to loc.c.
	(_initialize_dwarf2_read): Move "always-disassemble" registration
	to loc.c.
	* dwarf2/read.h (dwarf_always_disassemble): Don't declare.
	* dwarf2/loc.c (dwarf_always_disassemble): Move from read.c.  Now
	static.
	(show_dwarf_always_disassemble): Move from read.c.
	(_initialize_dwarf2loc): Move always-disassemble from read.c.

Change-Id: I33fb88112e98e583c3f4919d20e4d100f2ea0124
---
 gdb/ChangeLog     | 12 ++++++++++++
 gdb/dwarf2/loc.c  | 24 ++++++++++++++++++++++++
 gdb/dwarf2/read.c | 24 ------------------------
 gdb/dwarf2/read.h |  2 --
 4 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 03333602820..e337a02d473 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -4177,6 +4177,18 @@ disassemble_dwarf_expression (struct ui_file *stream,
   return data;
 }
 
+static bool dwarf_always_disassemble;
+
+static void
+show_dwarf_always_disassemble (struct ui_file *file, int from_tty,
+			       struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file,
+		    _("Whether to always disassemble "
+		      "DWARF expressions is %s.\n"),
+		    value);
+}
+
 /* Describe a single location, which may in turn consist of multiple
    pieces.  */
 
@@ -4570,4 +4582,16 @@ _initialize_dwarf2loc ()
 			     NULL,
 			     show_entry_values_debug,
 			     &setdebuglist, &showdebuglist);
+
+  add_setshow_boolean_cmd ("always-disassemble", class_obscure,
+			   &dwarf_always_disassemble, _("\
+Set whether `info address' always disassembles DWARF expressions."), _("\
+Show whether `info address' always disassembles DWARF expressions."), _("\
+When enabled, DWARF expressions are always printed in an assembly-like\n\
+syntax.  When disabled, expressions will be printed in a more\n\
+conversational style, when possible."),
+			   NULL,
+			   show_dwarf_always_disassemble,
+			   &set_dwarf_cmdlist,
+			   &show_dwarf_cmdlist);
 }
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7c59db56e22..c230778980e 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -25390,18 +25390,6 @@ show_dwarf_cmd (const char *args, int from_tty)
   cmd_show_list (show_dwarf_cmdlist, from_tty, "");
 }
 
-bool dwarf_always_disassemble;
-
-static void
-show_dwarf_always_disassemble (struct ui_file *file, int from_tty,
-			       struct cmd_list_element *c, const char *value)
-{
-  fprintf_filtered (file,
-		    _("Whether to always disassemble "
-		      "DWARF expressions is %s.\n"),
-		    value);
-}
-
 static void
 show_check_physname (struct ui_file *file, int from_tty,
 		     struct cmd_list_element *c, const char *value)
@@ -25439,18 +25427,6 @@ caching, which can slow down startup."),
 			    &set_dwarf_cmdlist,
 			    &show_dwarf_cmdlist);
 
-  add_setshow_boolean_cmd ("always-disassemble", class_obscure,
-			   &dwarf_always_disassemble, _("\
-Set whether `info address' always disassembles DWARF expressions."), _("\
-Show whether `info address' always disassembles DWARF expressions."), _("\
-When enabled, DWARF expressions are always printed in an assembly-like\n\
-syntax.  When disabled, expressions will be printed in a more\n\
-conversational style, when possible."),
-			   NULL,
-			   show_dwarf_always_disassemble,
-			   &set_dwarf_cmdlist,
-			   &show_dwarf_cmdlist);
-
   add_setshow_zuinteger_cmd ("dwarf-read", no_class, &dwarf_read_debug, _("\
 Set debugging of the DWARF reader."), _("\
 Show debugging of the DWARF reader."), _("\
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index c3a53f65fe7..b9d185d691c 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -32,8 +32,6 @@
 extern struct cmd_list_element *set_dwarf_cmdlist;
 extern struct cmd_list_element *show_dwarf_cmdlist;
 
-extern bool dwarf_always_disassemble;
-
 struct tu_stats
 {
   int nr_uniq_abbrev_tables;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 16/38] Change dwarf2_per_objfile::line_header_hash to htab_up
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
  2020-01-23  0:57 ` [PATCH 35/38] Convert read_address to a method on comp_unit_head Tom Tromey
  2020-01-23  0:57 ` [PATCH 07/38] Change attr_form_is_block to be a method Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 31/38] Convert dwarf2_section_size to a method Tom Tromey
                   ` (35 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes dwarf2_per_objfile::line_header_hash to be an htab_up,
and changes it to use heap allocation.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (~dwarf2_per_objfile): Don't delete
	line_header_hash.
	(handle_DW_AT_stmt_list): Update.  Don't allocate on obstack.
	* dwarf2/read.h (struct dwarf2_per_objfile) <line_header_hash>:
	Change type to htab_up.

Change-Id: Icb148a270838c0f96f38fc4a28b5b77d067927b6
---
 gdb/ChangeLog     |  8 ++++++++
 gdb/dwarf2/read.c | 18 ++++++------------
 gdb/dwarf2/read.h |  2 +-
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 17f2640d0d4..844ff8dc54b 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2019,9 +2019,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
   if (quick_file_names_table)
     htab_delete (quick_file_names_table);
 
-  if (line_header_hash)
-    htab_delete (line_header_hash);
-
   for (dwarf2_per_cu_data *per_cu : all_comp_units)
     per_cu->imported_symtabs_free ();
 
@@ -11104,7 +11101,6 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
 {
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = cu->per_cu->dwarf2_per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct attribute *attr;
   struct line_header line_header_local;
   hashval_t line_header_local_hash;
@@ -11129,12 +11125,10 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
       && die->tag == DW_TAG_partial_unit)
     {
       dwarf2_per_objfile->line_header_hash
-	= htab_create_alloc_ex (127, line_header_hash_voidp,
-				line_header_eq_voidp,
-				free_line_header_voidp,
-				&objfile->objfile_obstack,
-				hashtab_obstack_allocate,
-				dummy_obstack_deallocate);
+	.reset (htab_create_alloc (127, line_header_hash_voidp,
+				   line_header_eq_voidp,
+				   free_line_header_voidp,
+				   xcalloc, xfree));
     }
 
   line_header_local.sect_off = line_offset;
@@ -11142,7 +11136,7 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
   line_header_local_hash = line_header_hash (&line_header_local);
   if (dwarf2_per_objfile->line_header_hash != NULL)
     {
-      slot = htab_find_slot_with_hash (dwarf2_per_objfile->line_header_hash,
+      slot = htab_find_slot_with_hash (dwarf2_per_objfile->line_header_hash.get (),
 				       &line_header_local,
 				       line_header_local_hash, NO_INSERT);
 
@@ -11170,7 +11164,7 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
     slot = NULL;
   else
     {
-      slot = htab_find_slot_with_hash (dwarf2_per_objfile->line_header_hash,
+      slot = htab_find_slot_with_hash (dwarf2_per_objfile->line_header_hash.get (),
 				       &line_header_local,
 				       line_header_local_hash, INSERT);
       gdb_assert (slot != NULL);
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 9787127f99e..91d5c58faa0 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -219,7 +219,7 @@ public:
   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 {};
+  htab_up line_header_hash;
 
   /* Table containing all filenames.  This is an optional because the
      table is lazily constructed on first access.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 05/38] Create dwarf2/attribute.[ch]
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (6 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 38/38] Remove "keep" parameter from cutu_reader constructor Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 32/38] Move read_offset_1 to leb.c Tom Tromey
                   ` (30 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves the attribute-related code out of dwarf2read.c and into the
new files dwarf2/attribute.[ch].

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct attribute, DW_STRING)
	(DW_STRING_IS_CANONICAL, DW_UNSND, DW_BLOCK, DW_SND, DW_ADDR)
	(DW_SIGNATURE, struct dwarf_block, attr_value_as_address)
	(attr_form_is_block, attr_form_is_section_offset)
	(attr_form_is_constant, attr_form_is_ref): Move.
	* dwarf2/attribute.h: New file.
	* dwarf2/attribute.c: New file, from dwarf2read.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/attribute.c.

Change-Id: I1ea4c146256a1b9e38b66f1c605d782a14eeded7
---
 gdb/ChangeLog          |  11 +++
 gdb/Makefile.in        |   1 +
 gdb/dwarf2/attribute.c | 122 +++++++++++++++++++++++++++++
 gdb/dwarf2/attribute.h | 118 ++++++++++++++++++++++++++++
 gdb/dwarf2read.c       | 169 +----------------------------------------
 5 files changed, 253 insertions(+), 168 deletions(-)
 create mode 100644 gdb/dwarf2/attribute.c
 create mode 100644 gdb/dwarf2/attribute.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 2188d32c4e6..e652e4f971a 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1003,6 +1003,7 @@ COMMON_SFILES = \
 	dwarf2loc.c \
 	dwarf2read.c \
 	dwarf2/abbrev.c \
+	dwarf2/attribute.c \
 	dwarf2/leb.c \
 	dwarf2/section.c \
 	eval.c \
diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
new file mode 100644
index 00000000000..75a2fa3774b
--- /dev/null
+++ b/gdb/dwarf2/attribute.c
@@ -0,0 +1,122 @@
+/* DWARF attributes
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "dwarf2/attribute.h"
+
+/* See attribute.h.  */
+
+CORE_ADDR
+attr_value_as_address (struct attribute *attr)
+{
+  CORE_ADDR addr;
+
+  if (attr->form != DW_FORM_addr && attr->form != DW_FORM_addrx
+      && attr->form != DW_FORM_GNU_addr_index)
+    {
+      /* Aside from a few clearly defined exceptions, attributes that
+	 contain an address must always be in DW_FORM_addr form.
+	 Unfortunately, some compilers happen to be violating this
+	 requirement by encoding addresses using other forms, such
+	 as DW_FORM_data4 for example.  For those broken compilers,
+	 we try to do our best, without any guarantee of success,
+	 to interpret the address correctly.  It would also be nice
+	 to generate a complaint, but that would require us to maintain
+	 a list of legitimate cases where a non-address form is allowed,
+	 as well as update callers to pass in at least the CU's DWARF
+	 version.  This is more overhead than what we're willing to
+	 expand for a pretty rare case.  */
+      addr = DW_UNSND (attr);
+    }
+  else
+    addr = DW_ADDR (attr);
+
+  return addr;
+}
+
+/* See attribute.h.  */
+
+int
+attr_form_is_block (const struct attribute *attr)
+{
+  return (attr == NULL ? 0 :
+      attr->form == DW_FORM_block1
+      || attr->form == DW_FORM_block2
+      || attr->form == DW_FORM_block4
+      || attr->form == DW_FORM_block
+      || attr->form == DW_FORM_exprloc);
+}
+
+/* See attribute.h.  */
+
+int
+attr_form_is_section_offset (const struct attribute *attr)
+{
+  return (attr->form == DW_FORM_data4
+          || attr->form == DW_FORM_data8
+	  || attr->form == DW_FORM_sec_offset);
+}
+
+/* See attribute.h.  */
+
+int
+attr_form_is_constant (const struct attribute *attr)
+{
+  switch (attr->form)
+    {
+    case DW_FORM_sdata:
+    case DW_FORM_udata:
+    case DW_FORM_data1:
+    case DW_FORM_data2:
+    case DW_FORM_data4:
+    case DW_FORM_data8:
+    case DW_FORM_implicit_const:
+      return 1;
+    default:
+      return 0;
+    }
+}
+
+/* DW_ADDR is always stored already as sect_offset; despite for the forms
+   besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file.  */
+
+int
+attr_form_is_ref (const struct attribute *attr)
+{
+  switch (attr->form)
+    {
+    case DW_FORM_ref_addr:
+    case DW_FORM_ref1:
+    case DW_FORM_ref2:
+    case DW_FORM_ref4:
+    case DW_FORM_ref8:
+    case DW_FORM_ref_udata:
+    case DW_FORM_GNU_ref_alt:
+      return 1;
+    default:
+      return 0;
+    }
+}
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
new file mode 100644
index 00000000000..11c6cb929d9
--- /dev/null
+++ b/gdb/dwarf2/attribute.h
@@ -0,0 +1,118 @@
+/* DWARF attributes
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_DWARF2_ATTRIBUTE_H
+#define GDB_DWARF2_ATTRIBUTE_H
+
+#include "dwarf2.h"
+
+/* Blocks are a bunch of untyped bytes.  */
+struct dwarf_block
+{
+  size_t size;
+
+  /* Valid only if SIZE is not zero.  */
+  const gdb_byte *data;
+};
+
+/* Attributes have a name and a value.  */
+struct attribute
+{
+  ENUM_BITFIELD(dwarf_attribute) name : 16;
+  ENUM_BITFIELD(dwarf_form) form : 15;
+
+  /* Has DW_STRING already been updated by dwarf2_canonicalize_name?  This
+     field should be in u.str (existing only for DW_STRING) but it is kept
+     here for better struct attribute alignment.  */
+  unsigned int string_is_canonical : 1;
+
+  union
+    {
+      const char *str;
+      struct dwarf_block *blk;
+      ULONGEST unsnd;
+      LONGEST snd;
+      CORE_ADDR addr;
+      ULONGEST signature;
+    }
+  u;
+};
+
+/* Get at parts of an attribute structure.  */
+
+#define DW_STRING(attr)    ((attr)->u.str)
+#define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
+#define DW_UNSND(attr)     ((attr)->u.unsnd)
+#define DW_BLOCK(attr)     ((attr)->u.blk)
+#define DW_SND(attr)       ((attr)->u.snd)
+#define DW_ADDR(attr)	   ((attr)->u.addr)
+#define DW_SIGNATURE(attr) ((attr)->u.signature)
+
+/* Read the given attribute value as an address, taking the attribute's
+   form into account.  */
+
+extern CORE_ADDR attr_value_as_address (struct attribute *attr);
+
+/* Check if the attribute's form is a DW_FORM_block*
+   if so return true else false.  */
+
+extern int attr_form_is_block (const struct attribute *attr);
+
+/* Return non-zero if ATTR's value is a section offset --- classes
+   lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
+   You may use DW_UNSND (attr) to retrieve such offsets.
+
+   Section 7.5.4, "Attribute Encodings", explains that no attribute
+   may have a value that belongs to more than one of these classes; it
+   would be ambiguous if we did, because we use the same forms for all
+   of them.  */
+
+extern int attr_form_is_section_offset (const struct attribute *attr);
+
+/* Return non-zero if ATTR's value falls in the 'constant' class, or
+   zero otherwise.  When this function returns true, you can apply
+   dwarf2_get_attr_constant_value to it.
+
+   However, note that for some attributes you must check
+   attr_form_is_section_offset before using this test.  DW_FORM_data4
+   and DW_FORM_data8 are members of both the constant class, and of
+   the classes that contain offsets into other debug sections
+   (lineptr, loclistptr, macptr or rangelistptr).  The DWARF spec says
+   that, if an attribute's can be either a constant or one of the
+   section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
+   taken as section offsets, not constants.
+
+   DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
+   cannot handle that.  */
+
+extern int attr_form_is_constant (const struct attribute *attr);
+
+/* DW_ADDR is always stored already as sect_offset; despite for the forms
+   besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file.  */
+
+extern int attr_form_is_ref (const struct attribute *attr);
+
+#endif /* GDB_DWARF2_ATTRIBUTE_H */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 886bec1d7aa..5b77e397899 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -31,6 +31,7 @@
 #include "defs.h"
 #include "dwarf2read.h"
 #include "dwarf2/abbrev.h"
+#include "dwarf2/attribute.h"
 #include "dwarf-index-cache.h"
 #include "dwarf-index-common.h"
 #include "dwarf2/leb.h"
@@ -1233,29 +1234,6 @@ struct partial_die_info : public allocate_on_obstack
     }
   };
 
-/* Attributes have a name and a value.  */
-struct attribute
-  {
-    ENUM_BITFIELD(dwarf_attribute) name : 16;
-    ENUM_BITFIELD(dwarf_form) form : 15;
-
-    /* Has DW_STRING already been updated by dwarf2_canonicalize_name?  This
-       field should be in u.str (existing only for DW_STRING) but it is kept
-       here for better struct attribute alignment.  */
-    unsigned int string_is_canonical : 1;
-
-    union
-      {
-	const char *str;
-	struct dwarf_block *blk;
-	ULONGEST unsnd;
-	LONGEST snd;
-	CORE_ADDR addr;
-	ULONGEST signature;
-      }
-    u;
-  };
-
 /* This data structure holds a complete die structure.  */
 struct die_info
   {
@@ -1292,25 +1270,6 @@ struct die_info
     struct attribute attrs[1];
   };
 
-/* Get at parts of an attribute structure.  */
-
-#define DW_STRING(attr)    ((attr)->u.str)
-#define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical)
-#define DW_UNSND(attr)     ((attr)->u.unsnd)
-#define DW_BLOCK(attr)     ((attr)->u.blk)
-#define DW_SND(attr)       ((attr)->u.snd)
-#define DW_ADDR(attr)	   ((attr)->u.addr)
-#define DW_SIGNATURE(attr) ((attr)->u.signature)
-
-/* Blocks are a bunch of untyped bytes.  */
-struct dwarf_block
-  {
-    size_t size;
-
-    /* Valid only if SIZE is not zero.  */
-    const gdb_byte *data;
-  };
-
 /* 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.  */
@@ -1785,14 +1744,6 @@ static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int);
 
 static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int, int);
 
-static int attr_form_is_block (const struct attribute *);
-
-static int attr_form_is_section_offset (const struct attribute *);
-
-static int attr_form_is_constant (const struct attribute *);
-
-static int attr_form_is_ref (const struct attribute *);
-
 static void fill_in_loclist_baton (struct dwarf2_cu *cu,
 				   struct dwarf2_loclist_baton *baton,
 				   const struct attribute *attr);
@@ -2055,37 +2006,6 @@ line_header_eq_voidp (const void *item_lhs, const void *item_rhs)
 
 \f
 
-/* Read the given attribute value as an address, taking the attribute's
-   form into account.  */
-
-static CORE_ADDR
-attr_value_as_address (struct attribute *attr)
-{
-  CORE_ADDR addr;
-
-  if (attr->form != DW_FORM_addr && attr->form != DW_FORM_addrx
-      && attr->form != DW_FORM_GNU_addr_index)
-    {
-      /* Aside from a few clearly defined exceptions, attributes that
-	 contain an address must always be in DW_FORM_addr form.
-	 Unfortunately, some compilers happen to be violating this
-	 requirement by encoding addresses using other forms, such
-	 as DW_FORM_data4 for example.  For those broken compilers,
-	 we try to do our best, without any guarantee of success,
-	 to interpret the address correctly.  It would also be nice
-	 to generate a complaint, but that would require us to maintain
-	 a list of legitimate cases where a non-address form is allowed,
-	 as well as update callers to pass in at least the CU's DWARF
-	 version.  This is more overhead than what we're willing to
-	 expand for a pretty rare case.  */
-      addr = DW_UNSND (attr);
-    }
-  else
-    addr = DW_ADDR (attr);
-
-  return addr;
-}
-
 /* See declaration.  */
 
 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile *objfile_,
@@ -24857,93 +24777,6 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
 			    include_hash.get ());
 }
 
-/* Check if the attribute's form is a DW_FORM_block*
-   if so return true else false.  */
-
-static int
-attr_form_is_block (const struct attribute *attr)
-{
-  return (attr == NULL ? 0 :
-      attr->form == DW_FORM_block1
-      || attr->form == DW_FORM_block2
-      || attr->form == DW_FORM_block4
-      || attr->form == DW_FORM_block
-      || attr->form == DW_FORM_exprloc);
-}
-
-/* Return non-zero if ATTR's value is a section offset --- classes
-   lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
-   You may use DW_UNSND (attr) to retrieve such offsets.
-
-   Section 7.5.4, "Attribute Encodings", explains that no attribute
-   may have a value that belongs to more than one of these classes; it
-   would be ambiguous if we did, because we use the same forms for all
-   of them.  */
-
-static int
-attr_form_is_section_offset (const struct attribute *attr)
-{
-  return (attr->form == DW_FORM_data4
-          || attr->form == DW_FORM_data8
-	  || attr->form == DW_FORM_sec_offset);
-}
-
-/* Return non-zero if ATTR's value falls in the 'constant' class, or
-   zero otherwise.  When this function returns true, you can apply
-   dwarf2_get_attr_constant_value to it.
-
-   However, note that for some attributes you must check
-   attr_form_is_section_offset before using this test.  DW_FORM_data4
-   and DW_FORM_data8 are members of both the constant class, and of
-   the classes that contain offsets into other debug sections
-   (lineptr, loclistptr, macptr or rangelistptr).  The DWARF spec says
-   that, if an attribute's can be either a constant or one of the
-   section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
-   taken as section offsets, not constants.
-
-   DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
-   cannot handle that.  */
-
-static int
-attr_form_is_constant (const struct attribute *attr)
-{
-  switch (attr->form)
-    {
-    case DW_FORM_sdata:
-    case DW_FORM_udata:
-    case DW_FORM_data1:
-    case DW_FORM_data2:
-    case DW_FORM_data4:
-    case DW_FORM_data8:
-    case DW_FORM_implicit_const:
-      return 1;
-    default:
-      return 0;
-    }
-}
-
-
-/* DW_ADDR is always stored already as sect_offset; despite for the forms
-   besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file.  */
-
-static int
-attr_form_is_ref (const struct attribute *attr)
-{
-  switch (attr->form)
-    {
-    case DW_FORM_ref_addr:
-    case DW_FORM_ref1:
-    case DW_FORM_ref2:
-    case DW_FORM_ref4:
-    case DW_FORM_ref8:
-    case DW_FORM_ref_udata:
-    case DW_FORM_GNU_ref_alt:
-      return 1;
-    default:
-      return 0;
-    }
-}
-
 /* Return the .debug_loc section to use for CU.
    For DWO files use .debug_loc.dwo.  */
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 21/38] Use htab_up in abbrev_table
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (12 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 34/38] Convert read_offset to method on comp_unit_head Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 36/38] Move two more functions to dwarf2/leb.h Tom Tromey
                   ` (24 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes abbrev_table to use an htab_up rather than an ad hoc,
bucket-based hash table.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/abbrev.c (abbrev_table): Move constructor from header.
	Rewrite.
	(abbrev_table::add_abbrev, abbrev_table::lookup_abbrev): Rewrite.
	* dwarf2/abbrev.h (struct abbrev_info) <next>: Remove.
	(abbrev_table::abbrev_table): No longer inline.
	(ABBREV_HASH_SIZE): Remove.
	(abbrev_table::m_abbrevs): Now an htab_up.

Change-Id: Icbaa8e49501f9c43218d6a81a7e8c4d3a77d65dc
---
 gdb/ChangeLog       | 10 ++++++++++
 gdb/dwarf2/abbrev.c | 48 +++++++++++++++++++++++++++++----------------
 gdb/dwarf2/abbrev.h | 19 +++---------------
 3 files changed, 44 insertions(+), 33 deletions(-)

diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index fac7309b93c..f843e32d950 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -30,6 +30,25 @@
 #include "dwarf2/leb.h"
 #include "bfd.h"
 
+/* Hash function for an abbrev.  */
+
+static hashval_t
+hash_abbrev (const void *item)
+{
+  const struct abbrev_info *info = (const struct abbrev_info *) item;
+  return info->number;
+}
+
+/* Comparison function for abbrevs.  */
+
+static int
+eq_abbrev (const void *lhs, const void *rhs)
+{
+  const struct abbrev_info *l_info = (const struct abbrev_info *) lhs;
+  const struct abbrev_info *r_info = (const struct abbrev_info *) rhs;
+  return l_info->number == r_info->number;
+}
+
 /* Abbreviation tables.
 
    In DWARF version 2, the description of the debugging information is
@@ -37,6 +56,13 @@
    dies from a section we read in all abbreviations and install them
    in a hash table.  */
 
+abbrev_table::abbrev_table (sect_offset off)
+  : sect_off (off),
+    m_abbrevs (htab_create_alloc (20, hash_abbrev, eq_abbrev,
+				  nullptr, xcalloc, xfree))
+{
+}
+
 /* Allocate space for a struct abbrev_info object in ABBREV_TABLE.  */
 
 struct abbrev_info *
@@ -56,11 +82,8 @@ void
 abbrev_table::add_abbrev (unsigned int abbrev_number,
 			  struct abbrev_info *abbrev)
 {
-  unsigned int hash_number;
-
-  hash_number = abbrev_number % ABBREV_HASH_SIZE;
-  abbrev->next = m_abbrevs[hash_number];
-  m_abbrevs[hash_number] = abbrev;
+  void **slot = htab_find_slot (m_abbrevs.get (), abbrev, INSERT);
+  *slot = abbrev;
 }
 
 /* Look up an abbrev in the table.
@@ -69,19 +92,10 @@ abbrev_table::add_abbrev (unsigned int abbrev_number,
 struct abbrev_info *
 abbrev_table::lookup_abbrev (unsigned int abbrev_number)
 {
-  unsigned int hash_number;
-  struct abbrev_info *abbrev;
-
-  hash_number = abbrev_number % ABBREV_HASH_SIZE;
-  abbrev = m_abbrevs[hash_number];
+  struct abbrev_info search;
+  search.number = abbrev_number;
 
-  while (abbrev)
-    {
-      if (abbrev->number == abbrev_number)
-	return abbrev;
-      abbrev = abbrev->next;
-    }
-  return NULL;
+  return (struct abbrev_info *) htab_find (m_abbrevs.get (), &search);
 }
 
 /* Read in an abbrev table.  */
diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h
index 52103b0a683..b9ace64b448 100644
--- a/gdb/dwarf2/abbrev.h
+++ b/gdb/dwarf2/abbrev.h
@@ -35,7 +35,6 @@ struct abbrev_info
     unsigned short has_children;		/* boolean */
     unsigned short num_attrs;	/* number of attributes */
     struct attr_abbrev *attrs;	/* an array of attribute descriptions */
-    struct abbrev_info *next;	/* next in chain */
   };
 
 struct attr_abbrev
@@ -47,9 +46,6 @@ struct attr_abbrev
     LONGEST implicit_const;
   };
 
-/* Size of abbrev_table.abbrev_hash_table.  */
-#define ABBREV_HASH_SIZE 121
-
 struct abbrev_table;
 typedef std::unique_ptr<struct abbrev_table> abbrev_table_up;
 
@@ -73,13 +69,7 @@ struct abbrev_table
 
 private:
 
-  explicit abbrev_table (sect_offset off)
-    : sect_off (off)
-  {
-    m_abbrevs =
-      XOBNEWVEC (&m_abbrev_obstack, struct abbrev_info *, ABBREV_HASH_SIZE);
-    memset (m_abbrevs, 0, ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
-  }
+  explicit abbrev_table (sect_offset off);
 
   DISABLE_COPY_AND_ASSIGN (abbrev_table);
 
@@ -90,11 +80,8 @@ private:
   /* Add an abbreviation to the table.  */
   void add_abbrev (unsigned int abbrev_number, struct abbrev_info *abbrev);
 
-  /* Hash table of abbrevs.
-     This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
-     It could be statically allocated, but the previous code didn't so we
-     don't either.  */
-  struct abbrev_info **m_abbrevs;
+  /* Hash table of abbrevs.  */
+  htab_up m_abbrevs;
 
   /* Storage for the abbrev table.  */
   auto_obstack m_abbrev_obstack;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 18/38] Change dwp_file to use htab_up
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (24 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 25/38] Change file_full_name and file_file_name methods Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 04/38] Create dwarf2/abbrev.[ch] Tom Tromey
                   ` (12 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes dwp_file to use htab_up for the loaded_cus and loaded_tus
members.  This lets us avoid allocating the contents of these hash
tables on the objfile obstack.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (struct dwp_file) <loaded_cus, loaded_tus>: Now
	htab_up.
	(lookup_dwo_unit_in_dwp): Update.
	(allocate_dwp_loaded_cutus_table): Return htab_up.  Don't allocate
	on obstack.

Change-Id: Id61209bf5c6c6faa0c067195af31fbcf26813a3a
---
 gdb/ChangeLog     |  8 ++++++++
 gdb/dwarf2/read.c | 21 +++++++++------------
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2f87b9d2a50..5becbd5ef9b 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -868,8 +868,8 @@ struct dwp_file
   const struct dwp_hash_table *tus = nullptr;
 
   /* Tables of loaded CUs/TUs.  Each entry is a struct dwo_unit *.  */
-  htab_t loaded_cus {};
-  htab_t loaded_tus {};
+  htab_up loaded_cus;
+  htab_up loaded_tus;
 
   /* Table to map ELF section numbers to their sections.
      This is only needed for the DWP V1 file format.  */
@@ -12395,8 +12395,8 @@ lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile *dwarf2_per_objfile,
   memset (&find_dwo_cu, 0, sizeof (find_dwo_cu));
   find_dwo_cu.signature = signature;
   slot = htab_find_slot (is_debug_types
-			 ? dwp_file->loaded_tus
-			 : dwp_file->loaded_cus,
+			 ? dwp_file->loaded_tus.get ()
+			 : dwp_file->loaded_cus.get (),
 			 &find_dwo_cu, INSERT);
 
   if (*slot != NULL)
@@ -12767,16 +12767,13 @@ eq_dwp_loaded_cutus (const void *a, const void *b)
 
 /* Allocate a hash table for dwp_file loaded CUs/TUs.  */
 
-static htab_t
+static htab_up
 allocate_dwp_loaded_cutus_table (struct objfile *objfile)
 {
-  return htab_create_alloc_ex (3,
-			       hash_dwp_loaded_cutus,
-			       eq_dwp_loaded_cutus,
-			       NULL,
-			       &objfile->objfile_obstack,
-			       hashtab_obstack_allocate,
-			       dummy_obstack_deallocate);
+  return htab_up (htab_create_alloc (3,
+				     hash_dwp_loaded_cutus,
+				     eq_dwp_loaded_cutus,
+				     NULL, xcalloc, xfree));
 }
 
 /* Try to open DWP file FILE_NAME.
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 12/38] Introduce die_info::has_children
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (26 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 04/38] Create dwarf2/abbrev.[ch] Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 10/38] Remove die_reader_specs::comp_dir Tom Tromey
                   ` (10 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Many functions take a "has_children" parameter (either as an in- or
out-parameter).  However, it seems to me that it makes more sense to
have "has_children" be an attribute of a DIE.  Making this change
allows this parameter to be eliminated in many places.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (struct die_info) <has_children>: New member.
	(dw2_get_file_names_reader): Remove has_children.
	(dw2_get_file_names): Update.
	(read_cutu_die_from_dwo): Remove has_children.
	(cutu_reader::init_tu_and_read_dwo_dies)
	(cutu_reader::cutu_reader): Update.
	(process_psymtab_comp_unit_reader, build_type_psymtabs_reader):
	Remove has_children.
	(build_type_psymtabs_1, process_skeletonless_type_unit)
	(load_partial_comp_unit, load_full_comp_unit): Update.
	(create_dwo_cu_reader): Remove has_children.
	(create_cus_hash_table, read_die_and_children): Update.
	(read_full_die_1,read_full_die): Remove has_children.
	(read_signatured_type): Update.
	(class cutu_reader) <has_children>: Remove.

Change-Id: I0d3d51ae9379554a66032648d51124bba07f87b4
---
 gdb/ChangeLog     | 18 +++++++++++
 gdb/dwarf2/read.c | 82 ++++++++++++++++++++---------------------------
 2 files changed, 52 insertions(+), 48 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index c4879865532..a35a55673dc 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -929,7 +929,6 @@ public:
 
   const gdb_byte *info_ptr = nullptr;
   struct die_info *comp_unit_die = nullptr;
-  int has_children = 0;
   bool dummy_p = false;
 
 private:
@@ -1247,6 +1246,9 @@ struct die_info
     /* 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;
 
@@ -1370,8 +1372,7 @@ static struct partial_symtab *create_partial_symtab
 
 static void build_type_psymtabs_reader (const struct die_reader_specs *reader,
 					const gdb_byte *info_ptr,
-					struct die_info *type_unit_die,
-					int has_children);
+					struct die_info *type_unit_die);
 
 static void dwarf2_build_psymtabs_hard
   (struct dwarf2_per_objfile *dwarf2_per_objfile);
@@ -1653,11 +1654,10 @@ static struct die_info *read_die_and_siblings (const struct die_reader_specs *,
 
 static const gdb_byte *read_full_die_1 (const struct die_reader_specs *,
 					struct die_info **, const gdb_byte *,
-					int *, int);
+					int);
 
 static const gdb_byte *read_full_die (const struct die_reader_specs *,
-				      struct die_info **, const gdb_byte *,
-				      int *);
+				      struct die_info **, const gdb_byte *);
 
 static void process_die (struct die_info *, struct dwarf2_cu *);
 
@@ -3343,8 +3343,7 @@ dwarf2_read_gdb_index
 static void
 dw2_get_file_names_reader (const struct die_reader_specs *reader,
 			   const gdb_byte *info_ptr,
-			   struct die_info *comp_unit_die,
-			   int has_children)
+			   struct die_info *comp_unit_die)
 {
   struct dwarf2_cu *cu = reader->cu;
   struct dwarf2_per_cu_data *this_cu = cu->per_cu;
@@ -3442,8 +3441,7 @@ dw2_get_file_names (struct dwarf2_per_cu_data *this_cu)
 
   cutu_reader reader (this_cu);
   if (!reader.dummy_p)
-    dw2_get_file_names_reader (&reader, reader.info_ptr, reader.comp_unit_die,
-			       reader.has_children);
+    dw2_get_file_names_reader (&reader, reader.info_ptr, reader.comp_unit_die);
 
   if (this_cu->v.quick->no_file_data)
     return NULL;
@@ -6932,7 +6930,7 @@ init_cu_die_reader (struct die_reader_specs *reader,
    from the DWO file, bypassing the stub, it contains the DW_AT_comp_dir
    attribute of the referencing CU.  At most one of STUB_COMP_UNIT_DIE and
    STUB_COMP_DIR may be non-NULL.
-   *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE,*RESULT_HAS_CHILDREN
+   *RESULT_READER,*RESULT_INFO_PTR,*RESULT_COMP_UNIT_DIE
    are filled in with the info of the DIE from the DWO file.
    *RESULT_DWO_ABBREV_TABLE will be filled in with the abbrev table allocated
    from the dwo.  Since *RESULT_READER references this abbrev table, it must be
@@ -6948,7 +6946,6 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
 			struct die_reader_specs *result_reader,
 			const gdb_byte **result_info_ptr,
 			struct die_info **result_comp_unit_die,
-			int *result_has_children,
 			abbrev_table_up *result_dwo_abbrev_table)
 {
   struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile;
@@ -7072,7 +7069,7 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
 		     + (ranges != NULL)
 		     + (comp_dir != NULL));
   info_ptr = read_full_die_1 (result_reader, result_comp_unit_die, info_ptr,
-			      result_has_children, num_extra_attrs);
+			      num_extra_attrs);
 
   /* Copy over the attributes from the stub to the DIE we just read in.  */
   comp_unit_die = *result_comp_unit_die;
@@ -7203,7 +7200,7 @@ cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
 			      NULL /* stub_comp_unit_die */,
 			      sig_type->dwo_unit->dwo_file->comp_dir,
 			      &reader, &info_ptr,
-			      &comp_unit_die, &has_children,
+			      &comp_unit_die,
 			      &m_dwo_abbrev_table) == 0)
     {
       /* Dummy die.  */
@@ -7362,7 +7359,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
 
   /* Read the top level CU/TU die.  */
   init_cu_die_reader (this, cu, section, NULL, abbrev_table);
-  info_ptr = read_full_die (this, &comp_unit_die, info_ptr, &has_children);
+  info_ptr = read_full_die (this, &comp_unit_die, info_ptr);
 
   if (skip_partial && comp_unit_die->tag == DW_TAG_partial_unit)
     {
@@ -7384,7 +7381,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
       struct dwo_unit *dwo_unit;
       struct die_info *dwo_comp_unit_die;
 
-      if (has_children)
+      if (comp_unit_die->has_children)
 	{
 	  complaint (_("compilation unit with DW_AT_GNU_dwo_name"
 		       " has children (offset %s) [in module %s]"),
@@ -7397,7 +7394,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
 	  if (read_cutu_die_from_dwo (this_cu, dwo_unit,
 				      comp_unit_die, NULL,
 				      this, &info_ptr,
-				      &dwo_comp_unit_die, &has_children,
+				      &dwo_comp_unit_die,
 				      &m_dwo_abbrev_table) == 0)
 	    {
 	      /* Dummy die.  */
@@ -7460,7 +7457,6 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
   bfd *abfd = section->get_bfd_owner ();
   struct dwarf2_section_info *abbrev_section;
   const gdb_byte *begin_info_ptr, *info_ptr;
-  int has_children;
 
   if (dwarf_die_debug)
     fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset %s\n",
@@ -7507,7 +7503,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
 
   init_cu_die_reader (this, m_new_cu.get (), section, dwo_file,
 		      m_abbrev_table_holder.get ());
-  info_ptr = read_full_die (this, &comp_unit_die, info_ptr, &has_children);
+  info_ptr = read_full_die (this, &comp_unit_die, info_ptr);
 }
 
 \f
@@ -7693,7 +7689,6 @@ static void
 process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 				  const gdb_byte *info_ptr,
 				  struct die_info *comp_unit_die,
-				  int has_children,
 				  int want_partial_unit,
 				  enum language pretend_language)
 {
@@ -7749,7 +7744,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
   /* Check if comp unit has_children.
      If so, read the rest of the partial symbols from this comp unit.
      If not, there's no more debug_info for this comp unit.  */
-  if (has_children)
+  if (comp_unit_die->has_children)
     {
       struct partial_die_info *first_die;
       CORE_ADDR lowpc, highpc;
@@ -7841,12 +7836,11 @@ process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
       /* Nothing.  */
     }
   else if (this_cu->is_debug_types)
-    build_type_psymtabs_reader (&reader, reader.info_ptr, reader.comp_unit_die,
-				reader.has_children);
+    build_type_psymtabs_reader (&reader, reader.info_ptr,
+				reader.comp_unit_die);
   else
     process_psymtab_comp_unit_reader (&reader, reader.info_ptr,
 				      reader.comp_unit_die,
-				      reader.has_children,
 				      want_partial_unit,
 				      pretend_language);
 
@@ -7859,8 +7853,7 @@ process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
 static void
 build_type_psymtabs_reader (const struct die_reader_specs *reader,
 			    const gdb_byte *info_ptr,
-			    struct die_info *type_unit_die,
-			    int has_children)
+			    struct die_info *type_unit_die)
 {
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = reader->cu->per_cu->dwarf2_per_objfile;
@@ -7877,7 +7870,7 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
   gdb_assert (per_cu->is_debug_types);
   sig_type = (struct signatured_type *) per_cu;
 
-  if (! has_children)
+  if (! type_unit_die->has_children)
     return;
 
   attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list);
@@ -8008,8 +8001,7 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
 			  0, 0, false);
       if (!reader.dummy_p)
 	build_type_psymtabs_reader (&reader, reader.info_ptr,
-				    reader.comp_unit_die,
-				    reader.has_children);
+				    reader.comp_unit_die);
     }
 }
 
@@ -8117,7 +8109,7 @@ process_skeletonless_type_unit (void **slot, void *info)
   cutu_reader reader (&entry->per_cu, NULL, 0, 0, false);
   if (!reader.dummy_p)
     build_type_psymtabs_reader (&reader, reader.info_ptr,
-				reader.comp_unit_die, reader.has_children);
+				reader.comp_unit_die);
 
   return 1;
 }
@@ -8255,7 +8247,7 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
       /* Check if comp unit has_children.
 	 If so, read the rest of the partial symbols from this comp unit.
 	 If not, there's no more debug_info for this comp unit.  */
-      if (reader.has_children)
+      if (reader.comp_unit_die->has_children)
 	load_partial_dies (&reader, reader.info_ptr, 0);
     }
 }
@@ -9424,7 +9416,7 @@ load_full_comp_unit (struct dwarf2_per_cu_data *this_cu,
 			  hashtab_obstack_allocate,
 			  dummy_obstack_deallocate);
 
-  if (reader.has_children)
+  if (reader.comp_unit_die->has_children)
     reader.comp_unit_die->child
       = read_die_and_siblings (&reader, reader.info_ptr,
 			       &info_ptr, reader.comp_unit_die);
@@ -11580,7 +11572,6 @@ static void
 create_dwo_cu_reader (const struct die_reader_specs *reader,
 		      const gdb_byte *info_ptr,
 		      struct die_info *comp_unit_die,
-		      int has_children,
 		      struct dwo_file *dwo_file,
 		      struct dwo_unit *dwo_unit)
 {
@@ -11651,7 +11642,7 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
       cutu_reader reader (&per_cu, cu, &dwo_file);
       if (!reader.dummy_p)
 	create_dwo_cu_reader (&reader, reader.info_ptr, reader.comp_unit_die,
-			      reader.has_children, &dwo_file, &read_unit);
+			      &dwo_file, &read_unit);
       info_ptr += per_cu.length;
 
       // If the unit could not be parsed, skip it.
@@ -17956,9 +17947,8 @@ read_die_and_children (const struct die_reader_specs *reader,
 {
   struct die_info *die;
   const gdb_byte *cur_ptr;
-  int has_children;
 
-  cur_ptr = read_full_die_1 (reader, &die, info_ptr, &has_children, 0);
+  cur_ptr = read_full_die_1 (reader, &die, info_ptr, 0);
   if (die == NULL)
     {
       *new_info_ptr = cur_ptr;
@@ -17966,7 +17956,7 @@ read_die_and_children (const struct die_reader_specs *reader,
     }
   store_in_ref_table (die, reader->cu);
 
-  if (has_children)
+  if (die->has_children)
     die->child = read_die_and_siblings_1 (reader, cur_ptr, new_info_ptr, die);
   else
     {
@@ -18047,13 +18037,12 @@ read_die_and_siblings (const struct die_reader_specs *reader,
    The caller is responsible for filling in the extra attributes
    and updating (*DIEP)->num_attrs.
    Set DIEP to point to a newly allocated die with its information,
-   except for its child, sibling, and parent fields.
-   Set HAS_CHILDREN to tell whether the die has children or not.  */
+   except for its child, sibling, and parent fields.  */
 
 static const gdb_byte *
 read_full_die_1 (const struct die_reader_specs *reader,
 		 struct die_info **diep, const gdb_byte *info_ptr,
-		 int *has_children, int num_extra_attrs)
+		 int num_extra_attrs)
 {
   unsigned int abbrev_number, bytes_read, i;
   struct abbrev_info *abbrev;
@@ -18067,7 +18056,6 @@ read_full_die_1 (const struct die_reader_specs *reader,
   if (!abbrev_number)
     {
       *diep = NULL;
-      *has_children = 0;
       return info_ptr;
     }
 
@@ -18081,6 +18069,7 @@ read_full_die_1 (const struct die_reader_specs *reader,
   die->sect_off = sect_off;
   die->tag = abbrev->tag;
   die->abbrev = abbrev_number;
+  die->has_children = abbrev->has_children;
 
   /* Make the result usable.
      The caller needs to update num_attrs after adding the extra
@@ -18108,23 +18097,20 @@ read_full_die_1 (const struct die_reader_specs *reader,
   for (int index : indexes_that_need_reprocess)
     read_attribute_reprocess (reader, &die->attrs[index]);
   *diep = die;
-  *has_children = abbrev->has_children;
   return info_ptr;
 }
 
 /* Read a die and all its attributes.
    Set DIEP to point to a newly allocated die with its information,
-   except for its child, sibling, and parent fields.
-   Set HAS_CHILDREN to tell whether the die has children or not.  */
+   except for its child, sibling, and parent fields.  */
 
 static const gdb_byte *
 read_full_die (const struct die_reader_specs *reader,
-	       struct die_info **diep, const gdb_byte *info_ptr,
-	       int *has_children)
+	       struct die_info **diep, const gdb_byte *info_ptr)
 {
   const gdb_byte *result;
 
-  result = read_full_die_1 (reader, diep, info_ptr, has_children, 0);
+  result = read_full_die_1 (reader, diep, info_ptr, 0);
 
   if (dwarf_die_debug)
     {
@@ -23538,7 +23524,7 @@ read_signatured_type (struct signatured_type *sig_type)
 			      hashtab_obstack_allocate,
 			      dummy_obstack_deallocate);
 
-      if (reader.has_children)
+      if (reader.comp_unit_die->has_children)
 	reader.comp_unit_die->child
 	  = read_die_and_siblings (&reader, info_ptr, &info_ptr,
 				   reader.comp_unit_die);
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 23/38] Change dwarf2_per_objfile::quick_file_names_table to htab_up
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (15 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 15/38] Change dwarf2_per_objfile::type_unit_groups to htab_up Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 33/38] Create dwarf2/comp-unit.[ch] Tom Tromey
                   ` (21 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes dwarf2_per_objfile::quick_file_names_table to be an
htab_up.  This just removes a bit of manual management.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (~dwarf2_per_objfile): Update.
	(create_quick_file_names_table): Return htab_up.
	(dw2_get_file_names_reader, dw2_forget_cached_source_info):
	Update.
	* dwarf2/read.h (struct dwarf2_per_objfile)
	<quick_file_names_table>: Now htab_up.

Change-Id: I4ff2fce8b8af27f4bfe01a11b97a889edfd23151
---
 gdb/ChangeLog     |  9 +++++++++
 gdb/dwarf2/read.c | 15 ++++++---------
 gdb/dwarf2/read.h |  2 +-
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 84c38eb04c7..7c59db56e22 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2016,9 +2016,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
   /* Cached DIE trees use xmalloc and the comp_unit_obstack.  */
   free_cached_comp_units ();
 
-  if (quick_file_names_table)
-    htab_delete (quick_file_names_table);
-
   for (dwarf2_per_cu_data *per_cu : all_comp_units)
     per_cu->imported_symtabs_free ();
 
@@ -2529,12 +2526,12 @@ delete_file_name_entry (void *e)
 
 /* Create a quick_file_names hash table.  */
 
-static htab_t
+static htab_up
 create_quick_file_names_table (unsigned int nr_initial_entries)
 {
-  return htab_create_alloc (nr_initial_entries,
-			    hash_file_name_entry, eq_file_name_entry,
-			    delete_file_name_entry, xcalloc, xfree);
+  return htab_up (htab_create_alloc (nr_initial_entries,
+				     hash_file_name_entry, eq_file_name_entry,
+				     delete_file_name_entry, xcalloc, xfree));
 }
 
 /* Read in PER_CU->CU.  This function is unrelated to symtabs, symtab would
@@ -3370,7 +3367,7 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
 	 If we have we're done.  */
       find_entry.hash.dwo_unit = cu->dwo_unit;
       find_entry.hash.line_sect_off = line_offset;
-      slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table,
+      slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table.get (),
 			     &find_entry, INSERT);
       if (*slot != NULL)
 	{
@@ -3494,7 +3491,7 @@ dw2_forget_cached_source_info (struct objfile *objfile)
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = get_dwarf2_per_objfile (objfile);
 
-  htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table,
+  htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table.get (),
 			  dw2_free_cached_file_names, NULL);
 }
 
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 92a5562e0e1..c3a53f65fe7 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -204,7 +204,7 @@ public:
      sorted all the TUs into "type unit groups", grouped by their
      DW_AT_stmt_list value.  Therefore the only sharing done here is with a
      CU and its associated TU group if there is one.  */
-  htab_t quick_file_names_table {};
+  htab_up quick_file_names_table;
 
   /* Set during partial symbol reading, to prevent queueing of full
      symbols.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 20/38] Minor cleanups in abbrev_table
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (29 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 28/38] Move dwarf2_per_cu_data::imported_symtabs earlier Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 30/38] Unify read_initial_length implementations Tom Tromey
                   ` (7 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This cleans up the DWARF abbrev_table API a bit, primarily by making
various methods and members private.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_cutu_die_from_dwo): Update.
	(cutu_reader): Update.
	(build_type_psymtabs_1): Update.
	* dwarf2/abbrev.c (abbrev_table::read): Rename.
	(abbrev_table::alloc_abbrev): Update.
	* dwarf2/abbrev.h (abbrev_table_up): Move earlier.
	(abbrev_table::read): New static method, renamed from
	abbrev_table_read_table.
	(abbrev_table::alloc_abbrev)
	(abbrev_table::add_abbrev): Now private.
	(abbrev_table::abbrev_table): Now private.
	(abbrev_table::m_abbrev_obstack): Now private.  Rename.

Change-Id: I320dca83b799f672909ae66f73b7aca266adbaf9
---
 gdb/ChangeLog       | 15 +++++++++++++++
 gdb/dwarf2/abbrev.c | 10 +++++-----
 gdb/dwarf2/abbrev.h | 46 ++++++++++++++++++++++-----------------------
 gdb/dwarf2/read.c   | 18 +++++++++---------
 4 files changed, 52 insertions(+), 37 deletions(-)

diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index 544d5793add..fac7309b93c 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -44,7 +44,7 @@ abbrev_table::alloc_abbrev ()
 {
   struct abbrev_info *abbrev;
 
-  abbrev = XOBNEW (&abbrev_obstack, struct abbrev_info);
+  abbrev = XOBNEW (&m_abbrev_obstack, struct abbrev_info);
   memset (abbrev, 0, sizeof (struct abbrev_info));
 
   return abbrev;
@@ -87,9 +87,9 @@ abbrev_table::lookup_abbrev (unsigned int abbrev_number)
 /* Read in an abbrev table.  */
 
 abbrev_table_up
-abbrev_table_read_table (struct objfile *objfile,
-			 struct dwarf2_section_info *section,
-			 sect_offset sect_off)
+abbrev_table::read (struct objfile *objfile,
+		    struct dwarf2_section_info *section,
+		    sect_offset sect_off)
 {
   bfd *abfd = section->get_bfd_owner ();
   const gdb_byte *abbrev_ptr;
@@ -152,7 +152,7 @@ abbrev_table_read_table (struct objfile *objfile,
 	}
 
       cur_abbrev->attrs =
-	XOBNEWVEC (&abbrev_table->abbrev_obstack, struct attr_abbrev,
+	XOBNEWVEC (&abbrev_table->m_abbrev_obstack, struct attr_abbrev,
 		   cur_abbrev->num_attrs);
       memcpy (cur_abbrev->attrs, cur_attrs.data (),
 	      cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h
index df83c093be2..52103b0a683 100644
--- a/gdb/dwarf2/abbrev.h
+++ b/gdb/dwarf2/abbrev.h
@@ -50,15 +50,34 @@ struct attr_abbrev
 /* Size of abbrev_table.abbrev_hash_table.  */
 #define ABBREV_HASH_SIZE 121
 
+struct abbrev_table;
+typedef std::unique_ptr<struct abbrev_table> abbrev_table_up;
+
 /* Top level data structure to contain an abbreviation table.  */
 
 struct abbrev_table
 {
+  static abbrev_table_up read (struct objfile *objfile,
+			       struct dwarf2_section_info *section,
+			       sect_offset sect_off);
+
+  /* Look up an abbrev in the table.
+     Returns NULL if the abbrev is not found.  */
+
+  struct abbrev_info *lookup_abbrev (unsigned int abbrev_number);
+
+
+  /* Where the abbrev table came from.
+     This is used as a sanity check when the table is used.  */
+  const sect_offset sect_off;
+
+private:
+
   explicit abbrev_table (sect_offset off)
     : sect_off (off)
   {
     m_abbrevs =
-      XOBNEWVEC (&abbrev_obstack, struct abbrev_info *, ABBREV_HASH_SIZE);
+      XOBNEWVEC (&m_abbrev_obstack, struct abbrev_info *, ABBREV_HASH_SIZE);
     memset (m_abbrevs, 0, ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
   }
 
@@ -71,33 +90,14 @@ struct abbrev_table
   /* Add an abbreviation to the table.  */
   void add_abbrev (unsigned int abbrev_number, struct abbrev_info *abbrev);
 
-  /* Look up an abbrev in the table.
-     Returns NULL if the abbrev is not found.  */
-
-  struct abbrev_info *lookup_abbrev (unsigned int abbrev_number);
-
-
-  /* Where the abbrev table came from.
-     This is used as a sanity check when the table is used.  */
-  const sect_offset sect_off;
-
-  /* Storage for the abbrev table.  */
-  auto_obstack abbrev_obstack;
-
-private:
-
   /* Hash table of abbrevs.
      This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
      It could be statically allocated, but the previous code didn't so we
      don't either.  */
   struct abbrev_info **m_abbrevs;
-};
 
-typedef std::unique_ptr<struct abbrev_table> abbrev_table_up;
-
-extern abbrev_table_up abbrev_table_read_table
-  (struct objfile *objfile,
-   struct dwarf2_section_info *section,
-   sect_offset sect_off);
+  /* Storage for the abbrev table.  */
+  auto_obstack m_abbrev_obstack;
+};
 
 #endif /* GDB_DWARF2_ABBREV_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 76651ac7a41..84c38eb04c7 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7043,8 +7043,8 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
     }
 
   *result_dwo_abbrev_table
-    = abbrev_table_read_table (objfile, dwo_abbrev_section,
-			       cu->header.abbrev_sect_off);
+    = abbrev_table::read (objfile, dwo_abbrev_section,
+			  cu->header.abbrev_sect_off);
   init_cu_die_reader (result_reader, cu, section, dwo_unit->dwo_file,
 		      result_dwo_abbrev_table->get ());
 
@@ -7341,8 +7341,8 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
   else
     {
       m_abbrev_table_holder
-	= abbrev_table_read_table (objfile, abbrev_section,
-				   cu->header.abbrev_sect_off);
+	= abbrev_table::read (objfile, abbrev_section,
+			      cu->header.abbrev_sect_off);
       abbrev_table = m_abbrev_table_holder.get ();
     }
 
@@ -7487,8 +7487,8 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
     }
 
   m_abbrev_table_holder
-    = abbrev_table_read_table (objfile, abbrev_section,
-			       m_new_cu->header.abbrev_sect_off);
+    = abbrev_table::read (objfile, abbrev_section,
+			  m_new_cu->header.abbrev_sect_off);
 
   init_cu_die_reader (this, m_new_cu.get (), section, dwo_file,
 		      m_abbrev_table_holder.get ());
@@ -7977,9 +7977,9 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
 	{
 	  abbrev_offset = tu.abbrev_offset;
 	  abbrev_table =
-	    abbrev_table_read_table (dwarf2_per_objfile->objfile,
-				     &dwarf2_per_objfile->abbrev,
-				     abbrev_offset);
+	    abbrev_table::read (dwarf2_per_objfile->objfile,
+				&dwarf2_per_objfile->abbrev,
+				abbrev_offset);
 	  ++tu_stats->nr_uniq_abbrev_tables;
 	}
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 38/38] Remove "keep" parameter from cutu_reader constructor
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (5 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 27/38] Move DWARF line_header to new file Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-02-08 17:36   ` Simon Marchi
  2020-01-23  0:57 ` [PATCH 05/38] Create dwarf2/attribute.[ch] Tom Tromey
                   ` (31 subsequent siblings)
  38 siblings, 1 reply; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

cutu_reader has a "keep" parameter, which is used to decide what to do
with a new CU when the reader is destroyed.  Most code does not try to
preserve the CU, so this patch removes this parameter and instead adds
a new method that users can call to preserve the CU on the chain.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (class cutu_reader) <cutu_reader,
	init_tu_and_read_dwo_dies>: Remove "keep" parameter.
	<keep>: Declare method.
	<m_keep>: Remove member.
	<~cutu_reader>: Default.
	(cutu_reader::init_tu_and_read_dwo_dies): Update.
	(cutu_reader::cutu_reader): Update.
	(cutu_reader::keep): Rename from ~cutu_reader.
	(process_psymtab_comp_unit, build_type_psymtabs_1)
	(process_skeletonless_type_unit, load_partial_comp_unit)
	(load_full_comp_unit, dwarf2_read_addr_index)
	(read_signatured_type): Update.

Change-Id: I859b1c64313569d76d46317c14e9b077ebc3a27b
---
 gdb/ChangeLog     | 15 +++++++++++++
 gdb/dwarf2/read.c | 55 +++++++++++++++++++++++++----------------------
 2 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index d1a78afd8cf..754b752dc5d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -881,14 +881,14 @@ public:
 
   cutu_reader (struct dwarf2_per_cu_data *this_cu,
 	       struct abbrev_table *abbrev_table,
-	       int use_existing_cu, int keep,
+	       int use_existing_cu,
 	       bool skip_partial);
 
   explicit cutu_reader (struct dwarf2_per_cu_data *this_cu,
 			struct dwarf2_cu *parent_cu = nullptr,
 			struct dwo_file *dwo_file = nullptr);
 
-  ~cutu_reader ();
+  ~cutu_reader () = default;
 
   DISABLE_COPY_AND_ASSIGN (cutu_reader);
 
@@ -896,12 +896,15 @@ public:
   struct die_info *comp_unit_die = nullptr;
   bool dummy_p = false;
 
+  /* Release the new CU, putting it on the chain.  This cannot be done
+     for dummy CUs.  */
+  void keep ();
+
 private:
   void init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
-				  int use_existing_cu, int keep);
+				  int use_existing_cu);
 
   struct dwarf2_per_cu_data *m_this_cu;
-  int m_keep = 0;
   std::unique_ptr<dwarf2_cu> m_new_cu;
 
   /* The ordinary abbreviation table.  */
@@ -6730,7 +6733,7 @@ lookup_dwo_unit (struct dwarf2_per_cu_data *this_cu,
 
 void
 cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
-					int use_existing_cu, int keep)
+					int use_existing_cu)
 {
   struct signatured_type *sig_type;
   struct die_reader_specs reader;
@@ -6778,19 +6781,14 @@ cutu_reader::init_tu_and_read_dwo_dies (struct dwarf2_per_cu_data *this_cu,
    This is an optimization for when we already have the abbrev table.
 
    If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
-   Otherwise, a new CU is allocated with xmalloc.
-
-   If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to
-   read_in_chain.  Otherwise the dwarf2_cu data is freed at the
-   end.  */
+   Otherwise, a new CU is allocated with xmalloc.  */
 
 cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
 			  struct abbrev_table *abbrev_table,
-			  int use_existing_cu, int keep,
+			  int use_existing_cu,
 			  bool skip_partial)
   : die_reader_specs {},
-    m_this_cu (this_cu),
-    m_keep (keep)
+    m_this_cu (this_cu)
 {
   struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
@@ -6810,9 +6808,6 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
 			this_cu->is_debug_types ? "type" : "comp",
 			sect_offset_str (this_cu->sect_off));
 
-  if (use_existing_cu)
-    gdb_assert (keep);
-
   /* If we're reading a TU directly from a DWO file, including a virtual DWO
      file (instead of going through the stub), short-circuit all of this.  */
   if (this_cu->reading_dwo_directly)
@@ -6820,7 +6815,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
       /* Narrow down the scope of possibilities to have to understand.  */
       gdb_assert (this_cu->is_debug_types);
       gdb_assert (abbrev_table == NULL);
-      init_tu_and_read_dwo_dies (this_cu, use_existing_cu, keep);
+      init_tu_and_read_dwo_dies (this_cu, use_existing_cu);
       return;
     }
 
@@ -6976,10 +6971,12 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
     }
 }
 
-cutu_reader::~cutu_reader ()
+void
+cutu_reader::keep ()
 {
   /* Done, clean up.  */
-  if (m_new_cu != NULL && m_keep && !dummy_p)
+  gdb_assert (!dummy_p);
+  if (m_new_cu != NULL)
     {
       struct dwarf2_per_objfile *dwarf2_per_objfile
 	= m_this_cu->dwarf2_per_objfile;
@@ -7384,7 +7381,7 @@ process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
   if (this_cu->cu != NULL)
     free_one_cached_comp_unit (this_cu);
 
-  cutu_reader reader (this_cu, NULL, 0, 0, false);
+  cutu_reader reader (this_cu, NULL, 0, false);
 
   if (reader.dummy_p)
     {
@@ -7553,7 +7550,7 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
 	}
 
       cutu_reader reader (&tu.sig_type->per_cu, abbrev_table.get (),
-			  0, 0, false);
+			  0, false);
       if (!reader.dummy_p)
 	build_type_psymtabs_reader (&reader, reader.info_ptr,
 				    reader.comp_unit_die);
@@ -7661,7 +7658,7 @@ process_skeletonless_type_unit (void **slot, void *info)
   *slot = entry;
 
   /* This does the job that build_type_psymtabs_1 would have done.  */
-  cutu_reader reader (&entry->per_cu, NULL, 0, 0, false);
+  cutu_reader reader (&entry->per_cu, NULL, 0, false);
   if (!reader.dummy_p)
     build_type_psymtabs_reader (&reader, reader.info_ptr,
 				reader.comp_unit_die);
@@ -7790,7 +7787,7 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
 static void
 load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
 {
-  cutu_reader reader (this_cu, NULL, 1, 1, false);
+  cutu_reader reader (this_cu, NULL, 1, false);
 
   if (!reader.dummy_p)
     {
@@ -7802,6 +7799,8 @@ load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
 	 If not, there's no more debug_info for this comp unit.  */
       if (reader.comp_unit_die->has_children)
 	load_partial_dies (&reader, reader.info_ptr, 0);
+
+      reader.keep ();
     }
 }
 
@@ -8937,7 +8936,7 @@ load_full_comp_unit (struct dwarf2_per_cu_data *this_cu,
 {
   gdb_assert (! this_cu->is_debug_types);
 
-  cutu_reader reader (this_cu, NULL, 1, 1, skip_partial);
+  cutu_reader reader (this_cu, NULL, 1, skip_partial);
   if (reader.dummy_p)
     return;
 
@@ -8968,6 +8967,8 @@ load_full_comp_unit (struct dwarf2_per_cu_data *this_cu,
      Similarly, if we do not read the producer, we can not apply
      producer-specific interpretation.  */
   prepare_one_comp_unit (cu, cu->dies, pretend_language);
+
+  reader.keep ();
 }
 
 /* Add a DIE to the delayed physname list.  */
@@ -18961,7 +18962,7 @@ dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu,
     }
   else
     {
-      cutu_reader reader (per_cu, NULL, 0, 0, false);
+      cutu_reader reader (per_cu, NULL, 0, false);
       addr_base = reader.cu->addr_base;
       addr_size = reader.cu->header.addr_size;
     }
@@ -22791,7 +22792,7 @@ read_signatured_type (struct signatured_type *sig_type)
   gdb_assert (per_cu->is_debug_types);
   gdb_assert (per_cu->cu == NULL);
 
-  cutu_reader reader (per_cu, NULL, 0, 1, false);
+  cutu_reader reader (per_cu, NULL, 0, false);
 
   if (!reader.dummy_p)
     {
@@ -22822,6 +22823,8 @@ read_signatured_type (struct signatured_type *sig_type)
 	 correctly.  Similarly, if we do not read the producer, we can
 	 not apply producer-specific interpretation.  */
       prepare_one_comp_unit (cu, cu->dies, language_minimal);
+
+      reader.keep ();
     }
 
   sig_type->per_cu.tu_read = 1;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 06/38] Change some attribute functions to be methods
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (20 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 26/38] Change line_table methods to return unique_xmalloc_ptr Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 11/38] Move DWARF code to dwarf2/ subdirectory Tom Tromey
                   ` (16 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes most of the attribute-related functions to be methods.
(attr_form_is_block changed in a subsequent patch.)

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_find_base_address, )
	(read_call_site_scope, rust_containing_type)
	(dwarf2_get_pc_bounds, dwarf2_record_block_ranges)
	(handle_data_member_location, dwarf2_add_member_fn)
	(get_alignment, read_structure_type, process_structure_scope)
	(mark_common_block_symbol_computed, read_common_block)
	(read_tag_string_type, attr_to_dynamic_prop, read_subrange_type)
	(partial_die_info::read, read_attribute_value, new_symbol)
	(lookup_die_type, dwarf2_get_ref_die_offset)
	(dwarf2_get_attr_constant_value, follow_die_ref_or_sig)
	(dwarf2_fetch_die_loc_sect_off, get_DW_AT_signature_type)
	(dwarf2_symbol_mark_computed): Update.
	* dwarf2/attribute.h (struct attribute) <value_as_address,
	form_is_section_offset, form_is_constant, form_is_ref>: Declare
	methods.
	(value_as_address, attr_form_is_section_offset)
	(attr_form_is_constant, attr_form_is_ref): Don't declare.
	* dwarf2/attribute.c (attribute::value_as_address)
	(attribute::form_is_section_offset, attribute::form_is_constant)
	(attribute::form_is_ref): Now methods.

Change-Id: I320dad13002c59b848dc86c39d5d7111c8a15bdc
---
 gdb/ChangeLog          | 23 +++++++++++
 gdb/dwarf2/attribute.c | 40 +++++++++----------
 gdb/dwarf2/attribute.h | 78 ++++++++++++++++++-------------------
 gdb/dwarf2read.c       | 88 +++++++++++++++++++++---------------------
 4 files changed, 126 insertions(+), 103 deletions(-)

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 75a2fa3774b..6e51fff5362 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -30,12 +30,12 @@
 /* See attribute.h.  */
 
 CORE_ADDR
-attr_value_as_address (struct attribute *attr)
+attribute::value_as_address () const
 {
   CORE_ADDR addr;
 
-  if (attr->form != DW_FORM_addr && attr->form != DW_FORM_addrx
-      && attr->form != DW_FORM_GNU_addr_index)
+  if (form != DW_FORM_addr && form != DW_FORM_addrx
+      && form != DW_FORM_GNU_addr_index)
     {
       /* Aside from a few clearly defined exceptions, attributes that
 	 contain an address must always be in DW_FORM_addr form.
@@ -49,10 +49,10 @@ attr_value_as_address (struct attribute *attr)
 	 as well as update callers to pass in at least the CU's DWARF
 	 version.  This is more overhead than what we're willing to
 	 expand for a pretty rare case.  */
-      addr = DW_UNSND (attr);
+      addr = DW_UNSND (this);
     }
   else
-    addr = DW_ADDR (attr);
+    addr = DW_ADDR (this);
 
   return addr;
 }
@@ -72,20 +72,20 @@ attr_form_is_block (const struct attribute *attr)
 
 /* See attribute.h.  */
 
-int
-attr_form_is_section_offset (const struct attribute *attr)
+bool
+attribute::form_is_section_offset () const
 {
-  return (attr->form == DW_FORM_data4
-          || attr->form == DW_FORM_data8
-	  || attr->form == DW_FORM_sec_offset);
+  return (form == DW_FORM_data4
+          || form == DW_FORM_data8
+	  || form == DW_FORM_sec_offset);
 }
 
 /* See attribute.h.  */
 
-int
-attr_form_is_constant (const struct attribute *attr)
+bool
+attribute::form_is_constant () const
 {
-  switch (attr->form)
+  switch (form)
     {
     case DW_FORM_sdata:
     case DW_FORM_udata:
@@ -94,19 +94,19 @@ attr_form_is_constant (const struct attribute *attr)
     case DW_FORM_data4:
     case DW_FORM_data8:
     case DW_FORM_implicit_const:
-      return 1;
+      return true;
     default:
-      return 0;
+      return false;
     }
 }
 
 /* DW_ADDR is always stored already as sect_offset; despite for the forms
    besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file.  */
 
-int
-attr_form_is_ref (const struct attribute *attr)
+bool
+attribute::form_is_ref () const
 {
-  switch (attr->form)
+  switch (form)
     {
     case DW_FORM_ref_addr:
     case DW_FORM_ref1:
@@ -115,8 +115,8 @@ attr_form_is_ref (const struct attribute *attr)
     case DW_FORM_ref8:
     case DW_FORM_ref_udata:
     case DW_FORM_GNU_ref_alt:
-      return 1;
+      return true;
     default:
-      return 0;
+      return false;
     }
 }
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 11c6cb929d9..2e663f1560c 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -41,6 +41,45 @@ struct dwarf_block
 /* Attributes have a name and a value.  */
 struct attribute
 {
+  /* Read the given attribute value as an address, taking the
+     attribute's form into account.  */
+  CORE_ADDR value_as_address () const;
+
+  /* Return non-zero if ATTR's value is a section offset --- classes
+     lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
+     You may use DW_UNSND (attr) to retrieve such offsets.
+
+     Section 7.5.4, "Attribute Encodings", explains that no attribute
+     may have a value that belongs to more than one of these classes; it
+     would be ambiguous if we did, because we use the same forms for all
+     of them.  */
+
+  bool form_is_section_offset () const;
+
+  /* Return non-zero if ATTR's value falls in the 'constant' class, or
+     zero otherwise.  When this function returns true, you can apply
+     dwarf2_get_attr_constant_value to it.
+
+     However, note that for some attributes you must check
+     attr_form_is_section_offset before using this test.  DW_FORM_data4
+     and DW_FORM_data8 are members of both the constant class, and of
+     the classes that contain offsets into other debug sections
+     (lineptr, loclistptr, macptr or rangelistptr).  The DWARF spec says
+     that, if an attribute's can be either a constant or one of the
+     section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
+     taken as section offsets, not constants.
+
+     DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
+     cannot handle that.  */
+
+  bool form_is_constant () const;
+
+  /* DW_ADDR is always stored already as sect_offset; despite for the forms
+     besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file.  */
+
+  bool form_is_ref () const;
+
+
   ENUM_BITFIELD(dwarf_attribute) name : 16;
   ENUM_BITFIELD(dwarf_form) form : 15;
 
@@ -71,48 +110,9 @@ struct attribute
 #define DW_ADDR(attr)	   ((attr)->u.addr)
 #define DW_SIGNATURE(attr) ((attr)->u.signature)
 
-/* Read the given attribute value as an address, taking the attribute's
-   form into account.  */
-
-extern CORE_ADDR attr_value_as_address (struct attribute *attr);
-
 /* Check if the attribute's form is a DW_FORM_block*
    if so return true else false.  */
 
 extern int attr_form_is_block (const struct attribute *attr);
 
-/* Return non-zero if ATTR's value is a section offset --- classes
-   lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise.
-   You may use DW_UNSND (attr) to retrieve such offsets.
-
-   Section 7.5.4, "Attribute Encodings", explains that no attribute
-   may have a value that belongs to more than one of these classes; it
-   would be ambiguous if we did, because we use the same forms for all
-   of them.  */
-
-extern int attr_form_is_section_offset (const struct attribute *attr);
-
-/* Return non-zero if ATTR's value falls in the 'constant' class, or
-   zero otherwise.  When this function returns true, you can apply
-   dwarf2_get_attr_constant_value to it.
-
-   However, note that for some attributes you must check
-   attr_form_is_section_offset before using this test.  DW_FORM_data4
-   and DW_FORM_data8 are members of both the constant class, and of
-   the classes that contain offsets into other debug sections
-   (lineptr, loclistptr, macptr or rangelistptr).  The DWARF spec says
-   that, if an attribute's can be either a constant or one of the
-   section offset classes, DW_FORM_data4 and DW_FORM_data8 should be
-   taken as section offsets, not constants.
-
-   DW_FORM_data16 is not considered as dwarf2_get_attr_constant_value
-   cannot handle that.  */
-
-extern int attr_form_is_constant (const struct attribute *attr);
-
-/* DW_ADDR is always stored already as sect_offset; despite for the forms
-   besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file.  */
-
-extern int attr_form_is_ref (const struct attribute *attr);
-
 #endif /* GDB_DWARF2_ATTRIBUTE_H */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 5b77e397899..87b8aaaf679 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6117,7 +6117,7 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_entry_pc, cu);
   if (attr != nullptr)
     {
-      cu->base_address = attr_value_as_address (attr);
+      cu->base_address = attr->value_as_address ();
       cu->base_known = 1;
     }
   else
@@ -6125,7 +6125,7 @@ dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu)
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
       if (attr != nullptr)
 	{
-	  cu->base_address = attr_value_as_address (attr);
+	  cu->base_address = attr->value_as_address ();
 	  cu->base_known = 1;
 	}
     }
@@ -13632,7 +13632,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 		 sect_offset_str (die->sect_off), objfile_name (objfile));
       return;
     }
-  pc = attr_value_as_address (attr) + baseaddr;
+  pc = attr->value_as_address () + baseaddr;
   pc = gdbarch_adjust_dwarf2_addr (gdbarch, pc);
 
   if (cu->call_site_htab == NULL)
@@ -13751,7 +13751,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 
       SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton);
     }
-  else if (attr_form_is_ref (attr))
+  else if (attr->form_is_ref ())
     {
       struct dwarf2_cu *target_cu = cu;
       struct die_info *target_die;
@@ -13826,7 +13826,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	     for DW_AT_call_parameter.  */
 	  origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu);
 	}
-      if (loc == NULL && origin != NULL && attr_form_is_ref (origin))
+      if (loc == NULL && origin != NULL && origin->form_is_ref ())
 	{
 	  parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET;
 
@@ -13928,7 +13928,7 @@ rust_containing_type (struct die_info *die, struct dwarf2_cu *cu)
   struct die_info *type_die = NULL;
   struct dwarf2_cu *type_cu = cu;
 
-  if (attr_form_is_ref (attr))
+  if (attr->form_is_ref ())
     type_die = follow_die_ref (die, attr, &type_cu);
   if (type_die == NULL)
     return NULL;
@@ -14339,9 +14339,9 @@ dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc,
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
       if (attr != nullptr)
         {
-	  low = attr_value_as_address (attr);
-	  high = attr_value_as_address (attr_high);
-	  if (cu->header.version >= 4 && attr_form_is_constant (attr_high))
+	  low = attr->value_as_address ();
+	  high = attr_high->value_as_address ();
+	  if (cu->header.version >= 4 && attr_high->form_is_constant ())
 	    high += low;
 	}
       else
@@ -14512,10 +14512,10 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
       attr = dwarf2_attr (die, DW_AT_low_pc, cu);
       if (attr != nullptr)
         {
-          CORE_ADDR low = attr_value_as_address (attr);
-	  CORE_ADDR high = attr_value_as_address (attr_high);
+          CORE_ADDR low = attr->value_as_address ();
+	  CORE_ADDR high = attr_high->value_as_address ();
 
-	  if (cu->header.version >= 4 && attr_form_is_constant (attr_high))
+	  if (cu->header.version >= 4 && attr_high->form_is_constant ())
 	    high += low;
 
 	  low = gdbarch_adjust_dwarf2_addr (gdbarch, low + baseaddr);
@@ -14668,9 +14668,9 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
 	 This is because DW_AT_data_member_location is new in DWARF 4,
 	 so if we see it, we can assume that a constant form is really
 	 a constant and not a section offset.  */
-      if (attr_form_is_constant (attr))
+      if (attr->form_is_constant ())
 	*offset = dwarf2_get_attr_constant_value (attr, 0);
-      else if (attr_form_is_section_offset (attr))
+      else if (attr->form_is_section_offset ())
 	dwarf2_complex_location_expr_complaint ();
       else if (attr_form_is_block (attr))
 	*offset = decode_locdesc (DW_BLOCK (attr), cu);
@@ -15291,7 +15291,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
 		}
 	    }
 	}
-      else if (attr_form_is_section_offset (attr))
+      else if (attr->form_is_section_offset ())
         {
 	  dwarf2_complex_location_expr_complaint ();
         }
@@ -15418,7 +15418,7 @@ get_alignment (struct dwarf2_cu *cu, struct die_info *die)
   if (attr == nullptr)
     return 0;
 
-  if (!attr_form_is_constant (attr))
+  if (!attr->form_is_constant ())
     {
       complaint (_("DW_AT_alignment must have constant form"
 		   " - DIE at %s [in module %s]"),
@@ -15620,7 +15620,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr != nullptr)
     {
-      if (attr_form_is_constant (attr))
+      if (attr->form_is_constant ())
         TYPE_LENGTH (type) = DW_UNSND (attr);
       else
 	{
@@ -15785,7 +15785,7 @@ process_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
 	     In this case arrange not to check the offset.  */
 	  is_variant_part = false;
 	}
-      else if (attr_form_is_ref (discr))
+      else if (discr->form_is_ref ())
 	{
 	  struct dwarf2_cu *target_cu = cu;
 	  struct die_info *target_die = follow_die_ref (die, discr, &target_cu);
@@ -16463,7 +16463,7 @@ mark_common_block_symbol_computed (struct symbol *sym,
   gdb_assert (common_loc && member_loc);
   gdb_assert (attr_form_is_block (common_loc));
   gdb_assert (attr_form_is_block (member_loc)
-	      || attr_form_is_constant (member_loc));
+	      || member_loc->form_is_constant ());
 
   baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
   baton->per_cu = cu->per_cu;
@@ -16471,7 +16471,7 @@ mark_common_block_symbol_computed (struct symbol *sym,
 
   baton->size = 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */;
 
-  if (attr_form_is_constant (member_loc))
+  if (member_loc->form_is_constant ())
     {
       offset = dwarf2_get_attr_constant_value (member_loc, 0);
       baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
@@ -16487,7 +16487,7 @@ mark_common_block_symbol_computed (struct symbol *sym,
   store_unsigned_integer (ptr, 4, byte_order, cu_off);
   ptr += 4;
 
-  if (attr_form_is_constant (member_loc))
+  if (member_loc->form_is_constant ())
     {
       *ptr++ = DW_OP_addr;
       store_unsigned_integer (ptr, cu->header.addr_size, byte_order, offset);
@@ -16527,7 +16527,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
         {
 	  /* Ok.  */
         }
-      else if (attr_form_is_section_offset (attr))
+      else if (attr->form_is_section_offset ())
         {
 	  dwarf2_complex_location_expr_complaint ();
 	  attr = NULL;
@@ -16588,9 +16588,9 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
 			       sect_offset_str (child_die->sect_off),
 			     objfile_name (objfile));
 
-		  if (attr_form_is_section_offset (member_loc))
+		  if (member_loc->form_is_section_offset ())
 		    dwarf2_complex_location_expr_complaint ();
-		  else if (attr_form_is_constant (member_loc)
+		  else if (member_loc->form_is_constant ()
 			   || attr_form_is_block (member_loc))
 		    {
 		      if (attr != nullptr)
@@ -17051,7 +17051,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
     }
 
   attr = dwarf2_attr (die, DW_AT_string_length, cu);
-  if (attr != nullptr && !attr_form_is_constant (attr))
+  if (attr != nullptr && !attr->form_is_constant ())
     {
       /* The string length describes the location at which the length of
 	 the string can be found.  The size of the length field can be
@@ -17061,7 +17061,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
 	= dwarf2_attr (die, DW_AT_string_length_byte_size, cu);
       if (len == nullptr)
 	len = dwarf2_attr (die, DW_AT_byte_size, cu);
-      if (len != nullptr && attr_form_is_constant (len))
+      if (len != nullptr && len->form_is_constant ())
 	{
 	  /* Pass 0 as the default as we know this attribute is constant
 	     and the default value will not be returned.  */
@@ -17595,7 +17595,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
       prop->kind = PROP_LOCEXPR;
       gdb_assert (prop->data.baton != NULL);
     }
-  else if (attr_form_is_ref (attr))
+  else if (attr->form_is_ref ())
     {
       struct dwarf2_cu *target_cu = cu;
       struct die_info *target_die;
@@ -17612,7 +17612,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
       switch (target_attr->name)
 	{
 	  case DW_AT_location:
-	    if (attr_form_is_section_offset (target_attr))
+	    if (target_attr->form_is_section_offset ())
 	      {
 		baton = XOBNEW (obstack, struct dwarf2_property_baton);
 		baton->property_type = die_type (target_die, target_cu);
@@ -17659,7 +17659,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
 	    }
 	}
     }
-  else if (attr_form_is_constant (attr))
+  else if (attr->form_is_constant ())
     {
       prop->data.const_val = dwarf2_get_attr_constant_value (attr, 0);
       prop->kind = PROP_CONST;
@@ -17843,7 +17843,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 
   LONGEST bias = 0;
   struct attribute *bias_attr = dwarf2_attr (die, DW_AT_GNU_bias, cu);
-  if (bias_attr != nullptr && attr_form_is_constant (bias_attr))
+  if (bias_attr != nullptr && bias_attr->form_is_constant ())
     bias = dwarf2_get_attr_constant_value (bias_attr, 0);
 
   /* Normally, the DWARF producers are expected to use a signed
@@ -18521,12 +18521,12 @@ partial_die_info::read (const struct die_reader_specs *reader,
 	  break;
 	case DW_AT_low_pc:
 	  has_low_pc_attr = 1;
-	  lowpc = attr_value_as_address (&attr);
+	  lowpc = attr.value_as_address ();
 	  break;
 	case DW_AT_high_pc:
 	  has_high_pc_attr = 1;
-	  highpc = attr_value_as_address (&attr);
-	  if (cu->header.version >= 4 && attr_form_is_constant (&attr))
+	  highpc = attr.value_as_address ();
+	  if (cu->header.version >= 4 && attr.form_is_constant ())
 		high_pc_relative = 1;
 	  break;
 	case DW_AT_location:
@@ -18535,7 +18535,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
             {
 	       d.locdesc = DW_BLOCK (&attr);
             }
-          else if (attr_form_is_section_offset (&attr))
+          else if (attr.form_is_section_offset ())
             {
 	      dwarf2_complex_location_expr_complaint ();
             }
@@ -19207,7 +19207,7 @@ read_attribute_value (const struct die_reader_specs *reader,
     }
 
   /* Super hack.  */
-  if (cu->per_cu->is_dwz && attr_form_is_ref (attr))
+  if (cu->per_cu->is_dwz && attr->form_is_ref ())
     attr->form = DW_FORM_GNU_ref_alt;
 
   /* We have seen instances where the compiler tried to emit a byte
@@ -21321,7 +21321,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
 	    {
 	      CORE_ADDR addr;
 
-	      addr = attr_value_as_address (attr);
+	      addr = attr->value_as_address ();
 	      addr = gdbarch_adjust_dwarf2_addr (gdbarch, addr + baseaddr);
 	      SET_SYMBOL_VALUE_ADDRESS (sym, addr);
 	    }
@@ -21939,7 +21939,7 @@ lookup_die_type (struct die_info *die, const struct attribute *attr,
 						 dwarf2_per_objfile);
       this_type = get_die_type_at_offset (sect_off, per_cu);
     }
-  else if (attr_form_is_ref (attr))
+  else if (attr->form_is_ref ())
     {
       sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
 
@@ -21967,7 +21967,7 @@ lookup_die_type (struct die_info *die, const struct attribute *attr,
       struct die_info *type_die = NULL;
       struct dwarf2_cu *type_cu = cu;
 
-      if (attr_form_is_ref (attr))
+      if (attr->form_is_ref ())
 	type_die = follow_die_ref (die, attr, &type_cu);
       if (type_die == NULL)
 	return build_error_marker_type (cu, die);
@@ -22871,7 +22871,7 @@ store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
 static sect_offset
 dwarf2_get_ref_die_offset (const struct attribute *attr)
 {
-  if (attr_form_is_ref (attr))
+  if (attr->form_is_ref ())
     return (sect_offset) DW_UNSND (attr);
 
   complaint (_("unsupported die ref attribute form: '%s'"),
@@ -22895,7 +22895,7 @@ dwarf2_get_attr_constant_value (const struct attribute *attr, int default_value)
     return DW_UNSND (attr);
   else
     {
-      /* For DW_FORM_data16 see attr_form_is_constant.  */
+      /* For DW_FORM_data16 see attribute::form_is_constant.  */
       complaint (_("Attribute value is not a constant (%s)"),
                  dwarf_form_name (attr->form));
       return default_value;
@@ -22912,7 +22912,7 @@ follow_die_ref_or_sig (struct die_info *src_die, const struct attribute *attr,
 {
   struct die_info *die;
 
-  if (attr_form_is_ref (attr))
+  if (attr->form_is_ref ())
     die = follow_die_ref (src_die, attr, ref_cu);
   else if (attr->form == DW_FORM_ref_sig8)
     die = follow_die_sig (src_die, attr, ref_cu);
@@ -23086,7 +23086,7 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
       retval.data = NULL;
       retval.size = 0;
     }
-  else if (attr_form_is_section_offset (attr))
+  else if (attr->form_is_section_offset ())
     {
       struct dwarf2_loclist_baton loclist_baton;
       CORE_ADDR pc = (*get_frame_pc) (baton);
@@ -23474,7 +23474,7 @@ get_DW_AT_signature_type (struct die_info *die, const struct attribute *attr,
 			  struct dwarf2_cu *cu) /* ARI: editCase function */
 {
   /* Yes, DW_AT_signature can use a non-ref_sig8 reference.  */
-  if (attr_form_is_ref (attr))
+  if (attr->form_is_ref ())
     {
       struct dwarf2_cu *type_cu = cu;
       struct die_info *type_die = follow_die_ref (die, attr, &type_cu);
@@ -24828,7 +24828,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct dwarf2_section_info *section = cu_debug_loc_section (cu);
 
-  if (attr_form_is_section_offset (attr)
+  if (attr->form_is_section_offset ()
       /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
 	 the section.  If so, fall through to the complaint in the
 	 other branch.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 32/38] Move read_offset_1 to leb.c
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (7 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 05/38] Create dwarf2/attribute.[ch] Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 22/38] Minor simplification in abbrev_table::read Tom Tromey
                   ` (29 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves read_offset_1 to leb.c, as it is a low-level data-reading
function.  It is also renamed to remove the "_1", because gdb can use
overloading now, and this is clearer.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_offset_1): Move to leb.c.
	(read_abbrev_offset, read_offset, dwarf_decode_line_header)
	(dwarf_decode_macro_bytes): Update.
	* dwarf2/leb.c (read_offset): Rename; move from read.c.
	* dwarf2/leb.h (read_offset): Declare.

Change-Id: I048140598acfa76eade2cc529ab7933d4b9ca0b3
---
 gdb/ChangeLog     |  8 ++++++++
 gdb/dwarf2/leb.c  | 24 ++++++++++++++++++++++++
 gdb/dwarf2/leb.h  |  4 ++++
 gdb/dwarf2/read.c | 36 +++++-------------------------------
 4 files changed, 41 insertions(+), 31 deletions(-)

diff --git a/gdb/dwarf2/leb.c b/gdb/dwarf2/leb.c
index ef7314ed2b3..02faaa9954d 100644
--- a/gdb/dwarf2/leb.c
+++ b/gdb/dwarf2/leb.c
@@ -110,3 +110,27 @@ read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int *bytes_read,
 
   return length;
 }
+
+/* See leb.h.  */
+
+LONGEST
+read_offset (bfd *abfd, const gdb_byte *buf, unsigned int offset_size)
+{
+  LONGEST retval = 0;
+
+  switch (offset_size)
+    {
+    case 4:
+      retval = bfd_get_32 (abfd, buf);
+      break;
+    case 8:
+      retval = bfd_get_64 (abfd, buf);
+      break;
+    default:
+      internal_error (__FILE__, __LINE__,
+		      _("read_offset_1: bad switch [in module %s]"),
+		      bfd_get_filename (abfd));
+    }
+
+  return retval;
+}
diff --git a/gdb/dwarf2/leb.h b/gdb/dwarf2/leb.h
index 29fdffebfec..9c30cbea734 100644
--- a/gdb/dwarf2/leb.h
+++ b/gdb/dwarf2/leb.h
@@ -130,4 +130,8 @@ extern LONGEST read_initial_length (bfd *abfd, const gdb_byte *buf,
 				    unsigned int *bytes_read,
 				    bool handle_nonstd = true);
 
+/* Read an offset from the data stream.  */
+extern LONGEST read_offset (bfd *abfd, const gdb_byte *buf,
+			    unsigned int offset_size);
+
 #endif /* GDB_DWARF2_LEB_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 9db6529c4b8..9ab3dc24938 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1290,8 +1290,6 @@ static LONGEST read_offset (bfd *, const gdb_byte *,
 			    const struct comp_unit_head *,
 			    unsigned int *);
 
-static LONGEST read_offset_1 (bfd *, const gdb_byte *, unsigned int);
-
 static sect_offset read_abbrev_offset
   (struct dwarf2_per_objfile *dwarf2_per_objfile,
    struct dwarf2_section_info *, sect_offset);
@@ -6150,7 +6148,7 @@ read_abbrev_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
       info_ptr += 2;
     }
 
-  return (sect_offset) read_offset_1 (abfd, info_ptr, offset_size);
+  return (sect_offset) read_offset (abfd, info_ptr, offset_size);
 }
 
 /* Allocate a new partial symtab for file named NAME and mark this new
@@ -19078,36 +19076,12 @@ read_offset (bfd *abfd, const gdb_byte *buf,
 	     const struct comp_unit_head *cu_header,
              unsigned int *bytes_read)
 {
-  LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size);
+  LONGEST offset = read_offset (abfd, buf, cu_header->offset_size);
 
   *bytes_read = cu_header->offset_size;
   return offset;
 }
 
-/* Read an offset from the data stream.  */
-
-static LONGEST
-read_offset_1 (bfd *abfd, const gdb_byte *buf, unsigned int offset_size)
-{
-  LONGEST retval = 0;
-
-  switch (offset_size)
-    {
-    case 4:
-      retval = bfd_get_32 (abfd, buf);
-      break;
-    case 8:
-      retval = bfd_get_64 (abfd, buf);
-      break;
-    default:
-      internal_error (__FILE__, __LINE__,
-		      _("read_offset_1: bad switch [in module %s]"),
-		      bfd_get_filename (abfd));
-    }
-
-  return retval;
-}
-
 static const gdb_byte *
 read_n_bytes (bfd *abfd, const gdb_byte *buf, unsigned int size)
 {
@@ -19892,7 +19866,7 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
 	  return NULL;
 	}
     }
-  lh->header_length = read_offset_1 (abfd, line_ptr, offset_size);
+  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);
@@ -23965,7 +23939,7 @@ dwarf_decode_macro_bytes (struct dwarf2_cu *cu,
 	      {
 		LONGEST str_offset;
 
-		str_offset = read_offset_1 (abfd, mac_ptr, offset_size);
+		str_offset = read_offset (abfd, mac_ptr, offset_size);
 		mac_ptr += offset_size;
 
 		if (macinfo_type == DW_MACRO_define_sup
@@ -24105,7 +24079,7 @@ dwarf_decode_macro_bytes (struct dwarf2_cu *cu,
 	    int is_dwz = section_is_dwz;
 	    const gdb_byte *new_mac_ptr;
 
-	    offset = read_offset_1 (abfd, mac_ptr, offset_size);
+	    offset = read_offset (abfd, mac_ptr, offset_size);
 	    mac_ptr += offset_size;
 
 	    if (macinfo_type == DW_MACRO_import_sup)
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 34/38] Convert read_offset to method on comp_unit_head
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (11 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 02/38] Create dwarf2/section.[ch] Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 21/38] Use htab_up in abbrev_table Tom Tromey
                   ` (25 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes one of the read_offset overloads to be a method on
comp_unit_head.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_attribute_value, read_indirect_string)
	(read_indirect_line_string): Update.
	* dwarf2/comp-unit.c (read_offset): Remove.
	(read_comp_unit_head): Update.
	* dwarf2/comp-unit.h (struct comp_unit_head) <read_offset>: New
	method.
	(read_offset): Don't declare.

Change-Id: Ia595702a5748337b7c031352bc437956baab9990
---
 gdb/ChangeLog          | 10 ++++++++++
 gdb/dwarf2/comp-unit.c | 20 +++-----------------
 gdb/dwarf2/comp-unit.h | 18 +++++++++++-------
 gdb/dwarf2/read.c      | 16 ++++++++--------
 4 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/gdb/dwarf2/comp-unit.c b/gdb/dwarf2/comp-unit.c
index 03e804b7086..847a148cbd2 100644
--- a/gdb/dwarf2/comp-unit.c
+++ b/gdb/dwarf2/comp-unit.c
@@ -129,9 +129,8 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
       cu_header->addr_size = read_1_byte (abfd, info_ptr);
       info_ptr += 1;
     }
-  cu_header->abbrev_sect_off = (sect_offset) read_offset (abfd, info_ptr,
-							  cu_header,
-							  &bytes_read);
+  cu_header->abbrev_sect_off
+    = (sect_offset) cu_header->read_offset (abfd, info_ptr, &bytes_read);
   info_ptr += bytes_read;
   if (cu_header->version < 5)
     {
@@ -157,7 +156,7 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
   if (section_kind == rcuh_kind::TYPE)
     {
       LONGEST type_offset;
-      type_offset = read_offset (abfd, info_ptr, cu_header, &bytes_read);
+      type_offset = cu_header->read_offset (abfd, info_ptr, &bytes_read);
       info_ptr += bytes_read;
       cu_header->type_cu_offset_in_tu = (cu_offset) type_offset;
       if (to_underlying (cu_header->type_cu_offset_in_tu) != type_offset)
@@ -222,16 +221,3 @@ read_and_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   return info_ptr;
 }
-
-/* See comp-unit.h.  */
-
-LONGEST
-read_offset (bfd *abfd, const gdb_byte *buf,
-	     const struct comp_unit_head *cu_header,
-             unsigned int *bytes_read)
-{
-  LONGEST offset = read_offset (abfd, buf, cu_header->offset_size);
-
-  *bytes_read = cu_header->offset_size;
-  return offset;
-}
diff --git a/gdb/dwarf2/comp-unit.h b/gdb/dwarf2/comp-unit.h
index b4483ac1f7a..e61b1000b9e 100644
--- a/gdb/dwarf2/comp-unit.h
+++ b/gdb/dwarf2/comp-unit.h
@@ -27,6 +27,7 @@
 #ifndef GDB_DWARF2_COMP_UNIT_H
 #define GDB_DWARF2_COMP_UNIT_H
 
+#include "dwarf2/leb.h"
 #include "gdbtypes.h"
 
 /* The data in a compilation unit header, after target2host
@@ -78,6 +79,16 @@ struct comp_unit_head
     sect_offset top = sect_off + get_length ();
     return off >= bottom && off < top;
   }
+
+  /* Read an offset from the data stream.  The size of the offset is
+     given by cu_header->offset_size.  */
+  LONGEST read_offset (bfd *abfd, const gdb_byte *buf,
+		       unsigned int *bytes_read) const
+  {
+    LONGEST offset = ::read_offset (abfd, buf, offset_size);
+    *bytes_read = offset_size;
+    return offset;
+  }
 };
 
 /* Expected enum dwarf_unit_type for read_comp_unit_head.  */
@@ -104,11 +115,4 @@ extern const gdb_byte *read_and_check_comp_unit_head
    const gdb_byte *info_ptr,
    rcuh_kind section_kind);
 
-/* Read an offset from the data stream.  The size of the offset is
-   given by cu_header->offset_size.  */
-
-extern LONGEST read_offset (bfd *abfd, const gdb_byte *buf,
-			    const struct comp_unit_head *cu_header,
-			    unsigned int *bytes_read);
-
 #endif /* GDB_DWARF2_COMP_UNIT_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index b7401d408ce..7c0d1d21cb6 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18493,12 +18493,12 @@ read_attribute_value (const struct die_reader_specs *reader,
       if (cu->header.version == 2)
 	DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
       else
-	DW_UNSND (attr) = read_offset (abfd, info_ptr,
-				       &cu->header, &bytes_read);
+	DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr,
+						  &bytes_read);
       info_ptr += bytes_read;
       break;
     case DW_FORM_GNU_ref_alt:
-      DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
+      DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr, &bytes_read);
       info_ptr += bytes_read;
       break;
     case DW_FORM_addr:
@@ -18542,7 +18542,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       DW_BLOCK (attr) = blk;
       break;
     case DW_FORM_sec_offset:
-      DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read);
+      DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr, &bytes_read);
       info_ptr += bytes_read;
       break;
     case DW_FORM_string:
@@ -18575,8 +18575,8 @@ read_attribute_value (const struct die_reader_specs *reader,
     case DW_FORM_GNU_strp_alt:
       {
 	struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
-	LONGEST str_offset = read_offset (abfd, info_ptr, cu_header,
-					  &bytes_read);
+	LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
+						     &bytes_read);
 
 	DW_STRING (attr) = read_indirect_string_from_dwz (objfile,
 							  dwz, str_offset);
@@ -18937,7 +18937,7 @@ read_indirect_string (struct dwarf2_per_objfile *dwarf2_per_objfile, bfd *abfd,
 		      const struct comp_unit_head *cu_header,
 		      unsigned int *bytes_read_ptr)
 {
-  LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
+  LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr);
 
   return read_indirect_string_at_offset (dwarf2_per_objfile, abfd, str_offset);
 }
@@ -18952,7 +18952,7 @@ read_indirect_line_string (struct dwarf2_per_objfile *dwarf2_per_objfile,
 			   const struct comp_unit_head *cu_header,
 			   unsigned int *bytes_read_ptr)
 {
-  LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr);
+  LONGEST str_offset = cu_header->read_offset (abfd, buf, bytes_read_ptr);
 
   return read_indirect_line_string_at_offset (dwarf2_per_objfile, abfd,
 					      str_offset);
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 07/38] Change attr_form_is_block to be a method
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
  2020-01-23  0:57 ` [PATCH 35/38] Convert read_address to a method on comp_unit_head Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 16/38] Change dwarf2_per_objfile::line_header_hash to htab_up Tom Tromey
                   ` (36 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes attr_form_is_block to be a method.  This is done
separately because, unlike the other attribute functions,
attr_form_is_block had special handling for the case where the
argument was NULL.  This required auditing each call site; in most
cases, NULL was already ruled out, but in a few spots, an additional
check was needed.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (read_call_site_scope)
	(handle_data_member_location, dwarf2_add_member_fn)
	(mark_common_block_symbol_computed, read_common_block)
	(attr_to_dynamic_prop, partial_die_info::read)
	(var_decode_location, dwarf2_fetch_die_loc_sect_off)
	(dwarf2_symbol_mark_computed, set_die_type): Update.
	* dwarf2/attribute.h (struct attribute) <form_is_block>: Declare
	method.
	(attr_form_is_block): Don't declare.
	* dwarf2/attribute.c (attribute::form_is_block): Now a method.

Change-Id: Idfb290c61d738301ab991666f43e0b9cf577b2ae
---
 gdb/ChangeLog          | 13 +++++++++++++
 gdb/dwarf2/attribute.c | 15 +++++++--------
 gdb/dwarf2/attribute.h | 10 +++++-----
 gdb/dwarf2read.c       | 40 ++++++++++++++++++++--------------------
 4 files changed, 45 insertions(+), 33 deletions(-)

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 6e51fff5362..6efff3e2c0a 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -59,15 +59,14 @@ attribute::value_as_address () const
 
 /* See attribute.h.  */
 
-int
-attr_form_is_block (const struct attribute *attr)
+bool
+attribute::form_is_block () const
 {
-  return (attr == NULL ? 0 :
-      attr->form == DW_FORM_block1
-      || attr->form == DW_FORM_block2
-      || attr->form == DW_FORM_block4
-      || attr->form == DW_FORM_block
-      || attr->form == DW_FORM_exprloc);
+  return (form == DW_FORM_block1
+	  || form == DW_FORM_block2
+	  || form == DW_FORM_block4
+	  || form == DW_FORM_block
+	  || form == DW_FORM_exprloc);
 }
 
 /* See attribute.h.  */
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 2e663f1560c..c2602310715 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -79,6 +79,11 @@ struct attribute
 
   bool form_is_ref () const;
 
+  /* Check if the attribute's form is a DW_FORM_block*
+     if so return true else false.  */
+
+  bool form_is_block () const;
+
 
   ENUM_BITFIELD(dwarf_attribute) name : 16;
   ENUM_BITFIELD(dwarf_form) form : 15;
@@ -110,9 +115,4 @@ struct attribute
 #define DW_ADDR(attr)	   ((attr)->u.addr)
 #define DW_SIGNATURE(attr) ((attr)->u.signature)
 
-/* Check if the attribute's form is a DW_FORM_block*
-   if so return true else false.  */
-
-extern int attr_form_is_block (const struct attribute *attr);
-
 #endif /* GDB_DWARF2_ATTRIBUTE_H */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 87b8aaaf679..d5fc8e294f1 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -13738,9 +13738,9 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       attr = dwarf2_attr (die, DW_AT_abstract_origin, cu);
     }
   SET_FIELD_DWARF_BLOCK (call_site->target, NULL);
-  if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0))
+  if (!attr || (attr->form_is_block () && DW_BLOCK (attr)->size == 0))
     /* Keep NULL DWARF_BLOCK.  */;
-  else if (attr_form_is_block (attr))
+  else if (attr->form_is_block ())
     {
       struct dwarf2_locexpr_baton *dlbaton;
 
@@ -13846,7 +13846,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	  parameter->u.param_cu_off
 	    = (cu_offset) (sect_off - cu->header.sect_off);
 	}
-      else if (loc == NULL || origin != NULL || !attr_form_is_block (loc))
+      else if (loc == NULL || origin != NULL || !loc->form_is_block ())
 	{
 	  complaint (_("No DW_FORM_block* DW_AT_location for "
 		       "DW_TAG_call_site child DIE %s [in module %s]"),
@@ -13878,7 +13878,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
       attr = dwarf2_attr (child_die, DW_AT_call_value, cu);
       if (attr == NULL)
 	attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu);
-      if (!attr_form_is_block (attr))
+      if (attr == NULL || !attr->form_is_block ())
 	{
 	  complaint (_("No DW_FORM_block* DW_AT_call_value for "
 		       "DW_TAG_call_site child DIE %s [in module %s]"),
@@ -13899,7 +13899,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu);
       if (attr != nullptr)
 	{
-	  if (!attr_form_is_block (attr))
+	  if (!attr->form_is_block ())
 	    complaint (_("No DW_FORM_block* DW_AT_call_data_value for "
 			 "DW_TAG_call_site child DIE %s [in module %s]"),
 		       sect_offset_str (child_die->sect_off),
@@ -14672,7 +14672,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
 	*offset = dwarf2_get_attr_constant_value (attr, 0);
       else if (attr->form_is_section_offset ())
 	dwarf2_complex_location_expr_complaint ();
-      else if (attr_form_is_block (attr))
+      else if (attr->form_is_block ())
 	*offset = decode_locdesc (DW_BLOCK (attr), cu);
       else
 	dwarf2_complex_location_expr_complaint ();
@@ -15250,7 +15250,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu);
   if (attr != nullptr)
     {
-      if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0)
+      if (attr->form_is_block () && DW_BLOCK (attr)->size > 0)
         {
 	  if (DW_BLOCK (attr)->data[0] == DW_OP_constu)
 	    {
@@ -16461,8 +16461,8 @@ mark_common_block_symbol_computed (struct symbol *sym,
   LONGEST offset = 0;
 
   gdb_assert (common_loc && member_loc);
-  gdb_assert (attr_form_is_block (common_loc));
-  gdb_assert (attr_form_is_block (member_loc)
+  gdb_assert (common_loc->form_is_block ());
+  gdb_assert (member_loc->form_is_block ()
 	      || member_loc->form_is_constant ());
 
   baton = XOBNEW (&objfile->objfile_obstack, struct dwarf2_locexpr_baton);
@@ -16523,7 +16523,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
   if (attr != nullptr)
     {
       /* Support the .debug_loc offsets.  */
-      if (attr_form_is_block (attr))
+      if (attr->form_is_block ())
         {
 	  /* Ok.  */
         }
@@ -16591,7 +16591,7 @@ read_common_block (struct die_info *die, struct dwarf2_cu *cu)
 		  if (member_loc->form_is_section_offset ())
 		    dwarf2_complex_location_expr_complaint ();
 		  else if (member_loc->form_is_constant ()
-			   || attr_form_is_block (member_loc))
+			   || member_loc->form_is_block ())
 		    {
 		      if (attr != nullptr)
 			mark_common_block_symbol_computed (sym, die, attr,
@@ -17575,7 +17575,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
   if (attr == NULL || prop == NULL)
     return 0;
 
-  if (attr_form_is_block (attr))
+  if (attr->form_is_block ())
     {
       baton = XOBNEW (obstack, struct dwarf2_property_baton);
       baton->property_type = default_type;
@@ -17621,7 +17621,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
 		prop->kind = PROP_LOCLIST;
 		gdb_assert (prop->data.baton != NULL);
 	      }
-	    else if (attr_form_is_block (target_attr))
+	    else if (target_attr->form_is_block ())
 	      {
 		baton = XOBNEW (obstack, struct dwarf2_property_baton);
 		baton->property_type = die_type (target_die, target_cu);
@@ -18531,7 +18531,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
 	  break;
 	case DW_AT_location:
           /* Support the .debug_loc offsets.  */
-          if (attr_form_is_block (&attr))
+          if (attr.form_is_block ())
             {
 	       d.locdesc = DW_BLOCK (&attr);
             }
@@ -21174,7 +21174,7 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
 
   /* A DW_AT_location attribute with no contents indicates that a
      variable has been optimized away.  */
-  if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)
+  if (attr->form_is_block () && DW_BLOCK (attr)->size == 0)
     {
       SYMBOL_ACLASS_INDEX (sym) = LOC_OPTIMIZED_OUT;
       return;
@@ -21185,7 +21185,7 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
      specified.  If this is just a DW_OP_addr, DW_OP_addrx, or
      DW_OP_GNU_addr_index then mark this symbol as LOC_STATIC.  */
 
-  if (attr_form_is_block (attr)
+  if (attr->form_is_block ()
       && ((DW_BLOCK (attr)->data[0] == DW_OP_addr
 	   && DW_BLOCK (attr)->size == 1 + cu_header->addr_size)
 	  || ((DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index
@@ -23100,7 +23100,7 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
     }
   else
     {
-      if (!attr_form_is_block (attr))
+      if (!attr->form_is_block ())
 	error (_("Dwarf Error: DIE at %s referenced in module %s "
 		 "is neither DW_FORM_block* nor DW_FORM_exprloc"),
 	       sect_offset_str (sect_off), objfile_name (objfile));
@@ -24857,7 +24857,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
       baton->per_cu = cu->per_cu;
       gdb_assert (baton->per_cu);
 
-      if (attr_form_is_block (attr))
+      if (attr->form_is_block ())
 	{
 	  /* Note that we're just copying the block's data pointer
 	     here, not the actual data.  We're still pointing into the
@@ -25257,7 +25257,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
 
   /* Read DW_AT_allocated and set in type.  */
   attr = dwarf2_attr (die, DW_AT_allocated, cu);
-  if (attr_form_is_block (attr))
+  if (attr != NULL && attr->form_is_block ())
     {
       struct type *prop_type
 	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
@@ -25273,7 +25273,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
 
   /* Read DW_AT_associated and set in type.  */
   attr = dwarf2_attr (die, DW_AT_associated, cu);
-  if (attr_form_is_block (attr))
+  if (attr != NULL && attr->form_is_block ())
     {
       struct type *prop_type
 	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 15/38] Change dwarf2_per_objfile::type_unit_groups to htab_up
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (14 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 36/38] Move two more functions to dwarf2/leb.h Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 23/38] Change dwarf2_per_objfile::quick_file_names_table " Tom Tromey
                   ` (22 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes dwarf2_per_objfile::type_unit_groups to be an htab_up,
again allowing us to move the memory used by the hash table from the
objfile obstack to the heap.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (allocate_type_unit_groups_table): Return
	htab_up.  Don't allocate on obstack.
	(get_type_unit_group, dwarf2_build_psymtabs_hard): Update.
	* dwarf2/read.h (struct dwarf2_per_objfile) <type_unit_groups>:
	Change type to htab_up.

Change-Id: Ia045df0ff3ec30aac813da5a9a2314a607ef7ec8
---
 gdb/ChangeLog     |  8 ++++++++
 gdb/dwarf2/read.c | 17 +++++++----------
 gdb/dwarf2/read.h |  2 +-
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 10cbc7bd231..17f2640d0d4 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7527,16 +7527,13 @@ eq_type_unit_group (const void *item_lhs, const void *item_rhs)
 
 /* Allocate a hash table for type unit groups.  */
 
-static htab_t
+static htab_up
 allocate_type_unit_groups_table (struct objfile *objfile)
 {
-  return htab_create_alloc_ex (3,
-			       hash_type_unit_group,
-			       eq_type_unit_group,
-			       NULL,
-			       &objfile->objfile_obstack,
-			       hashtab_obstack_allocate,
-			       dummy_obstack_deallocate);
+  return htab_up (htab_create_alloc (3,
+				     hash_type_unit_group,
+				     eq_type_unit_group,
+				     NULL, xcalloc, xfree));
 }
 
 /* Type units that don't have DW_AT_stmt_list are grouped into their own
@@ -7632,7 +7629,7 @@ get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list)
 
   type_unit_group_for_lookup.hash.dwo_unit = cu->dwo_unit;
   type_unit_group_for_lookup.hash.line_sect_off = (sect_offset) line_offset;
-  slot = htab_find_slot (dwarf2_per_objfile->type_unit_groups,
+  slot = htab_find_slot (dwarf2_per_objfile->type_unit_groups.get (),
 			 &type_unit_group_for_lookup, INSERT);
   if (*slot != NULL)
     {
@@ -8201,7 +8198,7 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
   /* Now that all TUs have been processed we can fill in the dependencies.  */
   if (dwarf2_per_objfile->type_unit_groups != NULL)
     {
-      htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups,
+      htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups.get (),
 			      build_type_psymtab_dependencies, dwarf2_per_objfile);
     }
 
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 33ecb4a5911..9787127f99e 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -152,7 +152,7 @@ public:
 
   /* Table of struct type_unit_group objects.
      The hash key is the DW_AT_stmt_list value.  */
-  htab_t type_unit_groups {};
+  htab_up type_unit_groups;
 
   /* A table mapping .debug_types signatures to its signatured_type entry.
      This is NULL if the .debug_types section hasn't been read in yet.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 26/38] Change line_table methods to return unique_xmalloc_ptr
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (19 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 01/38] Create dwarf2/leb.[ch] Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 06/38] Change some attribute functions to be methods Tom Tromey
                   ` (17 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes the two new line_table methods to return
unique_xmalloc_ptr.  This removes a bit of manual memory management.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (struct line_header) <file_full_name,
	file_file_name>: Return unique_xmalloc_ptr.
	(line_header::file_file_name): Update.
	(line_header::file_full_name): Update.
	(dw2_get_file_names_reader): Update.
	(macro_start_file): Update.

Change-Id: I9442dba43882fb26097d0770a291eea2b03913a4
---
 gdb/ChangeLog     |  9 +++++++++
 gdb/dwarf2/read.c | 37 ++++++++++++++++++++-----------------
 2 files changed, 29 insertions(+), 17 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 153faac8238..b33f505362f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1078,13 +1078,14 @@ struct line_header
      table.  Use COMP_DIR as the name of the current directory of the
      compilation.  The result is allocated using xmalloc; the caller
      is responsible for freeing it.  */
-  char *file_full_name (int file, const char *comp_dir);
+  gdb::unique_xmalloc_ptr<char> file_full_name (int file,
+						const char *comp_dir);
 
   /* Return file name relative to the compilation directory of file
      number I in this object's file name table.  The result is
      allocated using xmalloc; the caller is responsible for freeing
      it.  */
-  char *file_file_name (int file);
+  gdb::unique_xmalloc_ptr<char> file_file_name (int file);
 
  private:
   /* The include_directories table.  Note these are observing
@@ -3410,7 +3411,8 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
   if (offset != 0)
     qfn->file_names[0] = xstrdup (fnd.name);
   for (int i = 0; i < lh->file_names_size (); ++i)
-    qfn->file_names[i + offset] = lh->file_full_name (i + 1, fnd.comp_dir);
+    qfn->file_names[i + offset] = lh->file_full_name (i + 1,
+						      fnd.comp_dir).release ();
   qfn->real_names = NULL;
 
   lh_cu->v.quick->file_names = qfn;
@@ -23797,7 +23799,7 @@ dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
 \f
 /* Macro support.  */
 
-char *
+gdb::unique_xmalloc_ptr<char>
 line_header::file_file_name (int file)
 {
   /* Is the file number a valid index into the line header's file name
@@ -23810,9 +23812,11 @@ line_header::file_file_name (int file)
 	{
 	  const char *dir = fe->include_dir (this);
 	  if (dir != NULL)
-	    return concat (dir, SLASH_STRING, fe->name, (char *) NULL);
+	    return gdb::unique_xmalloc_ptr<char> (concat (dir, SLASH_STRING,
+							  fe->name,
+							  (char *) NULL));
 	}
-      return xstrdup (fe->name);
+      return make_unique_xstrdup (fe->name);
     }
   else
     {
@@ -23827,23 +23831,24 @@ line_header::file_file_name (int file)
       complaint (_("bad file number in macro information (%d)"),
                  file);
 
-      return xstrdup (fake_name);
+      return make_unique_xstrdup (fake_name);
     }
 }
 
-char *
+gdb::unique_xmalloc_ptr<char>
 line_header::file_full_name (int file, const char *comp_dir)
 {
   /* Is the file number a valid index into the line header's file name
      table?  Remember that file numbers start with one, not zero.  */
   if (is_valid_file_index (file))
     {
-      char *relative = file_file_name (file);
+      gdb::unique_xmalloc_ptr<char> relative = file_file_name (file);
 
-      if (IS_ABSOLUTE_PATH (relative) || comp_dir == NULL)
+      if (IS_ABSOLUTE_PATH (relative.get ()) || comp_dir == NULL)
 	return relative;
-      return reconcat (relative, comp_dir, SLASH_STRING,
-		       relative, (char *) NULL);
+      return gdb::unique_xmalloc_ptr<char> (concat (comp_dir, SLASH_STRING,
+						    relative.get (),
+						    (char *) NULL));
     }
   else
     return file_file_name (file);
@@ -23857,7 +23862,7 @@ macro_start_file (struct dwarf2_cu *cu,
                   struct line_header *lh)
 {
   /* File name relative to the compilation directory of this source file.  */
-  char *file_name = lh->file_file_name (file);
+  gdb::unique_xmalloc_ptr<char> file_name = lh->file_file_name (file);
 
   if (! current_file)
     {
@@ -23867,13 +23872,11 @@ macro_start_file (struct dwarf2_cu *cu,
 
       /* If we have no current file, then this must be the start_file
 	 directive for the compilation unit's main source file.  */
-      current_file = macro_set_main (macro_table, file_name);
+      current_file = macro_set_main (macro_table, file_name.get ());
       macro_define_special (macro_table);
     }
   else
-    current_file = macro_include (current_file, line, file_name);
-
-  xfree (file_name);
+    current_file = macro_include (current_file, line, file_name.get ());
 
   return current_file;
 }
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 36/38] Move two more functions to dwarf2/leb.h
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (13 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 21/38] Use htab_up in abbrev_table Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 15/38] Change dwarf2_per_objfile::type_unit_groups to htab_up Tom Tromey
                   ` (23 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves read_n_bytes and read_direct_string to be with the the
low-level value-reading code.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_n_bytes, read_direct_string): Move to
	read.c.
	* dwarf2/leb.h (read_n_bytes, read_direct_string): Move from
	read.c.

Change-Id: Id07bfa13d93c0ac1f47a385749a8f01f4755b818
---
 gdb/ChangeLog     |  7 +++++++
 gdb/dwarf2/leb.h  | 27 +++++++++++++++++++++++++++
 gdb/dwarf2/read.c | 31 -------------------------------
 3 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/gdb/dwarf2/leb.h b/gdb/dwarf2/leb.h
index 9c30cbea734..f312fc261ee 100644
--- a/gdb/dwarf2/leb.h
+++ b/gdb/dwarf2/leb.h
@@ -134,4 +134,31 @@ extern LONGEST read_initial_length (bfd *abfd, const gdb_byte *buf,
 extern LONGEST read_offset (bfd *abfd, const gdb_byte *buf,
 			    unsigned int offset_size);
 
+static inline const gdb_byte *
+read_n_bytes (bfd *abfd, const gdb_byte *buf, unsigned int size)
+{
+  /* If the size of a host char is 8 bits, we can return a pointer
+     to the buffer, otherwise we have to copy the data to a buffer
+     allocated on the temporary obstack.  */
+  gdb_assert (HOST_CHAR_BIT == 8);
+  return buf;
+}
+
+static inline const char *
+read_direct_string (bfd *abfd, const gdb_byte *buf,
+		    unsigned int *bytes_read_ptr)
+{
+  /* If the size of a host char is 8 bits, we can return a pointer
+     to the string, otherwise we have to copy the string to a buffer
+     allocated on the temporary obstack.  */
+  gdb_assert (HOST_CHAR_BIT == 8);
+  if (*buf == '\0')
+    {
+      *bytes_read_ptr = 1;
+      return NULL;
+    }
+  *bytes_read_ptr = strlen ((const char *) buf) + 1;
+  return (const char *) buf;
+}
+
 #endif /* GDB_DWARF2_LEB_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index e47f7443a58..09840400cec 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1251,10 +1251,6 @@ static sect_offset read_abbrev_offset
   (struct dwarf2_per_objfile *dwarf2_per_objfile,
    struct dwarf2_section_info *, sect_offset);
 
-static const gdb_byte *read_n_bytes (bfd *, const gdb_byte *, unsigned int);
-
-static const char *read_direct_string (bfd *, const gdb_byte *, unsigned int *);
-
 static const char *read_indirect_string
   (struct dwarf2_per_objfile *dwarf2_per_objfile, bfd *, const gdb_byte *,
    const struct comp_unit_head *, unsigned int *);
@@ -18776,33 +18772,6 @@ read_checked_initial_length_and_offset (bfd *abfd, const gdb_byte *buf,
   return length;
 }
 
-static const gdb_byte *
-read_n_bytes (bfd *abfd, const gdb_byte *buf, unsigned int size)
-{
-  /* If the size of a host char is 8 bits, we can return a pointer
-     to the buffer, otherwise we have to copy the data to a buffer
-     allocated on the temporary obstack.  */
-  gdb_assert (HOST_CHAR_BIT == 8);
-  return buf;
-}
-
-static const char *
-read_direct_string (bfd *abfd, const gdb_byte *buf,
-		    unsigned int *bytes_read_ptr)
-{
-  /* If the size of a host char is 8 bits, we can return a pointer
-     to the string, otherwise we have to copy the string to a buffer
-     allocated on the temporary obstack.  */
-  gdb_assert (HOST_CHAR_BIT == 8);
-  if (*buf == '\0')
-    {
-      *bytes_read_ptr = 1;
-      return NULL;
-    }
-  *bytes_read_ptr = strlen ((const char *) buf) + 1;
-  return (const char *) buf;
-}
-
 /* Return pointer to string at section SECT offset STR_OFFSET with error
    reporting strings FORM_NAME and SECT_NAME.  */
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 01/38] Create dwarf2/leb.[ch]
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (18 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 08/38] Remove die_info_ptr typedef Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 26/38] Change line_table methods to return unique_xmalloc_ptr Tom Tromey
                   ` (18 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves some scalar-unpacking code into a couple of new files,
dwarf2/leb.h and dwarf2/leb.c.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (read_unsigned_leb128): Don't declare.
	* dwarf2read.c (read_1_byte, read_1_signed_byte, read_2_bytes)
	(read_2_signed_bytes, read_3_bytes, read_4_bytes)
	(read_4_signed_bytes, read_8_bytes): Move to dwarf2/leb.h.
	(read_unsigned_leb128, read_signed_leb128): Move to dwarf2/leb.c.
	* dwarf2/leb.h: New file, from dwarf2read.c.
	* dwarf2/leb.c: New file, from dwarf2read.c.
	* dwarf2-frame.c (read_1_byte, read_4_bytes, read_8_bytes):
	Remove.
	* Makefile.in (CONFIG_SRC_SUBDIR): Add dwarf2.
	(COMMON_SFILES): Add dwarf2/leb.c.

Change-Id: Idd19647686c8f959d226a95fdfca4db47c6e96d0
---
 gdb/ChangeLog      |  14 +++++
 gdb/Makefile.in    |   3 +-
 gdb/dwarf2-frame.c |  18 +------
 gdb/dwarf2/leb.c   |  85 +++++++++++++++++++++++++++++
 gdb/dwarf2/leb.h   |  92 ++++++++++++++++++++++++++++++++
 gdb/dwarf2loc.c    |   1 +
 gdb/dwarf2read.c   | 130 +--------------------------------------------
 gdb/dwarf2read.h   |   2 -
 8 files changed, 196 insertions(+), 149 deletions(-)
 create mode 100644 gdb/dwarf2/leb.c
 create mode 100644 gdb/dwarf2/leb.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 45d1586e85e..36d8523533a 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -551,7 +551,7 @@ CONFIG_INSTALL = @CONFIG_INSTALL@
 CONFIG_UNINSTALL = @CONFIG_UNINSTALL@
 HAVE_NATIVE_GCORE_TARGET = @HAVE_NATIVE_GCORE_TARGET@
 
-CONFIG_SRC_SUBDIR = arch cli mi compile tui unittests guile python \
+CONFIG_SRC_SUBDIR = arch cli dwarf2 mi compile tui unittests guile python \
 	target nat
 CONFIG_DEP_SUBDIR = $(addsuffix /$(DEPDIR),$(CONFIG_SRC_SUBDIR))
 
@@ -1002,6 +1002,7 @@ COMMON_SFILES = \
 	dwarf2expr.c \
 	dwarf2loc.c \
 	dwarf2read.c \
+	dwarf2/leb.c \
 	eval.c \
 	event-loop.c \
 	event-top.c \
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index a043d48217b..9daa66b0a29 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -22,6 +22,7 @@
 #include "defs.h"
 #include "dwarf2expr.h"
 #include "dwarf2.h"
+#include "dwarf2/leb.h"
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
@@ -1474,23 +1475,6 @@ const struct objfile_key<dwarf2_fde_table,
 			 gdb::noop_deleter<dwarf2_fde_table>>
   dwarf2_frame_objfile_data;
 
-static unsigned int
-read_1_byte (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_8 (abfd, buf);
-}
-
-static unsigned int
-read_4_bytes (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_32 (abfd, buf);
-}
-
-static ULONGEST
-read_8_bytes (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_64 (abfd, buf);
-}
 
 static ULONGEST
 read_initial_length (bfd *abfd, const gdb_byte *buf,
diff --git a/gdb/dwarf2/leb.c b/gdb/dwarf2/leb.c
new file mode 100644
index 00000000000..d26b48b381c
--- /dev/null
+++ b/gdb/dwarf2/leb.c
@@ -0,0 +1,85 @@
+/* Low-level DWARF 2 reading code
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "dwarf2/leb.h"
+
+ULONGEST
+read_unsigned_leb128 (bfd *abfd, const gdb_byte *buf,
+			  unsigned int *bytes_read_ptr)
+{
+  ULONGEST result;
+  unsigned int num_read;
+  int shift;
+  unsigned char byte;
+
+  result = 0;
+  shift = 0;
+  num_read = 0;
+  while (1)
+    {
+      byte = bfd_get_8 (abfd, buf);
+      buf++;
+      num_read++;
+      result |= ((ULONGEST) (byte & 127) << shift);
+      if ((byte & 128) == 0)
+	{
+	  break;
+	}
+      shift += 7;
+    }
+  *bytes_read_ptr = num_read;
+  return result;
+}
+
+LONGEST
+read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
+		    unsigned int *bytes_read_ptr)
+{
+  ULONGEST result;
+  int shift, num_read;
+  unsigned char byte;
+
+  result = 0;
+  shift = 0;
+  num_read = 0;
+  while (1)
+    {
+      byte = bfd_get_8 (abfd, buf);
+      buf++;
+      num_read++;
+      result |= ((ULONGEST) (byte & 127) << shift);
+      shift += 7;
+      if ((byte & 128) == 0)
+	{
+	  break;
+	}
+    }
+  if ((shift < 8 * sizeof (result)) && (byte & 0x40))
+    result |= -(((ULONGEST) 1) << shift);
+  *bytes_read_ptr = num_read;
+  return result;
+}
diff --git a/gdb/dwarf2/leb.h b/gdb/dwarf2/leb.h
new file mode 100644
index 00000000000..b17ab881ba2
--- /dev/null
+++ b/gdb/dwarf2/leb.h
@@ -0,0 +1,92 @@
+/* Low-level DWARF 2 reading code
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_DWARF2_LEB_H
+#define GDB_DWARF2_LEB_H
+
+/* Read dwarf information from a buffer.  */
+
+static inline unsigned int
+read_1_byte (bfd *abfd, const gdb_byte *buf)
+{
+  return bfd_get_8 (abfd, buf);
+}
+
+static inline int
+read_1_signed_byte (bfd *abfd, const gdb_byte *buf)
+{
+  return bfd_get_signed_8 (abfd, buf);
+}
+
+static inline unsigned int
+read_2_bytes (bfd *abfd, const gdb_byte *buf)
+{
+  return bfd_get_16 (abfd, buf);
+}
+
+static inline int
+read_2_signed_bytes (bfd *abfd, const gdb_byte *buf)
+{
+  return bfd_get_signed_16 (abfd, buf);
+}
+
+/* Read the next three bytes (little-endian order) as an unsigned integer.  */
+static inline unsigned int
+read_3_bytes (bfd *abfd, const gdb_byte *buf)
+{
+  unsigned int result = 0;
+  for (int i = 0; i < 3; ++i)
+    {
+      unsigned char byte = bfd_get_8 (abfd, buf);
+      buf++;
+      result |= ((unsigned int) byte << (i * 8));
+    }
+  return result;
+}
+
+static inline unsigned int
+read_4_bytes (bfd *abfd, const gdb_byte *buf)
+{
+  return bfd_get_32 (abfd, buf);
+}
+
+static inline int
+read_4_signed_bytes (bfd *abfd, const gdb_byte *buf)
+{
+  return bfd_get_signed_32 (abfd, buf);
+}
+
+static inline ULONGEST
+read_8_bytes (bfd *abfd, const gdb_byte *buf)
+{
+  return bfd_get_64 (abfd, buf);
+}
+
+extern LONGEST read_signed_leb128 (bfd *, const gdb_byte *, unsigned int *);
+
+extern ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
+
+#endif /* GDB_DWARF2_LEB_H */
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 405b239ed42..9cfc852c9e1 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -38,6 +38,7 @@
 #include "dwarf2loc.h"
 #include "dwarf2read.h"
 #include "dwarf2-frame.h"
+#include "dwarf2/leb.h"
 #include "compile/compile.h"
 #include "gdbsupport/selftest.h"
 #include <algorithm>
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index dfa2f91d450..e7a474d17a4 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -32,6 +32,7 @@
 #include "dwarf2read.h"
 #include "dwarf-index-cache.h"
 #include "dwarf-index-common.h"
+#include "dwarf2/leb.h"
 #include "bfd.h"
 #include "elf-bfd.h"
 #include "symtab.h"
@@ -1556,19 +1557,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 unsigned int read_1_byte (bfd *, const gdb_byte *);
-
-static int read_1_signed_byte (bfd *, const gdb_byte *);
-
-static unsigned int read_2_bytes (bfd *, const gdb_byte *);
-
-/* Read the next three bytes (little-endian order) as an unsigned integer.  */
-static unsigned int read_3_bytes (bfd *, const gdb_byte *);
-
-static unsigned int read_4_bytes (bfd *, const gdb_byte *);
-
-static ULONGEST read_8_bytes (bfd *, const gdb_byte *);
-
 static CORE_ADDR read_address (bfd *, const gdb_byte *ptr, struct dwarf2_cu *,
 			       unsigned int *);
 
@@ -1607,8 +1595,6 @@ static const char *read_indirect_string_at_offset
 static const char *read_indirect_string_from_dwz
   (struct objfile *objfile, struct dwz_file *, LONGEST);
 
-static LONGEST read_signed_leb128 (bfd *, const gdb_byte *, unsigned int *);
-
 static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *,
 					      const gdb_byte *,
 					      unsigned int *);
@@ -19730,63 +19716,6 @@ read_attribute (const struct die_reader_specs *reader,
 			       need_reprocess);
 }
 
-/* Read dwarf information from a buffer.  */
-
-static unsigned int
-read_1_byte (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_8 (abfd, buf);
-}
-
-static int
-read_1_signed_byte (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_signed_8 (abfd, buf);
-}
-
-static unsigned int
-read_2_bytes (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_16 (abfd, buf);
-}
-
-static int
-read_2_signed_bytes (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_signed_16 (abfd, buf);
-}
-
-static unsigned int
-read_3_bytes (bfd *abfd, const gdb_byte *buf)
-{
-  unsigned int result = 0;
-  for (int i = 0; i < 3; ++i)
-    {
-      unsigned char byte = bfd_get_8 (abfd, buf);
-      buf++;
-      result |= ((unsigned int) byte << (i * 8));
-    }
-  return result;
-}
-
-static unsigned int
-read_4_bytes (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_32 (abfd, buf);
-}
-
-static int
-read_4_signed_bytes (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_signed_32 (abfd, buf);
-}
-
-static ULONGEST
-read_8_bytes (bfd *abfd, const gdb_byte *buf)
-{
-  return bfd_get_64 (abfd, buf);
-}
-
 static CORE_ADDR
 read_address (bfd *abfd, const gdb_byte *buf, struct dwarf2_cu *cu,
 	      unsigned int *bytes_read)
@@ -20096,63 +20025,6 @@ read_indirect_line_string (struct dwarf2_per_objfile *dwarf2_per_objfile,
 					      str_offset);
 }
 
-ULONGEST
-read_unsigned_leb128 (bfd *abfd, const gdb_byte *buf,
-			  unsigned int *bytes_read_ptr)
-{
-  ULONGEST result;
-  unsigned int num_read;
-  int shift;
-  unsigned char byte;
-
-  result = 0;
-  shift = 0;
-  num_read = 0;
-  while (1)
-    {
-      byte = bfd_get_8 (abfd, buf);
-      buf++;
-      num_read++;
-      result |= ((ULONGEST) (byte & 127) << shift);
-      if ((byte & 128) == 0)
-	{
-	  break;
-	}
-      shift += 7;
-    }
-  *bytes_read_ptr = num_read;
-  return result;
-}
-
-static LONGEST
-read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
-		    unsigned int *bytes_read_ptr)
-{
-  ULONGEST result;
-  int shift, num_read;
-  unsigned char byte;
-
-  result = 0;
-  shift = 0;
-  num_read = 0;
-  while (1)
-    {
-      byte = bfd_get_8 (abfd, buf);
-      buf++;
-      num_read++;
-      result |= ((ULONGEST) (byte & 127) << shift);
-      shift += 7;
-      if ((byte & 128) == 0)
-	{
-	  break;
-	}
-    }
-  if ((shift < 8 * sizeof (result)) && (byte & 0x40))
-    result |= -(((ULONGEST) 1) << shift);
-  *bytes_read_ptr = num_read;
-  return result;
-}
-
 /* Given index ADDR_INDEX in .debug_addr, fetch the value.
    ADDR_BASE is the DW_AT_addr_base (DW_AT_GNU_addr_base) attribute or zero.
    ADDR_SIZE is the size of addresses from the CU header.  */
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index bc8087ba406..7961ffe10c2 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -442,8 +442,6 @@ struct signatured_type
   struct dwo_unit *dwo_unit;
 };
 
-ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned int *);
-
 /* This represents a '.dwz' file.  */
 
 struct dwz_file
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 25/38] Change file_full_name and file_file_name methods
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (23 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 14/38] Change dwarf2_per_objfile::signatured_types to be htab_up Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-27 13:31   ` Christian Biesinger via gdb-patches
  2020-01-23  0:57 ` [PATCH 18/38] Change dwp_file to use htab_up Tom Tromey
                   ` (13 subsequent siblings)
  38 siblings, 1 reply; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes file_full_name and file_file_name methods to be methods
on line_header.  This seems more clear to me.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (struct line_header) <file_full_name,
	file_file_name>: Declare methods.
	(dw2_get_file_names_reader): Update.
	(file_file_name): Now a method.
	(file_full_name): Likewise.
	(macro_start_file): Update.

Change-Id: I50d3e91665a9637c732e1e8d8e4263764c766d9c
---
 gdb/ChangeLog     |  9 +++++++++
 gdb/dwarf2/read.c | 47 ++++++++++++++++++++++++-----------------------
 2 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index c230778980e..153faac8238 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1074,6 +1074,18 @@ struct line_header
      header.  These point into dwarf2_per_objfile->line_buffer.  */
   const gdb_byte *statement_program_start {}, *statement_program_end {};
 
+  /* Return the full name of file number I in this object's file name
+     table.  Use COMP_DIR as the name of the current directory of the
+     compilation.  The result is allocated using xmalloc; the caller
+     is responsible for freeing it.  */
+  char *file_full_name (int file, const char *comp_dir);
+
+  /* Return file name relative to the compilation directory of file
+     number I in this object's file name table.  The result is
+     allocated using xmalloc; the caller is responsible for freeing
+     it.  */
+  char *file_file_name (int file);
+
  private:
   /* The include_directories table.  Note these are observing
      pointers.  The memory is owned by debug_line_buffer.  */
@@ -1860,9 +1872,6 @@ struct file_and_directory
 static file_and_directory find_file_and_directory (struct die_info *die,
 						   struct dwarf2_cu *cu);
 
-static char *file_full_name (int file, struct line_header *lh,
-			     const char *comp_dir);
-
 /* Expected enum dwarf_unit_type for read_comp_unit_head.  */
 enum class rcuh_kind { COMPILE, TYPE };
 
@@ -3401,7 +3410,7 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
   if (offset != 0)
     qfn->file_names[0] = xstrdup (fnd.name);
   for (int i = 0; i < lh->file_names_size (); ++i)
-    qfn->file_names[i + offset] = file_full_name (i + 1, lh.get (), fnd.comp_dir);
+    qfn->file_names[i + offset] = lh->file_full_name (i + 1, fnd.comp_dir);
   qfn->real_names = NULL;
 
   lh_cu->v.quick->file_names = qfn;
@@ -23788,22 +23797,18 @@ dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
 \f
 /* Macro support.  */
 
-/* Return file name relative to the compilation directory of file number I in
-   *LH's file name table.  The result is allocated using xmalloc; the caller is
-   responsible for freeing it.  */
-
-static char *
-file_file_name (int file, struct line_header *lh)
+char *
+line_header::file_file_name (int file)
 {
   /* Is the file number a valid index into the line header's file name
      table?  Remember that file numbers start with one, not zero.  */
-  if (lh->is_valid_file_index (file))
+  if (is_valid_file_index (file))
     {
-      const file_entry *fe = lh->file_name_at (file);
+      const file_entry *fe = file_name_at (file);
 
       if (!IS_ABSOLUTE_PATH (fe->name))
 	{
-	  const char *dir = fe->include_dir (lh);
+	  const char *dir = fe->include_dir (this);
 	  if (dir != NULL)
 	    return concat (dir, SLASH_STRING, fe->name, (char *) NULL);
 	}
@@ -23826,18 +23831,14 @@ file_file_name (int file, struct line_header *lh)
     }
 }
 
-/* Return the full name of file number I in *LH's file name table.
-   Use COMP_DIR as the name of the current directory of the
-   compilation.  The result is allocated using xmalloc; the caller is
-   responsible for freeing it.  */
-static char *
-file_full_name (int file, struct line_header *lh, const char *comp_dir)
+char *
+line_header::file_full_name (int file, const char *comp_dir)
 {
   /* Is the file number a valid index into the line header's file name
      table?  Remember that file numbers start with one, not zero.  */
-  if (lh->is_valid_file_index (file))
+  if (is_valid_file_index (file))
     {
-      char *relative = file_file_name (file, lh);
+      char *relative = file_file_name (file);
 
       if (IS_ABSOLUTE_PATH (relative) || comp_dir == NULL)
 	return relative;
@@ -23845,7 +23846,7 @@ file_full_name (int file, struct line_header *lh, const char *comp_dir)
 		       relative, (char *) NULL);
     }
   else
-    return file_file_name (file, lh);
+    return file_file_name (file);
 }
 
 
@@ -23856,7 +23857,7 @@ macro_start_file (struct dwarf2_cu *cu,
                   struct line_header *lh)
 {
   /* File name relative to the compilation directory of this source file.  */
-  char *file_name = file_file_name (file, lh);
+  char *file_name = lh->file_file_name (file);
 
   if (! current_file)
     {
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 02/38] Create dwarf2/section.[ch]
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (10 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 13/38] Remove DWARF queue-related globals Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 34/38] Convert read_offset to method on comp_unit_head Tom Tromey
                   ` (26 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves some section-handling code from dwarf2read.c into new
files, dwarf2/section.[ch].

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (struct dwarf2_section_info, dwarf2_read_section):
	Move to dwarf2/section.h.
	* dwarf2read.c (get_containing_section, get_section_bfd_owner)
	(get_section_bfd_section, get_section_name)
	(get_section_file_name, get_section_id, get_section_flags)
	(dwarf2_section_empty_p, dwarf2_read_section): Moe to
	dwarf2/section.c.
	* dwarf2/section.h: New file.
	* dwarf2/section.c: New file, from dwarf2read.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/section.c.

Change-Id: I9f8498094cf99d9521e9481622ce8adbd453daf4
---
 gdb/ChangeLog        |  13 ++++
 gdb/Makefile.in      |   1 +
 gdb/dwarf2/section.c | 179 +++++++++++++++++++++++++++++++++++++++++++
 gdb/dwarf2/section.h | 121 +++++++++++++++++++++++++++++
 gdb/dwarf2read.c     | 175 ------------------------------------------
 gdb/dwarf2read.h     |  49 +-----------
 6 files changed, 315 insertions(+), 223 deletions(-)
 create mode 100644 gdb/dwarf2/section.c
 create mode 100644 gdb/dwarf2/section.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 36d8523533a..c10ce71a50e 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1003,6 +1003,7 @@ COMMON_SFILES = \
 	dwarf2loc.c \
 	dwarf2read.c \
 	dwarf2/leb.c \
+	dwarf2/section.c \
 	eval.c \
 	event-loop.c \
 	event-top.c \
diff --git a/gdb/dwarf2/section.c b/gdb/dwarf2/section.c
new file mode 100644
index 00000000000..618ab9adf12
--- /dev/null
+++ b/gdb/dwarf2/section.c
@@ -0,0 +1,179 @@
+/* DWARF 2 low-level section code
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "dwarf2/section.h"
+#include "gdb_bfd.h"
+#include "objfiles.h"
+
+struct dwarf2_section_info *
+get_containing_section (const struct dwarf2_section_info *section)
+{
+  gdb_assert (section->is_virtual);
+  return section->s.containing_section;
+}
+
+struct bfd *
+get_section_bfd_owner (const struct dwarf2_section_info *section)
+{
+  if (section->is_virtual)
+    {
+      section = get_containing_section (section);
+      gdb_assert (!section->is_virtual);
+    }
+  return section->s.section->owner;
+}
+
+asection *
+get_section_bfd_section (const struct dwarf2_section_info *section)
+{
+  if (section->is_virtual)
+    {
+      section = get_containing_section (section);
+      gdb_assert (!section->is_virtual);
+    }
+  return section->s.section;
+}
+
+const char *
+get_section_name (const struct dwarf2_section_info *section)
+{
+  asection *sectp = get_section_bfd_section (section);
+
+  gdb_assert (sectp != NULL);
+  return bfd_section_name (sectp);
+}
+
+const char *
+get_section_file_name (const struct dwarf2_section_info *section)
+{
+  bfd *abfd = get_section_bfd_owner (section);
+
+  return bfd_get_filename (abfd);
+}
+
+int
+get_section_id (const struct dwarf2_section_info *section)
+{
+  asection *sectp = get_section_bfd_section (section);
+
+  if (sectp == NULL)
+    return 0;
+  return sectp->id;
+}
+
+int
+get_section_flags (const struct dwarf2_section_info *section)
+{
+  asection *sectp = get_section_bfd_section (section);
+
+  gdb_assert (sectp != NULL);
+  return bfd_section_flags (sectp);
+}
+
+int
+dwarf2_section_empty_p (const struct dwarf2_section_info *section)
+{
+  if (section->is_virtual)
+    return section->size == 0;
+  return section->s.section == NULL || section->size == 0;
+}
+
+void
+dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
+{
+  asection *sectp;
+  bfd *abfd;
+  gdb_byte *buf, *retbuf;
+
+  if (info->readin)
+    return;
+  info->buffer = NULL;
+  info->readin = true;
+
+  if (dwarf2_section_empty_p (info))
+    return;
+
+  sectp = get_section_bfd_section (info);
+
+  /* If this is a virtual section we need to read in the real one first.  */
+  if (info->is_virtual)
+    {
+      struct dwarf2_section_info *containing_section =
+	get_containing_section (info);
+
+      gdb_assert (sectp != NULL);
+      if ((sectp->flags & SEC_RELOC) != 0)
+	{
+	  error (_("Dwarf Error: DWP format V2 with relocations is not"
+		   " supported in section %s [in module %s]"),
+		 get_section_name (info), get_section_file_name (info));
+	}
+      dwarf2_read_section (objfile, containing_section);
+      /* Other code should have already caught virtual sections that don't
+	 fit.  */
+      gdb_assert (info->virtual_offset + info->size
+		  <= containing_section->size);
+      /* If the real section is empty or there was a problem reading the
+	 section we shouldn't get here.  */
+      gdb_assert (containing_section->buffer != NULL);
+      info->buffer = containing_section->buffer + info->virtual_offset;
+      return;
+    }
+
+  /* If the section has relocations, we must read it ourselves.
+     Otherwise we attach it to the BFD.  */
+  if ((sectp->flags & SEC_RELOC) == 0)
+    {
+      info->buffer = gdb_bfd_map_section (sectp, &info->size);
+      return;
+    }
+
+  buf = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, info->size);
+  info->buffer = buf;
+
+  /* When debugging .o files, we may need to apply relocations; see
+     http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
+     We never compress sections in .o files, so we only need to
+     try this when the section is not compressed.  */
+  retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
+  if (retbuf != NULL)
+    {
+      info->buffer = retbuf;
+      return;
+    }
+
+  abfd = get_section_bfd_owner (info);
+  gdb_assert (abfd != NULL);
+
+  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
+      || bfd_bread (buf, info->size, abfd) != info->size)
+    {
+      error (_("Dwarf Error: Can't read DWARF data"
+	       " in section %s [in module %s]"),
+	     bfd_section_name (sectp), bfd_get_filename (abfd));
+    }
+}
diff --git a/gdb/dwarf2/section.h b/gdb/dwarf2/section.h
new file mode 100644
index 00000000000..a1acc5f9e66
--- /dev/null
+++ b/gdb/dwarf2/section.h
@@ -0,0 +1,121 @@
+/* DWARF 2 low-level section code
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_DWARF2_SECTION_H
+#define GDB_DWARF2_SECTION_H
+
+/* A descriptor for dwarf sections.
+
+   S.ASECTION, SIZE are typically initialized when the objfile is first
+   scanned.  BUFFER, READIN are filled in later when the section is read.
+   If the section contained compressed data then SIZE is updated to record
+   the uncompressed size of the section.
+
+   DWP file format V2 introduces a wrinkle that is easiest to handle by
+   creating the concept of virtual sections contained within a real section.
+   In DWP V2 the sections of the input DWO files are concatenated together
+   into one section, but section offsets are kept relative to the original
+   input section.
+   If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
+   the real section this "virtual" section is contained in, and BUFFER,SIZE
+   describe the virtual section.  */
+
+struct dwarf2_section_info
+{
+  union
+  {
+    /* If this is a real section, the bfd section.  */
+    asection *section;
+    /* If this is a virtual section, pointer to the containing ("real")
+       section.  */
+    struct dwarf2_section_info *containing_section;
+  } s;
+  /* Pointer to section data, only valid if readin.  */
+  const gdb_byte *buffer;
+  /* The size of the section, real or virtual.  */
+  bfd_size_type size;
+  /* If this is a virtual section, the offset in the real section.
+     Only valid if is_virtual.  */
+  bfd_size_type virtual_offset;
+  /* True if we have tried to read this section.  */
+  bool readin;
+  /* True if this is a virtual section, False otherwise.
+     This specifies which of s.section and s.containing_section to use.  */
+  bool is_virtual;
+};
+
+/* 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
+   of the DWO file.
+   If the section is compressed, uncompress it before returning.  */
+
+extern void dwarf2_read_section (struct objfile *objfile,
+				 dwarf2_section_info *info);
+
+extern const char *get_section_name (const struct dwarf2_section_info *);
+
+extern const char *get_section_file_name (const struct dwarf2_section_info *);
+
+/* Return the containing section of virtual section SECTION.  */
+
+extern struct dwarf2_section_info *get_containing_section
+  (const struct dwarf2_section_info *section);
+
+/* Return the bfd owner of SECTION.  */
+
+extern struct bfd *get_section_bfd_owner
+  (const struct dwarf2_section_info *section);
+
+/* Return the bfd section of SECTION.
+   Returns NULL if the section is not present.  */
+
+extern asection *get_section_bfd_section
+  (const struct dwarf2_section_info *section);
+
+/* Return the name of SECTION.  */
+
+extern const char *get_section_name
+  (const struct dwarf2_section_info *section);
+
+/* Return the name of the file SECTION is in.  */
+
+extern const char *get_section_file_name
+  (const struct dwarf2_section_info *section);
+
+/* Return the id of SECTION.
+   Returns 0 if SECTION doesn't exist.  */
+
+extern int get_section_id (const struct dwarf2_section_info *section);
+
+/* Return the flags of SECTION.
+   SECTION (or containing section if this is a virtual section) must exist.  */
+
+extern int get_section_flags (const struct dwarf2_section_info *section);
+
+extern int dwarf2_section_empty_p (const struct dwarf2_section_info *section);
+
+#endif /* GDB_DWARF2_SECTION_H */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index e7a474d17a4..4eabda98be5 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -1474,10 +1474,6 @@ show_dwarf_max_cache_age (struct ui_file *file, int from_tty,
 \f
 /* local function prototypes */
 
-static const char *get_section_name (const struct dwarf2_section_info *);
-
-static const char *get_section_file_name (const struct dwarf2_section_info *);
-
 static void dwarf2_find_base_address (struct die_info *die,
 				      struct dwarf2_cu *cu);
 
@@ -2269,88 +2265,6 @@ dwarf2_has_info (struct objfile *objfile,
 	  && dwarf2_per_objfile->abbrev.s.section != NULL);
 }
 
-/* Return the containing section of virtual section SECTION.  */
-
-static struct dwarf2_section_info *
-get_containing_section (const struct dwarf2_section_info *section)
-{
-  gdb_assert (section->is_virtual);
-  return section->s.containing_section;
-}
-
-/* Return the bfd owner of SECTION.  */
-
-static struct bfd *
-get_section_bfd_owner (const struct dwarf2_section_info *section)
-{
-  if (section->is_virtual)
-    {
-      section = get_containing_section (section);
-      gdb_assert (!section->is_virtual);
-    }
-  return section->s.section->owner;
-}
-
-/* Return the bfd section of SECTION.
-   Returns NULL if the section is not present.  */
-
-static asection *
-get_section_bfd_section (const struct dwarf2_section_info *section)
-{
-  if (section->is_virtual)
-    {
-      section = get_containing_section (section);
-      gdb_assert (!section->is_virtual);
-    }
-  return section->s.section;
-}
-
-/* Return the name of SECTION.  */
-
-static const char *
-get_section_name (const struct dwarf2_section_info *section)
-{
-  asection *sectp = get_section_bfd_section (section);
-
-  gdb_assert (sectp != NULL);
-  return bfd_section_name (sectp);
-}
-
-/* Return the name of the file SECTION is in.  */
-
-static const char *
-get_section_file_name (const struct dwarf2_section_info *section)
-{
-  bfd *abfd = get_section_bfd_owner (section);
-
-  return bfd_get_filename (abfd);
-}
-
-/* Return the id of SECTION.
-   Returns 0 if SECTION doesn't exist.  */
-
-static int
-get_section_id (const struct dwarf2_section_info *section)
-{
-  asection *sectp = get_section_bfd_section (section);
-
-  if (sectp == NULL)
-    return 0;
-  return sectp->id;
-}
-
-/* Return the flags of SECTION.
-   SECTION (or containing section if this is a virtual section) must exist.  */
-
-static int
-get_section_flags (const struct dwarf2_section_info *section)
-{
-  asection *sectp = get_section_bfd_section (section);
-
-  gdb_assert (sectp != NULL);
-  return bfd_section_flags (sectp);
-}
-
 /* When loading sections, we look either for uncompressed section or for
    compressed section names.  */
 
@@ -2493,95 +2407,6 @@ dwarf2_per_objfile::locate_sections (bfd *abfd, asection *sectp,
     this->has_section_at_zero = true;
 }
 
-/* A helper function that decides whether a section is empty,
-   or not present.  */
-
-static int
-dwarf2_section_empty_p (const struct dwarf2_section_info *section)
-{
-  if (section->is_virtual)
-    return section->size == 0;
-  return section->s.section == NULL || section->size == 0;
-}
-
-/* See dwarf2read.h.  */
-
-void
-dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
-{
-  asection *sectp;
-  bfd *abfd;
-  gdb_byte *buf, *retbuf;
-
-  if (info->readin)
-    return;
-  info->buffer = NULL;
-  info->readin = true;
-
-  if (dwarf2_section_empty_p (info))
-    return;
-
-  sectp = get_section_bfd_section (info);
-
-  /* If this is a virtual section we need to read in the real one first.  */
-  if (info->is_virtual)
-    {
-      struct dwarf2_section_info *containing_section =
-	get_containing_section (info);
-
-      gdb_assert (sectp != NULL);
-      if ((sectp->flags & SEC_RELOC) != 0)
-	{
-	  error (_("Dwarf Error: DWP format V2 with relocations is not"
-		   " supported in section %s [in module %s]"),
-		 get_section_name (info), get_section_file_name (info));
-	}
-      dwarf2_read_section (objfile, containing_section);
-      /* Other code should have already caught virtual sections that don't
-	 fit.  */
-      gdb_assert (info->virtual_offset + info->size
-		  <= containing_section->size);
-      /* If the real section is empty or there was a problem reading the
-	 section we shouldn't get here.  */
-      gdb_assert (containing_section->buffer != NULL);
-      info->buffer = containing_section->buffer + info->virtual_offset;
-      return;
-    }
-
-  /* If the section has relocations, we must read it ourselves.
-     Otherwise we attach it to the BFD.  */
-  if ((sectp->flags & SEC_RELOC) == 0)
-    {
-      info->buffer = gdb_bfd_map_section (sectp, &info->size);
-      return;
-    }
-
-  buf = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, info->size);
-  info->buffer = buf;
-
-  /* When debugging .o files, we may need to apply relocations; see
-     http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
-     We never compress sections in .o files, so we only need to
-     try this when the section is not compressed.  */
-  retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
-  if (retbuf != NULL)
-    {
-      info->buffer = retbuf;
-      return;
-    }
-
-  abfd = get_section_bfd_owner (info);
-  gdb_assert (abfd != NULL);
-
-  if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
-      || bfd_bread (buf, info->size, abfd) != info->size)
-    {
-      error (_("Dwarf Error: Can't read DWARF data"
-	       " in section %s [in module %s]"),
-	     bfd_section_name (sectp), bfd_get_filename (abfd));
-    }
-}
-
 /* A helper function that returns the size of a section in a safe way.
    If you are positive that the section has been read before using the
    size, then it is safe to refer to the dwarf2_section_info object's
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 7961ffe10c2..f3a652530ce 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -22,6 +22,7 @@
 
 #include <unordered_map>
 #include "dwarf-index-cache.h"
+#include "dwarf2/section.h"
 #include "filename-seen-cache.h"
 #include "gdb_obstack.h"
 #include "gdbsupport/hash_enum.h"
@@ -32,54 +33,6 @@ extern struct cmd_list_element *show_dwarf_cmdlist;
 
 extern bool dwarf_always_disassemble;
 
-/* A descriptor for dwarf sections.
-
-   S.ASECTION, SIZE are typically initialized when the objfile is first
-   scanned.  BUFFER, READIN are filled in later when the section is read.
-   If the section contained compressed data then SIZE is updated to record
-   the uncompressed size of the section.
-
-   DWP file format V2 introduces a wrinkle that is easiest to handle by
-   creating the concept of virtual sections contained within a real section.
-   In DWP V2 the sections of the input DWO files are concatenated together
-   into one section, but section offsets are kept relative to the original
-   input section.
-   If this is a virtual dwp-v2 section, S.CONTAINING_SECTION is a backlink to
-   the real section this "virtual" section is contained in, and BUFFER,SIZE
-   describe the virtual section.  */
-
-struct dwarf2_section_info
-{
-  union
-  {
-    /* If this is a real section, the bfd section.  */
-    asection *section;
-    /* If this is a virtual section, pointer to the containing ("real")
-       section.  */
-    struct dwarf2_section_info *containing_section;
-  } s;
-  /* Pointer to section data, only valid if readin.  */
-  const gdb_byte *buffer;
-  /* The size of the section, real or virtual.  */
-  bfd_size_type size;
-  /* If this is a virtual section, the offset in the real section.
-     Only valid if is_virtual.  */
-  bfd_size_type virtual_offset;
-  /* True if we have tried to read this section.  */
-  bool readin;
-  /* True if this is a virtual section, False otherwise.
-     This specifies which of s.section and s.containing_section to use.  */
-  bool is_virtual;
-};
-
-/* 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
-   of the DWO file.
-   If the section is compressed, uncompress it before returning.  */
-
-void dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info);
-
 struct tu_stats
 {
   int nr_uniq_abbrev_tables;
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 27/38] Move DWARF line_header to new file
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (4 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 19/38] Change dwarf2_per_objfile::die_type_hash to htab_up Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 38/38] Remove "keep" parameter from cutu_reader constructor Tom Tromey
                   ` (32 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves the line_header class to a pair of new files, making
dwarf2/read.c somewhat smaller.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (dwarf_line_debug): Declare.
	* Makefile.in (COMMON_SFILES): Add dwarf2/line-header.c.
	* dwarf2/read.c: Move line_header code to new files.
	(dwarf_line_debug): No longer static.
	* dwarf2/line-header.c: New file.
	* dwarf2/line-header.h: New file.

Change-Id: I8d9d8a2398b4e888e20cc5dd68d041c28b5a06e3
---
 gdb/ChangeLog            |   9 ++
 gdb/Makefile.in          |   1 +
 gdb/dwarf2/line-header.c | 114 +++++++++++++++++
 gdb/dwarf2/line-header.h | 188 +++++++++++++++++++++++++++++
 gdb/dwarf2/read.c        | 255 +--------------------------------------
 gdb/dwarf2/read.h        |   3 +
 6 files changed, 317 insertions(+), 253 deletions(-)
 create mode 100644 gdb/dwarf2/line-header.c
 create mode 100644 gdb/dwarf2/line-header.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 37c5d250ff0..e4c2ebf968d 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1003,6 +1003,7 @@ COMMON_SFILES = \
 	dwarf2/index-common.c \
 	dwarf2/index-write.c \
 	dwarf2/leb.c \
+	dwarf2/line-header.c \
 	dwarf2/loc.c \
 	dwarf2/read.c \
 	dwarf2/section.c \
diff --git a/gdb/dwarf2/line-header.c b/gdb/dwarf2/line-header.c
new file mode 100644
index 00000000000..56dfb5c2dd2
--- /dev/null
+++ b/gdb/dwarf2/line-header.c
@@ -0,0 +1,114 @@
+/* DWARF 2 debugging format support for GDB.
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "dwarf2/line-header.h"
+#include "dwarf2/read.h"
+#include "complaints.h"
+#include "filenames.h"
+
+void
+line_header::add_include_dir (const char *include_dir)
+{
+  if (dwarf_line_debug >= 2)
+    {
+      size_t new_size;
+      if (version >= 5)
+        new_size = m_include_dirs.size ();
+      else
+        new_size = m_include_dirs.size () + 1;
+      fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
+			  new_size, include_dir);
+    }
+  m_include_dirs.push_back (include_dir);
+}
+
+void
+line_header::add_file_name (const char *name,
+			    dir_index d_index,
+			    unsigned int mod_time,
+			    unsigned int length)
+{
+  if (dwarf_line_debug >= 2)
+    {
+      size_t new_size;
+      if (version >= 5)
+        new_size = file_names_size ();
+      else
+        new_size = file_names_size () + 1;
+      fprintf_unfiltered (gdb_stdlog, "Adding file %zu: %s\n",
+			  new_size, name);
+    }
+  m_file_names.emplace_back (name, d_index, mod_time, length);
+}
+
+gdb::unique_xmalloc_ptr<char>
+line_header::file_file_name (int file)
+{
+  /* Is the file number a valid index into the line header's file name
+     table?  Remember that file numbers start with one, not zero.  */
+  if (is_valid_file_index (file))
+    {
+      const file_entry *fe = file_name_at (file);
+
+      if (!IS_ABSOLUTE_PATH (fe->name))
+	{
+	  const char *dir = fe->include_dir (this);
+	  if (dir != NULL)
+	    return gdb::unique_xmalloc_ptr<char> (concat (dir, SLASH_STRING,
+							  fe->name,
+							  (char *) NULL));
+	}
+      return make_unique_xstrdup (fe->name);
+    }
+  else
+    {
+      /* The compiler produced a bogus file number.  We can at least
+         record the macro definitions made in the file, even if we
+         won't be able to find the file by name.  */
+      char fake_name[80];
+
+      xsnprintf (fake_name, sizeof (fake_name),
+		 "<bad macro file number %d>", file);
+
+      complaint (_("bad file number in macro information (%d)"),
+                 file);
+
+      return make_unique_xstrdup (fake_name);
+    }
+}
+
+gdb::unique_xmalloc_ptr<char>
+line_header::file_full_name (int file, const char *comp_dir)
+{
+  /* Is the file number a valid index into the line header's file name
+     table?  Remember that file numbers start with one, not zero.  */
+  if (is_valid_file_index (file))
+    {
+      gdb::unique_xmalloc_ptr<char> relative = file_file_name (file);
+
+      if (IS_ABSOLUTE_PATH (relative.get ()) || comp_dir == NULL)
+	return relative;
+      return gdb::unique_xmalloc_ptr<char> (concat (comp_dir, SLASH_STRING,
+						    relative.get (),
+						    (char *) NULL));
+    }
+  else
+    return file_file_name (file);
+}
diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h
new file mode 100644
index 00000000000..08cf7b0810f
--- /dev/null
+++ b/gdb/dwarf2/line-header.h
@@ -0,0 +1,188 @@
+/* DWARF 2 debugging format support for GDB.
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef DWARF2_LINE_HEADER_H
+#define DWARF2_LINE_HEADER_H
+
+#include "gdbtypes.h"
+
+/* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
+   later.  */
+typedef int dir_index;
+
+/* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
+   and later.  */
+typedef int file_name_index;
+
+struct line_header;
+
+struct file_entry
+{
+  file_entry () = default;
+
+  file_entry (const char *name_, dir_index d_index_,
+	      unsigned int mod_time_, unsigned int length_)
+    : name (name_),
+      d_index (d_index_),
+      mod_time (mod_time_),
+      length (length_)
+  {}
+
+  /* Return the include directory at D_INDEX stored in LH.  Returns
+     NULL if D_INDEX is out of bounds.  */
+  const char *include_dir (const line_header *lh) const;
+
+  /* The file name.  Note this is an observing pointer.  The memory is
+     owned by debug_line_buffer.  */
+  const char *name {};
+
+  /* The directory index (1-based).  */
+  dir_index d_index {};
+
+  unsigned int mod_time {};
+
+  unsigned int length {};
+
+  /* True if referenced by the Line Number Program.  */
+  bool included_p {};
+
+  /* The associated symbol table, if any.  */
+  struct symtab *symtab {};
+};
+
+/* The line number information for a compilation unit (found in the
+   .debug_line section) begins with a "statement program header",
+   which contains the following information.  */
+struct line_header
+{
+  line_header ()
+    : offset_in_dwz {}
+  {}
+
+  /* Add an entry to the include directory table.  */
+  void add_include_dir (const char *include_dir);
+
+  /* Add an entry to the file name table.  */
+  void add_file_name (const char *name, dir_index d_index,
+		      unsigned int mod_time, unsigned int length);
+
+  /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
+     Returns NULL if INDEX is out of bounds.  */
+  const char *include_dir_at (dir_index index) const
+  {
+    int vec_index;
+    if (version >= 5)
+      vec_index = index;
+    else
+      vec_index = index - 1;
+    if (vec_index < 0 || vec_index >= m_include_dirs.size ())
+      return NULL;
+    return m_include_dirs[vec_index];
+  }
+
+  bool is_valid_file_index (int file_index)
+  {
+    if (version >= 5)
+      return 0 <= file_index && file_index < file_names_size ();
+    return 1 <= file_index && file_index <= file_names_size ();
+  }
+
+  /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
+     Returns NULL if INDEX is out of bounds.  */
+  file_entry *file_name_at (file_name_index index)
+  {
+    int vec_index;
+    if (version >= 5)
+      vec_index = index;
+    else
+      vec_index = index - 1;
+    if (vec_index < 0 || vec_index >= m_file_names.size ())
+      return NULL;
+    return &m_file_names[vec_index];
+  }
+
+  /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
+     this method should only be used to iterate through all file entries in an
+     index-agnostic manner.  */
+  std::vector<file_entry> &file_names ()
+  { return m_file_names; }
+
+  /* Offset of line number information in .debug_line section.  */
+  sect_offset sect_off {};
+
+  /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile.  */
+  unsigned offset_in_dwz : 1; /* Can't initialize bitfields in-class.  */
+
+  unsigned int total_length {};
+  unsigned short version {};
+  unsigned int header_length {};
+  unsigned char minimum_instruction_length {};
+  unsigned char maximum_ops_per_instruction {};
+  unsigned char default_is_stmt {};
+  int line_base {};
+  unsigned char line_range {};
+  unsigned char opcode_base {};
+
+  /* standard_opcode_lengths[i] is the number of operands for the
+     standard opcode whose value is i.  This means that
+     standard_opcode_lengths[0] is unused, and the last meaningful
+     element is standard_opcode_lengths[opcode_base - 1].  */
+  std::unique_ptr<unsigned char[]> standard_opcode_lengths;
+
+  int file_names_size ()
+  { return m_file_names.size(); }
+
+  /* The start and end of the statement program following this
+     header.  These point into dwarf2_per_objfile->line_buffer.  */
+  const gdb_byte *statement_program_start {}, *statement_program_end {};
+
+  /* Return the full name of file number I in this object's file name
+     table.  Use COMP_DIR as the name of the current directory of the
+     compilation.  The result is allocated using xmalloc; the caller
+     is responsible for freeing it.  */
+  gdb::unique_xmalloc_ptr<char> file_full_name (int file,
+						const char *comp_dir);
+
+  /* Return file name relative to the compilation directory of file
+     number I in this object's file name table.  The result is
+     allocated using xmalloc; the caller is responsible for freeing
+     it.  */
+  gdb::unique_xmalloc_ptr<char> file_file_name (int file);
+
+ private:
+  /* The include_directories table.  Note these are observing
+     pointers.  The memory is owned by debug_line_buffer.  */
+  std::vector<const char *> m_include_dirs;
+
+  /* The file_names table. This is private because the meaning of indexes
+     differs among DWARF versions (The first valid index is 1 in DWARF 4 and
+     before, and is 0 in DWARF 5 and later).  So the client should use
+     file_name_at method for access.  */
+  std::vector<file_entry> m_file_names;
+};
+
+typedef std::unique_ptr<line_header> line_header_up;
+
+inline const char *
+file_entry::include_dir (const line_header *lh) const
+{
+  return lh->include_dir_at (d_index);
+}
+
+#endif /* DWARF2_LINE_HEADER_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index b33f505362f..6a9a1a95012 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -35,6 +35,7 @@
 #include "dwarf2/index-cache.h"
 #include "dwarf2/index-common.h"
 #include "dwarf2/leb.h"
+#include "dwarf2/line-header.h"
 #include "bfd.h"
 #include "elf-bfd.h"
 #include "symtab.h"
@@ -90,7 +91,7 @@ static unsigned int dwarf_read_debug = 0;
 static unsigned int dwarf_die_debug = 0;
 
 /* When non-zero, dump line number entries as they are read in.  */
-static unsigned int dwarf_line_debug = 0;
+unsigned int dwarf_line_debug = 0;
 
 /* When true, cross-check physname against demangler.  */
 static bool check_physname = false;
@@ -946,167 +947,6 @@ private:
   abbrev_table_up m_dwo_abbrev_table;
 };
 
-/* dir_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5 and
-   later.  */
-typedef int dir_index;
-
-/* file_name_index is 1-based in DWARF 4 and before, and is 0-based in DWARF 5
-   and later.  */
-typedef int file_name_index;
-
-struct file_entry
-{
-  file_entry () = default;
-
-  file_entry (const char *name_, dir_index d_index_,
-	      unsigned int mod_time_, unsigned int length_)
-    : name (name_),
-      d_index (d_index_),
-      mod_time (mod_time_),
-      length (length_)
-  {}
-
-  /* Return the include directory at D_INDEX stored in LH.  Returns
-     NULL if D_INDEX is out of bounds.  */
-  const char *include_dir (const line_header *lh) const;
-
-  /* The file name.  Note this is an observing pointer.  The memory is
-     owned by debug_line_buffer.  */
-  const char *name {};
-
-  /* The directory index (1-based).  */
-  dir_index d_index {};
-
-  unsigned int mod_time {};
-
-  unsigned int length {};
-
-  /* True if referenced by the Line Number Program.  */
-  bool included_p {};
-
-  /* The associated symbol table, if any.  */
-  struct symtab *symtab {};
-};
-
-/* The line number information for a compilation unit (found in the
-   .debug_line section) begins with a "statement program header",
-   which contains the following information.  */
-struct line_header
-{
-  line_header ()
-    : offset_in_dwz {}
-  {}
-
-  /* Add an entry to the include directory table.  */
-  void add_include_dir (const char *include_dir);
-
-  /* Add an entry to the file name table.  */
-  void add_file_name (const char *name, dir_index d_index,
-		      unsigned int mod_time, unsigned int length);
-
-  /* Return the include dir at INDEX (0-based in DWARF 5 and 1-based before).
-     Returns NULL if INDEX is out of bounds.  */
-  const char *include_dir_at (dir_index index) const
-  {
-    int vec_index;
-    if (version >= 5)
-      vec_index = index;
-    else
-      vec_index = index - 1;
-    if (vec_index < 0 || vec_index >= m_include_dirs.size ())
-      return NULL;
-    return m_include_dirs[vec_index];
-  }
-
-  bool is_valid_file_index (int file_index)
-  {
-    if (version >= 5)
-      return 0 <= file_index && file_index < file_names_size ();
-    return 1 <= file_index && file_index <= file_names_size ();
-  }
-
-  /* Return the file name at INDEX (0-based in DWARF 5 and 1-based before).
-     Returns NULL if INDEX is out of bounds.  */
-  file_entry *file_name_at (file_name_index index)
-  {
-    int vec_index;
-    if (version >= 5)
-      vec_index = index;
-    else
-      vec_index = index - 1;
-    if (vec_index < 0 || vec_index >= m_file_names.size ())
-      return NULL;
-    return &m_file_names[vec_index];
-  }
-
-  /* The indexes are 0-based in DWARF 5 and 1-based in DWARF 4. Therefore,
-     this method should only be used to iterate through all file entries in an
-     index-agnostic manner.  */
-  std::vector<file_entry> &file_names ()
-  { return m_file_names; }
-
-  /* Offset of line number information in .debug_line section.  */
-  sect_offset sect_off {};
-
-  /* OFFSET is for struct dwz_file associated with dwarf2_per_objfile.  */
-  unsigned offset_in_dwz : 1; /* Can't initialize bitfields in-class.  */
-
-  unsigned int total_length {};
-  unsigned short version {};
-  unsigned int header_length {};
-  unsigned char minimum_instruction_length {};
-  unsigned char maximum_ops_per_instruction {};
-  unsigned char default_is_stmt {};
-  int line_base {};
-  unsigned char line_range {};
-  unsigned char opcode_base {};
-
-  /* standard_opcode_lengths[i] is the number of operands for the
-     standard opcode whose value is i.  This means that
-     standard_opcode_lengths[0] is unused, and the last meaningful
-     element is standard_opcode_lengths[opcode_base - 1].  */
-  std::unique_ptr<unsigned char[]> standard_opcode_lengths;
-
-  int file_names_size ()
-  { return m_file_names.size(); }
-
-  /* The start and end of the statement program following this
-     header.  These point into dwarf2_per_objfile->line_buffer.  */
-  const gdb_byte *statement_program_start {}, *statement_program_end {};
-
-  /* Return the full name of file number I in this object's file name
-     table.  Use COMP_DIR as the name of the current directory of the
-     compilation.  The result is allocated using xmalloc; the caller
-     is responsible for freeing it.  */
-  gdb::unique_xmalloc_ptr<char> file_full_name (int file,
-						const char *comp_dir);
-
-  /* Return file name relative to the compilation directory of file
-     number I in this object's file name table.  The result is
-     allocated using xmalloc; the caller is responsible for freeing
-     it.  */
-  gdb::unique_xmalloc_ptr<char> file_file_name (int file);
-
- private:
-  /* The include_directories table.  Note these are observing
-     pointers.  The memory is owned by debug_line_buffer.  */
-  std::vector<const char *> m_include_dirs;
-
-  /* The file_names table. This is private because the meaning of indexes
-     differs among DWARF versions (The first valid index is 1 in DWARF 4 and
-     before, and is 0 in DWARF 5 and later).  So the client should use
-     file_name_at method for access.  */
-  std::vector<file_entry> m_file_names;
-};
-
-typedef std::unique_ptr<line_header> line_header_up;
-
-const char *
-file_entry::include_dir (const line_header *lh) const
-{
-  return lh->include_dir_at (d_index);
-}
-
 /* When we construct a partial symbol table entry we only
    need this much information.  */
 struct partial_die_info : public allocate_on_obstack
@@ -19895,41 +19735,6 @@ free_line_header_voidp (void *arg)
   delete lh;
 }
 
-void
-line_header::add_include_dir (const char *include_dir)
-{
-  if (dwarf_line_debug >= 2)
-    {
-      size_t new_size;
-      if (version >= 5)
-        new_size = m_include_dirs.size ();
-      else
-        new_size = m_include_dirs.size () + 1;
-      fprintf_unfiltered (gdb_stdlog, "Adding dir %zu: %s\n",
-			  new_size, include_dir);
-    }
-  m_include_dirs.push_back (include_dir);
-}
-
-void
-line_header::add_file_name (const char *name,
-			    dir_index d_index,
-			    unsigned int mod_time,
-			    unsigned int length)
-{
-  if (dwarf_line_debug >= 2)
-    {
-      size_t new_size;
-      if (version >= 5)
-        new_size = file_names_size ();
-      else
-        new_size = file_names_size () + 1;
-      fprintf_unfiltered (gdb_stdlog, "Adding file %zu: %s\n",
-			  new_size, name);
-    }
-  m_file_names.emplace_back (name, d_index, mod_time, length);
-}
-
 /* A convenience function to find the proper .debug_line section for a CU.  */
 
 static struct dwarf2_section_info *
@@ -23799,62 +23604,6 @@ dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs)
 \f
 /* Macro support.  */
 
-gdb::unique_xmalloc_ptr<char>
-line_header::file_file_name (int file)
-{
-  /* Is the file number a valid index into the line header's file name
-     table?  Remember that file numbers start with one, not zero.  */
-  if (is_valid_file_index (file))
-    {
-      const file_entry *fe = file_name_at (file);
-
-      if (!IS_ABSOLUTE_PATH (fe->name))
-	{
-	  const char *dir = fe->include_dir (this);
-	  if (dir != NULL)
-	    return gdb::unique_xmalloc_ptr<char> (concat (dir, SLASH_STRING,
-							  fe->name,
-							  (char *) NULL));
-	}
-      return make_unique_xstrdup (fe->name);
-    }
-  else
-    {
-      /* The compiler produced a bogus file number.  We can at least
-         record the macro definitions made in the file, even if we
-         won't be able to find the file by name.  */
-      char fake_name[80];
-
-      xsnprintf (fake_name, sizeof (fake_name),
-		 "<bad macro file number %d>", file);
-
-      complaint (_("bad file number in macro information (%d)"),
-                 file);
-
-      return make_unique_xstrdup (fake_name);
-    }
-}
-
-gdb::unique_xmalloc_ptr<char>
-line_header::file_full_name (int file, const char *comp_dir)
-{
-  /* Is the file number a valid index into the line header's file name
-     table?  Remember that file numbers start with one, not zero.  */
-  if (is_valid_file_index (file))
-    {
-      gdb::unique_xmalloc_ptr<char> relative = file_file_name (file);
-
-      if (IS_ABSOLUTE_PATH (relative.get ()) || comp_dir == NULL)
-	return relative;
-      return gdb::unique_xmalloc_ptr<char> (concat (comp_dir, SLASH_STRING,
-						    relative.get (),
-						    (char *) NULL));
-    }
-  else
-    return file_file_name (file);
-}
-
-
 static struct macro_source_file *
 macro_start_file (struct dwarf2_cu *cu,
 		  int file, int line,
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index b9d185d691c..9eab657e14a 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -452,4 +452,7 @@ struct dwz_file
 extern struct dwz_file *dwarf2_get_dwz_file
     (struct dwarf2_per_objfile *dwarf2_per_objfile);
 
+/* When non-zero, dump line number entries as they are read in.  */
+extern unsigned int dwarf_line_debug;
+
 #endif /* DWARF2READ_H */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 11/38] Move DWARF code to dwarf2/ subdirectory
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (21 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 06/38] Change some attribute functions to be methods Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-27 13:41   ` Christian Biesinger via gdb-patches
  2020-01-23  0:57 ` [PATCH 14/38] Change dwarf2_per_objfile::signatured_types to be htab_up Tom Tromey
                   ` (15 subsequent siblings)
  38 siblings, 1 reply; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves all the remaining DWARF code to the new dwarf2
subdirectory.  This is just a simple renaming, with updates to
includes as needed.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/expr.c: Rename from dwarf2expr.c.
	* dwarf2/expr.h: Rename from dwarf2expr.h.
	* dwarf2/frame-tailcall.c: Rename from dwarf2-frame-tailcall.c.
	* dwarf2/frame-tailcall.h: Rename from dwarf2-frame-tailcall.h.
	* dwarf2/frame.c: Rename from dwarf2-frame.c.
	* dwarf2/frame.h: Rename from dwarf2-frame.h.
	* dwarf2/index-cache.c: Rename from dwarf-index-cache.c.
	* dwarf2/index-cache.h: Rename from dwarf-index-cache.h.
	* dwarf2/index-common.c: Rename from dwarf-index-common.c.
	* dwarf2/index-common.h: Rename from dwarf-index-common.h.
	* dwarf2/index-write.c: Rename from dwarf-index-write.c.
	* dwarf2/index-write.h: Rename from dwarf-index-write.h.
	* dwarf2/loc.c: Rename from dwarf2loc.c.
	* dwarf2/loc.h: Rename from dwarf2loc.h.
	* dwarf2/read.c: Rename from dwarf2read.c.
	* dwarf2/read.h: Rename from dwarf2read.h.
	* dwarf2/abbrev.c, aarch64-tdep.c, alpha-tdep.c,
	amd64-darwin-tdep.c, arc-tdep.c, arm-tdep.c, bfin-tdep.c,
	compile/compile-c-symbols.c, compile/compile-cplus-symbols.c,
	compile/compile-loc2c.c, cris-tdep.c, csky-tdep.c, findvar.c,
	gdbtypes.c, guile/scm-type.c, h8300-tdep.c, hppa-bsd-tdep.c,
	hppa-linux-tdep.c, i386-darwin-tdep.c, i386-linux-tdep.c,
	i386-tdep.c, iq2000-tdep.c, m32c-tdep.c, m68hc11-tdep.c,
	m68k-tdep.c, microblaze-tdep.c, mips-tdep.c, mn10300-tdep.c,
	msp430-tdep.c, nds32-tdep.c, nios2-tdep.c, or1k-tdep.c,
	riscv-tdep.c, rl78-tdep.c, rs6000-tdep.c, rx-tdep.c, s12z-tdep.c,
	s390-tdep.c, score-tdep.c, sh-tdep.c, sparc-linux-tdep.c,
	sparc-tdep.c, sparc64-linux-tdep.c, sparc64-tdep.c, tic6x-tdep.c,
	tilegx-tdep.c, v850-tdep.c, xstormy16-tdep.c, xtensa-tdep.c:
	Update.
	* Makefile.in (COMMON_SFILES): Update.
	(HFILES_NO_SRCDIR): Update.

Change-Id: Ied9ce1436cd27ac4a4cffef10ec92e396f181928
---
 gdb/ChangeLog                                 | 35 +++++++++++++++++++
 gdb/Makefile.in                               | 30 ++++++++--------
 gdb/aarch64-tdep.c                            |  2 +-
 gdb/alpha-tdep.c                              |  2 +-
 gdb/amd64-darwin-tdep.c                       |  2 +-
 gdb/arc-tdep.c                                |  2 +-
 gdb/arm-tdep.c                                |  2 +-
 gdb/bfin-tdep.c                               |  2 +-
 gdb/compile/compile-c-symbols.c               |  2 +-
 gdb/compile/compile-cplus-symbols.c           |  2 +-
 gdb/compile/compile-loc2c.c                   |  6 ++--
 gdb/cris-tdep.c                               |  2 +-
 gdb/csky-tdep.c                               |  2 +-
 gdb/dwarf2/abbrev.c                           |  2 +-
 gdb/{dwarf2expr.c => dwarf2/expr.c}           |  4 +--
 gdb/{dwarf2expr.h => dwarf2/expr.h}           |  0
 .../frame-tailcall.c}                         |  6 ++--
 .../frame-tailcall.h}                         |  0
 gdb/{dwarf2-frame.c => dwarf2/frame.c}        | 10 +++---
 gdb/{dwarf2-frame.h => dwarf2/frame.h}        |  0
 .../index-cache.c}                            |  6 ++--
 .../index-cache.h}                            |  2 +-
 .../index-common.c}                           |  2 +-
 .../index-common.h}                           |  0
 .../index-write.c}                            |  6 ++--
 .../index-write.h}                            |  2 +-
 gdb/{dwarf2loc.c => dwarf2/loc.c}             |  8 ++---
 gdb/{dwarf2loc.h => dwarf2/loc.h}             |  2 +-
 gdb/{dwarf2read.c => dwarf2/read.c}           | 10 +++---
 gdb/{dwarf2read.h => dwarf2/read.h}           |  2 +-
 gdb/findvar.c                                 |  2 +-
 gdb/gdbtypes.c                                |  2 +-
 gdb/guile/scm-type.c                          |  2 +-
 gdb/h8300-tdep.c                              |  2 +-
 gdb/hppa-bsd-tdep.c                           |  2 +-
 gdb/hppa-linux-tdep.c                         |  2 +-
 gdb/i386-darwin-tdep.c                        |  2 +-
 gdb/i386-linux-tdep.c                         |  2 +-
 gdb/i386-tdep.c                               |  2 +-
 gdb/iq2000-tdep.c                             |  2 +-
 gdb/m32c-tdep.c                               |  4 +--
 gdb/m68hc11-tdep.c                            |  2 +-
 gdb/m68k-tdep.c                               |  2 +-
 gdb/microblaze-tdep.c                         |  2 +-
 gdb/mips-tdep.c                               |  2 +-
 gdb/mn10300-tdep.c                            |  2 +-
 gdb/msp430-tdep.c                             |  2 +-
 gdb/nds32-tdep.c                              |  2 +-
 gdb/nios2-tdep.c                              |  2 +-
 gdb/or1k-tdep.c                               |  2 +-
 gdb/riscv-tdep.c                              |  2 +-
 gdb/rl78-tdep.c                               |  2 +-
 gdb/rs6000-tdep.c                             |  2 +-
 gdb/rx-tdep.c                                 |  2 +-
 gdb/s12z-tdep.c                               |  2 +-
 gdb/s390-tdep.c                               |  2 +-
 gdb/score-tdep.c                              |  2 +-
 gdb/sh-tdep.c                                 |  2 +-
 gdb/sparc-linux-tdep.c                        |  2 +-
 gdb/sparc-tdep.c                              |  2 +-
 gdb/sparc64-linux-tdep.c                      |  2 +-
 gdb/sparc64-tdep.c                            |  2 +-
 gdb/tic6x-tdep.c                              |  2 +-
 gdb/tilegx-tdep.c                             |  2 +-
 gdb/v850-tdep.c                               |  2 +-
 gdb/xstormy16-tdep.c                          |  2 +-
 gdb/xtensa-tdep.c                             |  4 +--
 67 files changed, 133 insertions(+), 98 deletions(-)
 rename gdb/{dwarf2expr.c => dwarf2/expr.c} (99%)
 rename gdb/{dwarf2expr.h => dwarf2/expr.h} (100%)
 rename gdb/{dwarf2-frame-tailcall.c => dwarf2/frame-tailcall.c} (99%)
 rename gdb/{dwarf2-frame-tailcall.h => dwarf2/frame-tailcall.h} (100%)
 rename gdb/{dwarf2-frame.c => dwarf2/frame.c} (99%)
 rename gdb/{dwarf2-frame.h => dwarf2/frame.h} (100%)
 rename gdb/{dwarf-index-cache.c => dwarf2/index-cache.c} (99%)
 rename gdb/{dwarf-index-cache.h => dwarf2/index-cache.h} (98%)
 rename gdb/{dwarf-index-common.c => dwarf2/index-common.c} (97%)
 rename gdb/{dwarf-index-common.h => dwarf2/index-common.h} (100%)
 rename gdb/{dwarf-index-write.c => dwarf2/index-write.c} (99%)
 rename gdb/{dwarf-index-write.h => dwarf2/index-write.h} (98%)
 rename gdb/{dwarf2loc.c => dwarf2/loc.c} (99%)
 rename gdb/{dwarf2loc.h => dwarf2/loc.h} (99%)
 rename gdb/{dwarf2read.c => dwarf2/read.c} (99%)
 rename gdb/{dwarf2read.h => dwarf2/read.h} (99%)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index e652e4f971a..37c5d250ff0 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -994,17 +994,17 @@ COMMON_SFILES = \
 	disasm.c \
 	disasm-selftests.c \
 	dummy-frame.c \
-	dwarf-index-cache.c \
-	dwarf-index-common.c \
-	dwarf-index-write.c \
-	dwarf2-frame.c \
-	dwarf2-frame-tailcall.c \
-	dwarf2expr.c \
-	dwarf2loc.c \
-	dwarf2read.c \
 	dwarf2/abbrev.c \
 	dwarf2/attribute.c \
+	dwarf2/expr.c \
+	dwarf2/frame-tailcall.c \
+	dwarf2/frame.c \
+	dwarf2/index-cache.c \
+	dwarf2/index-common.c \
+	dwarf2/index-write.c \
 	dwarf2/leb.c \
+	dwarf2/loc.c \
+	dwarf2/read.c \
 	dwarf2/section.c \
 	eval.c \
 	event-loop.c \
@@ -1234,13 +1234,13 @@ HFILES_NO_SRCDIR = \
 	dictionary.h \
 	disasm.h \
 	dummy-frame.h \
-	dwarf-index-cache.h \
-	dwarf-index-common.h \
-	dwarf2-frame.h \
-	dwarf2-frame-tailcall.h \
-	dwarf2expr.h \
-	dwarf2loc.h \
-	dwarf2read.h \
+	dwarf2/frame-tailcall.h \
+	dwarf2/frame.h \
+	dwarf2/expr.h \
+	dwarf2/index-cache.h \
+	dwarf2/index-common.h \
+	dwarf2/loc.h \
+	dwarf2/read.h \
 	event-loop.h \
 	event-top.h \
 	exceptions.h \
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 1631178f8c2..6d099fbf35d 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -34,7 +34,7 @@
 #include "trad-frame.h"
 #include "objfiles.h"
 #include "dwarf2.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "gdbtypes.h"
 #include "prologue-value.h"
 #include "target-descriptions.h"
diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
index 390f865edad..aabd202b1cc 100644
--- a/gdb/alpha-tdep.c
+++ b/gdb/alpha-tdep.c
@@ -21,7 +21,7 @@
 #include "frame.h"
 #include "frame-unwind.h"
 #include "frame-base.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "inferior.h"
 #include "symtab.h"
 #include "value.h"
diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
index 5e8f352ffc9..447e272f4ea 100644
--- a/gdb/amd64-darwin-tdep.c
+++ b/gdb/amd64-darwin-tdep.c
@@ -36,7 +36,7 @@
 #include "i386-darwin-tdep.h"
 #include "solib.h"
 #include "solib-darwin.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 
 /* Offsets into the struct x86_thread_state64 where we'll find the saved regs.
    From <mach/i386/thread_status.h> and amd64-tdep.h.  */
diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 13da0226f78..ac98f03efc1 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -22,7 +22,7 @@
 #include "defs.h"
 #include "arch-utils.h"
 #include "disasm.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
 #include "gdbcore.h"
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 0e72bcc651a..d4fed8977e7 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -38,7 +38,7 @@
 #include "frame-base.h"
 #include "trad-frame.h"
 #include "objfiles.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "gdbtypes.h"
 #include "prologue-value.h"
 #include "remote.h"
diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
index 23591d4a5f0..55fb6a61d6d 100644
--- a/gdb/bfin-tdep.c
+++ b/gdb/bfin-tdep.c
@@ -31,7 +31,7 @@
 #include "dis-asm.h"
 #include "sim-regno.h"
 #include "gdb/sim-bfin.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "symtab.h"
 #include "elf-bfd.h"
 #include "elf/bfin.h"
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 7af85d62cd4..eb5af8e015f 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -29,7 +29,7 @@
 #include "value.h"
 #include "exceptions.h"
 #include "gdbtypes.h"
-#include "dwarf2loc.h"
+#include "dwarf2/loc.h"
 
 \f
 
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index 34cae4a6d8f..fee2651e47f 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -30,7 +30,7 @@
 #include "value.h"
 #include "exceptions.h"
 #include "gdbtypes.h"
-#include "dwarf2loc.h"
+#include "dwarf2/loc.h"
 #include "cp-support.h"
 #include "gdbcmd.h"
 #include "compile-c.h"
diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index 0f911821115..636c929b022 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -19,15 +19,15 @@
 
 #include "defs.h"
 #include "dwarf2.h"
-#include "dwarf2expr.h"
-#include "dwarf2loc.h"
+#include "dwarf2/expr.h"
+#include "dwarf2/loc.h"
 #include "ui-file.h"
 #include "utils.h"
 #include "compile-internal.h"
 #include "compile-c.h"
 #include "compile.h"
 #include "block.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "gdbsupport/gdb_vecs.h"
 #include "value.h"
 #include "gdbarch.h"
diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
index 6885d237f3a..cc45a7f8ebf 100644
--- a/gdb/cris-tdep.c
+++ b/gdb/cris-tdep.c
@@ -25,7 +25,7 @@
 #include "frame-unwind.h"
 #include "frame-base.h"
 #include "trad-frame.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "symtab.h"
 #include "inferior.h"
 #include "gdbtypes.h"
diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c
index 583298ce74c..955238bb014 100644
--- a/gdb/csky-tdep.c
+++ b/gdb/csky-tdep.c
@@ -49,7 +49,7 @@
 #include "floatformat.h"
 #include "remote.h"
 #include "target-descriptions.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "user-regs.h"
 #include "valprint.h"
 #include "csky-tdep.h"
diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index 6bd455f012b..544d5793add 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -25,7 +25,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "dwarf2read.h"
+#include "dwarf2/read.h"
 #include "dwarf2/abbrev.h"
 #include "dwarf2/leb.h"
 #include "bfd.h"
diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2/expr.c
similarity index 99%
rename from gdb/dwarf2expr.c
rename to gdb/dwarf2/expr.c
index ad82cbec2f7..243f493084b 100644
--- a/gdb/dwarf2expr.c
+++ b/gdb/dwarf2/expr.c
@@ -25,8 +25,8 @@
 #include "value.h"
 #include "gdbcore.h"
 #include "dwarf2.h"
-#include "dwarf2expr.h"
-#include "dwarf2loc.h"
+#include "dwarf2/expr.h"
+#include "dwarf2/loc.h"
 #include "gdbsupport/underlying.h"
 #include "gdbarch.h"
 
diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2/expr.h
similarity index 100%
rename from gdb/dwarf2expr.h
rename to gdb/dwarf2/expr.h
diff --git a/gdb/dwarf2-frame-tailcall.c b/gdb/dwarf2/frame-tailcall.c
similarity index 99%
rename from gdb/dwarf2-frame-tailcall.c
rename to gdb/dwarf2/frame-tailcall.c
index fca1d3d0235..3dc300df60a 100644
--- a/gdb/dwarf2-frame-tailcall.c
+++ b/gdb/dwarf2/frame-tailcall.c
@@ -19,15 +19,15 @@
 
 #include "defs.h"
 #include "frame.h"
-#include "dwarf2-frame-tailcall.h"
-#include "dwarf2loc.h"
+#include "dwarf2/frame-tailcall.h"
+#include "dwarf2/loc.h"
 #include "frame-unwind.h"
 #include "block.h"
 #include "hashtab.h"
 #include "gdbtypes.h"
 #include "regcache.h"
 #include "value.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "gdbarch.h"
 
 /* Contains struct tailcall_cache indexed by next_bottom_frame.  */
diff --git a/gdb/dwarf2-frame-tailcall.h b/gdb/dwarf2/frame-tailcall.h
similarity index 100%
rename from gdb/dwarf2-frame-tailcall.h
rename to gdb/dwarf2/frame-tailcall.h
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2/frame.c
similarity index 99%
rename from gdb/dwarf2-frame.c
rename to gdb/dwarf2/frame.c
index 9daa66b0a29..7f57c28be2c 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2/frame.c
@@ -20,7 +20,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "dwarf2expr.h"
+#include "dwarf2/expr.h"
 #include "dwarf2.h"
 #include "dwarf2/leb.h"
 #include "frame.h"
@@ -35,11 +35,11 @@
 #include "record.h"
 
 #include "complaints.h"
-#include "dwarf2-frame.h"
-#include "dwarf2read.h"
+#include "dwarf2/frame.h"
+#include "dwarf2/read.h"
 #include "ax.h"
-#include "dwarf2loc.h"
-#include "dwarf2-frame-tailcall.h"
+#include "dwarf2/loc.h"
+#include "dwarf2/frame-tailcall.h"
 #include "gdbsupport/gdb_binary_search.h"
 #if GDB_SELF_TEST
 #include "gdbsupport/selftest.h"
diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2/frame.h
similarity index 100%
rename from gdb/dwarf2-frame.h
rename to gdb/dwarf2/frame.h
diff --git a/gdb/dwarf-index-cache.c b/gdb/dwarf2/index-cache.c
similarity index 99%
rename from gdb/dwarf-index-cache.c
rename to gdb/dwarf2/index-cache.c
index 977fcc1b20c..7b4d9975905 100644
--- a/gdb/dwarf-index-cache.c
+++ b/gdb/dwarf2/index-cache.c
@@ -18,15 +18,15 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "dwarf-index-cache.h"
+#include "dwarf2/index-cache.h"
 
 #include "build-id.h"
 #include "cli/cli-cmds.h"
 #include "command.h"
 #include "gdbsupport/scoped_mmap.h"
 #include "gdbsupport/pathstuff.h"
-#include "dwarf-index-write.h"
-#include "dwarf2read.h"
+#include "dwarf2/index-write.h"
+#include "dwarf2/read.h"
 #include "objfiles.h"
 #include "gdbsupport/selftest.h"
 #include <string>
diff --git a/gdb/dwarf-index-cache.h b/gdb/dwarf2/index-cache.h
similarity index 98%
rename from gdb/dwarf-index-cache.h
rename to gdb/dwarf2/index-cache.h
index bc1b30aa45f..07e93fa853c 100644
--- a/gdb/dwarf-index-cache.h
+++ b/gdb/dwarf2/index-cache.h
@@ -20,7 +20,7 @@
 #ifndef DWARF_INDEX_CACHE_H
 #define DWARF_INDEX_CACHE_H
 
-#include "dwarf-index-common.h"
+#include "dwarf2/index-common.h"
 #include "gdbsupport/array-view.h"
 #include "symfile.h"
 
diff --git a/gdb/dwarf-index-common.c b/gdb/dwarf2/index-common.c
similarity index 97%
rename from gdb/dwarf-index-common.c
rename to gdb/dwarf2/index-common.c
index 0baf869e41e..13c6f0f8ab9 100644
--- a/gdb/dwarf-index-common.c
+++ b/gdb/dwarf2/index-common.c
@@ -18,7 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "dwarf-index-common.h"
+#include "dwarf2/index-common.h"
 
 /* See dwarf-index-common.h.  */
 
diff --git a/gdb/dwarf-index-common.h b/gdb/dwarf2/index-common.h
similarity index 100%
rename from gdb/dwarf-index-common.h
rename to gdb/dwarf2/index-common.h
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf2/index-write.c
similarity index 99%
rename from gdb/dwarf-index-write.c
rename to gdb/dwarf2/index-write.c
index c43a4817b97..6744e1a44db 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -19,7 +19,7 @@
 
 #include "defs.h"
 
-#include "dwarf-index-write.h"
+#include "dwarf2/index-write.h"
 
 #include "addrmap.h"
 #include "cli/cli-decode.h"
@@ -29,9 +29,9 @@
 #include "gdbsupport/pathstuff.h"
 #include "gdbsupport/scoped_fd.h"
 #include "complaints.h"
-#include "dwarf-index-common.h"
+#include "dwarf2/index-common.h"
 #include "dwarf2.h"
-#include "dwarf2read.h"
+#include "dwarf2/read.h"
 #include "gdb/gdb-index.h"
 #include "gdbcmd.h"
 #include "objfiles.h"
diff --git a/gdb/dwarf-index-write.h b/gdb/dwarf2/index-write.h
similarity index 98%
rename from gdb/dwarf-index-write.h
rename to gdb/dwarf2/index-write.h
index d78ff2ac073..5ba17251a9f 100644
--- a/gdb/dwarf-index-write.h
+++ b/gdb/dwarf2/index-write.h
@@ -21,7 +21,7 @@
 #define DWARF_INDEX_WRITE_H
 
 #include "symfile.h"
-#include "dwarf2read.h"
+#include "dwarf2/read.h"
 
 /* Create index files for OBJFILE in the directory DIR.
 
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2/loc.c
similarity index 99%
rename from gdb/dwarf2loc.c
rename to gdb/dwarf2/loc.c
index 9cfc852c9e1..03333602820 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2/loc.c
@@ -34,10 +34,10 @@
 #include "gdbcmd.h"
 #include "complaints.h"
 #include "dwarf2.h"
-#include "dwarf2expr.h"
-#include "dwarf2loc.h"
-#include "dwarf2read.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/expr.h"
+#include "dwarf2/loc.h"
+#include "dwarf2/read.h"
+#include "dwarf2/frame.h"
 #include "dwarf2/leb.h"
 #include "compile/compile.h"
 #include "gdbsupport/selftest.h"
diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2/loc.h
similarity index 99%
rename from gdb/dwarf2loc.h
rename to gdb/dwarf2/loc.h
index d0bc23b37d8..a49a9903b11 100644
--- a/gdb/dwarf2loc.h
+++ b/gdb/dwarf2/loc.h
@@ -20,7 +20,7 @@
 #if !defined (DWARF2LOC_H)
 #define DWARF2LOC_H
 
-#include "dwarf2expr.h"
+#include "dwarf2/expr.h"
 
 struct symbol_computed_ops;
 struct objfile;
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2/read.c
similarity index 99%
rename from gdb/dwarf2read.c
rename to gdb/dwarf2/read.c
index 99b0551cd5a..c4879865532 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2/read.c
@@ -29,11 +29,11 @@
    E.g., load_partial_dies, read_partial_die.  */
 
 #include "defs.h"
-#include "dwarf2read.h"
+#include "dwarf2/read.h"
 #include "dwarf2/abbrev.h"
 #include "dwarf2/attribute.h"
-#include "dwarf-index-cache.h"
-#include "dwarf-index-common.h"
+#include "dwarf2/index-cache.h"
+#include "dwarf2/index-common.h"
 #include "dwarf2/leb.h"
 #include "bfd.h"
 #include "elf-bfd.h"
@@ -48,8 +48,8 @@
 #include "macrotab.h"
 #include "language.h"
 #include "complaints.h"
-#include "dwarf2expr.h"
-#include "dwarf2loc.h"
+#include "dwarf2/expr.h"
+#include "dwarf2/loc.h"
 #include "cp-support.h"
 #include "hashtab.h"
 #include "command.h"
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2/read.h
similarity index 99%
rename from gdb/dwarf2read.h
rename to gdb/dwarf2/read.h
index a2228200257..9752abc5e4c 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2/read.h
@@ -21,7 +21,7 @@
 #define DWARF2READ_H
 
 #include <unordered_map>
-#include "dwarf-index-cache.h"
+#include "dwarf2/index-cache.h"
 #include "dwarf2/section.h"
 #include "filename-seen-cache.h"
 #include "gdb_obstack.h"
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 5cf1cd4137b..a836c63dc5d 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -31,7 +31,7 @@
 #include "block.h"
 #include "objfiles.h"
 #include "language.h"
-#include "dwarf2loc.h"
+#include "dwarf2/loc.h"
 #include "gdbsupport/selftest.h"
 
 /* Basic byte-swapping routines.  All 'extract' functions return a
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 1d5bfd4bc20..85758930491 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -36,7 +36,7 @@
 #include "hashtab.h"
 #include "cp-support.h"
 #include "bcache.h"
-#include "dwarf2loc.h"
+#include "dwarf2/loc.h"
 #include "gdbcore.h"
 #include "floatformat.h"
 
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 52817ea4ede..bf2f751ce4d 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -27,7 +27,7 @@
 #include "objfiles.h"
 #include "language.h"
 #include "bcache.h"
-#include "dwarf2loc.h"
+#include "dwarf2/loc.h"
 #include "typeprint.h"
 #include "guile-internal.h"
 
diff --git a/gdb/h8300-tdep.c b/gdb/h8300-tdep.c
index 5e8ba94b72f..79c74001bc8 100644
--- a/gdb/h8300-tdep.c
+++ b/gdb/h8300-tdep.c
@@ -29,7 +29,7 @@
 #include "gdbcore.h"
 #include "objfiles.h"
 #include "dis-asm.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
 
diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c
index 34dec20298f..2a00a27dbbd 100644
--- a/gdb/hppa-bsd-tdep.c
+++ b/gdb/hppa-bsd-tdep.c
@@ -26,7 +26,7 @@
 
 #include "hppa-tdep.h"
 #include "hppa-bsd-tdep.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "solib-svr4.h"
 
 static CORE_ADDR
diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
index 51c84d8e4f0..6a38d7200be 100644
--- a/gdb/hppa-linux-tdep.c
+++ b/gdb/hppa-linux-tdep.c
@@ -26,7 +26,7 @@
 #include "glibc-tdep.h"
 #include "frame-unwind.h"
 #include "trad-frame.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "value.h"
 #include "regset.h"
 #include "regcache.h"
diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
index a1c226ba66f..a796a8544f0 100644
--- a/gdb/i386-darwin-tdep.c
+++ b/gdb/i386-darwin-tdep.c
@@ -34,7 +34,7 @@
 #include "i386-darwin-tdep.h"
 #include "solib.h"
 #include "solib-darwin.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include <algorithm>
 
 /* Offsets into the struct i386_thread_state where we'll find the saved regs.
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 6f702b59e7f..f4a5f0a7616 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -26,7 +26,7 @@
 #include "inferior.h"
 #include "osabi.h"
 #include "reggroups.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "i386-tdep.h"
 #include "i386-linux-tdep.h"
 #include "linux-tdep.h"
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index f120438081d..f71444f6528 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -22,7 +22,7 @@
 #include "arch-utils.h"
 #include "command.h"
 #include "dummy-frame.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
diff --git a/gdb/iq2000-tdep.c b/gdb/iq2000-tdep.c
index 4b3419ead7b..7864d810d75 100644
--- a/gdb/iq2000-tdep.c
+++ b/gdb/iq2000-tdep.c
@@ -24,7 +24,7 @@
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "gdbtypes.h"
 #include "value.h"
 #include "dis-asm.h"
diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
index 31f4d24cac5..585fa337745 100644
--- a/gdb/m32c-tdep.c
+++ b/gdb/m32c-tdep.c
@@ -27,8 +27,8 @@
 #include "arch-utils.h"
 #include "frame.h"
 #include "frame-unwind.h"
-#include "dwarf2-frame.h"
-#include "dwarf2expr.h"
+#include "dwarf2/frame.h"
+#include "dwarf2/expr.h"
 #include "symtab.h"
 #include "gdbcore.h"
 #include "value.h"
diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
index 4e63c2f2fa0..fb3b18ac718 100644
--- a/gdb/m68hc11-tdep.c
+++ b/gdb/m68hc11-tdep.c
@@ -24,7 +24,7 @@
 #include "frame.h"
 #include "frame-unwind.h"
 #include "frame-base.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "trad-frame.h"
 #include "symtab.h"
 #include "gdbtypes.h"
diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index ec754a62af9..5ed5087da1f 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -18,7 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
index a05088c36a1..5c804133040 100644
--- a/gdb/microblaze-tdep.c
+++ b/gdb/microblaze-tdep.c
@@ -31,7 +31,7 @@
 #include "target.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "osabi.h"
 #include "target-descriptions.h"
 #include "opcodes/microblaze-opcm.h"
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 90ec3707c5d..2599f825e83 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -51,7 +51,7 @@
 #include "infcall.h"
 #include "remote.h"
 #include "target-descriptions.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "user-regs.h"
 #include "valprint.h"
 #include "ax.h"
diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index d779ad1dd0d..8e487241e70 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -28,7 +28,7 @@
 #include "frame-unwind.h"
 #include "frame-base.h"
 #include "symtab.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "osabi.h"
 #include "infcall.h"
 #include "prologue-value.h"
diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
index 0893274686e..88597660b53 100644
--- a/gdb/msp430-tdep.c
+++ b/gdb/msp430-tdep.c
@@ -32,7 +32,7 @@
 #include "frame-base.h"
 #include "value.h"
 #include "gdbcore.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "reggroups.h"
 
 #include "elf/msp430.h"
diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
index 5238fe54a71..220ad1e968d 100644
--- a/gdb/nds32-tdep.c
+++ b/gdb/nds32-tdep.c
@@ -34,7 +34,7 @@
 #include "dis-asm.h"
 #include "user-regs.h"
 #include "elf-bfd.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "remote.h"
 #include "target-descriptions.h"
 
diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
index cb669da2480..02cdaea738e 100644
--- a/gdb/nios2-tdep.c
+++ b/gdb/nios2-tdep.c
@@ -24,7 +24,7 @@
 #include "frame-unwind.h"
 #include "frame-base.h"
 #include "trad-frame.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "symtab.h"
 #include "inferior.h"
 #include "gdbtypes.h"
diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
index 772ecff3349..61901a7689e 100644
--- a/gdb/or1k-tdep.c
+++ b/gdb/or1k-tdep.c
@@ -35,7 +35,7 @@
 #include "arch-utils.h"
 #include "frame-unwind.h"
 #include "frame-base.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "trad-frame.h"
 #include "regset.h"
 #include "remote.h"
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index d585b0be5ab..a14ef4db083 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -47,7 +47,7 @@
 #include "floatformat.h"
 #include "remote.h"
 #include "target-descriptions.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "user-regs.h"
 #include "valprint.h"
 #include "gdbsupport/common-defs.h"
diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
index 3705efdbe89..aca7649fe06 100644
--- a/gdb/rl78-tdep.c
+++ b/gdb/rl78-tdep.c
@@ -32,7 +32,7 @@
 #include "frame-base.h"
 #include "value.h"
 #include "gdbcore.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "reggroups.h"
 
 #include "elf/rl78.h"
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index ccffc39508a..919bebc71b2 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -37,7 +37,7 @@
 #include "sim-regno.h"
 #include "gdb/sim-ppc.h"
 #include "reggroups.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "target-descriptions.h"
 #include "user-regs.h"
 #include "record-full.h"
diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
index 766eaa06ed3..c14ce20282c 100644
--- a/gdb/rx-tdep.c
+++ b/gdb/rx-tdep.c
@@ -32,7 +32,7 @@
 #include "frame-base.h"
 #include "value.h"
 #include "gdbcore.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "remote.h"
 #include "target-descriptions.h"
 
diff --git a/gdb/s12z-tdep.c b/gdb/s12z-tdep.c
index 922268d1ef2..4d2febadc9b 100644
--- a/gdb/s12z-tdep.c
+++ b/gdb/s12z-tdep.c
@@ -21,7 +21,7 @@
 #include "defs.h"
 
 #include "arch-utils.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "gdbsupport/errors.h"
 #include "frame-unwind.h"
 #include "gdbcore.h"
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index e01505549e6..5f3cb7e81e7 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -21,7 +21,7 @@
 
 #include "arch-utils.h"
 #include "ax-gdb.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "elf/s390.h"
 #include "elf-bfd.h"
 #include "frame-base.h"
diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c
index 14eeee9eb8c..c5c183628ab 100644
--- a/gdb/score-tdep.c
+++ b/gdb/score-tdep.c
@@ -34,7 +34,7 @@
 #include "frame-unwind.h"
 #include "frame-base.h"
 #include "trad-frame.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "score-tdep.h"
 
 #define G_FLD(_i,_ms,_ls) \
diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
index b69313d050f..9e831fb42e0 100644
--- a/gdb/sh-tdep.c
+++ b/gdb/sh-tdep.c
@@ -24,7 +24,7 @@
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "gdbcmd.h"
diff --git a/gdb/sparc-linux-tdep.c b/gdb/sparc-linux-tdep.c
index 1c4adb83674..247fde21657 100644
--- a/gdb/sparc-linux-tdep.c
+++ b/gdb/sparc-linux-tdep.c
@@ -18,7 +18,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "frame.h"
 #include "frame-unwind.h"
 #include "gdbtypes.h"
diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
index e048f872c2a..a0c41722440 100644
--- a/gdb/sparc-tdep.c
+++ b/gdb/sparc-tdep.c
@@ -21,7 +21,7 @@
 #include "arch-utils.h"
 #include "dis-asm.h"
 #include "dwarf2.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
index de6c0479009..a7f439fbb04 100644
--- a/gdb/sparc64-linux-tdep.c
+++ b/gdb/sparc64-linux-tdep.c
@@ -20,7 +20,7 @@
 #include "defs.h"
 #include "frame.h"
 #include "frame-unwind.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "regset.h"
 #include "regcache.h"
 #include "gdbarch.h"
diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
index a11da6ab2e8..ac915d468fd 100644
--- a/gdb/sparc64-tdep.c
+++ b/gdb/sparc64-tdep.c
@@ -19,7 +19,7 @@
 
 #include "defs.h"
 #include "arch-utils.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
index a05675c570c..50031c100a5 100644
--- a/gdb/tic6x-tdep.c
+++ b/gdb/tic6x-tdep.c
@@ -24,7 +24,7 @@
 #include "frame-unwind.h"
 #include "frame-base.h"
 #include "trad-frame.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "symtab.h"
 #include "inferior.h"
 #include "gdbtypes.h"
diff --git a/gdb/tilegx-tdep.c b/gdb/tilegx-tdep.c
index 9290bc3878b..70c4add90b1 100644
--- a/gdb/tilegx-tdep.c
+++ b/gdb/tilegx-tdep.c
@@ -21,7 +21,7 @@
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "trad-frame.h"
 #include "symtab.h"
 #include "gdbtypes.h"
diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
index 9b2e9b62e71..fd5a9ff4587 100644
--- a/gdb/v850-tdep.c
+++ b/gdb/v850-tdep.c
@@ -22,7 +22,7 @@
 #include "frame-base.h"
 #include "trad-frame.h"
 #include "frame-unwind.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "gdbtypes.h"
 #include "inferior.h"
 #include "gdbcore.h"
diff --git a/gdb/xstormy16-tdep.c b/gdb/xstormy16-tdep.c
index 0206af8bebc..1715dc81e38 100644
--- a/gdb/xstormy16-tdep.c
+++ b/gdb/xstormy16-tdep.c
@@ -21,7 +21,7 @@
 #include "frame.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
-#include "dwarf2-frame.h"
+#include "dwarf2/frame.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "gdbcmd.h"
diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
index bbd92d5cf8f..2ea11212601 100644
--- a/gdb/xtensa-tdep.c
+++ b/gdb/xtensa-tdep.c
@@ -35,8 +35,8 @@
 
 #include "dummy-frame.h"
 #include "dwarf2.h"
-#include "dwarf2-frame.h"
-#include "dwarf2loc.h"
+#include "dwarf2/frame.h"
+#include "dwarf2/loc.h"
 #include "frame-base.h"
 #include "frame-unwind.h"
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 35/38] Convert read_address to a method on comp_unit_head
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 07/38] Change attr_form_is_block to be a method Tom Tromey
                   ` (37 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes read_address to be a method on comp_unit_head.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_address): Move to comp-unit.c.
	(dwarf2_rnglists_process, dwarf2_ranges_process)
	(read_attribute_value, dwarf_decode_lines_1)
	(var_decode_location, decode_locdesc): Update.
	* dwarf2/comp-unit.c (comp_unit_head::read_address): Move from
	read.c.  Remove "cu" parameter.
	* dwarf2/comp-unit.h (struct comp_unit_head) <read_address>: New
	method.

Change-Id: Ibd6c7235f2e4d5fd88c272cfd2c3d3328618cc56
---
 gdb/ChangeLog          | 11 ++++++
 gdb/dwarf2/comp-unit.c | 50 ++++++++++++++++++++++++
 gdb/dwarf2/comp-unit.h |  4 ++
 gdb/dwarf2/read.c      | 87 +++++++++---------------------------------
 4 files changed, 83 insertions(+), 69 deletions(-)

diff --git a/gdb/dwarf2/comp-unit.c b/gdb/dwarf2/comp-unit.c
index 847a148cbd2..0b6629f14ce 100644
--- a/gdb/dwarf2/comp-unit.c
+++ b/gdb/dwarf2/comp-unit.c
@@ -221,3 +221,53 @@ read_and_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   return info_ptr;
 }
+
+CORE_ADDR
+comp_unit_head::read_address (bfd *abfd, const gdb_byte *buf,
+			      unsigned int *bytes_read) const
+{
+  CORE_ADDR retval = 0;
+
+  if (signed_addr_p)
+    {
+      switch (addr_size)
+	{
+	case 2:
+	  retval = bfd_get_signed_16 (abfd, buf);
+	  break;
+	case 4:
+	  retval = bfd_get_signed_32 (abfd, buf);
+	  break;
+	case 8:
+	  retval = bfd_get_signed_64 (abfd, buf);
+	  break;
+	default:
+	  internal_error (__FILE__, __LINE__,
+			  _("read_address: bad switch, signed [in module %s]"),
+			  bfd_get_filename (abfd));
+	}
+    }
+  else
+    {
+      switch (addr_size)
+	{
+	case 2:
+	  retval = bfd_get_16 (abfd, buf);
+	  break;
+	case 4:
+	  retval = bfd_get_32 (abfd, buf);
+	  break;
+	case 8:
+	  retval = bfd_get_64 (abfd, buf);
+	  break;
+	default:
+	  internal_error (__FILE__, __LINE__,
+			  _("read_address: bad switch, "
+			    "unsigned [in module %s]"),
+			  bfd_get_filename (abfd));
+	}
+    }
+
+  *bytes_read = addr_size;
+  return retval;
+}
diff --git a/gdb/dwarf2/comp-unit.h b/gdb/dwarf2/comp-unit.h
index e61b1000b9e..2dd80901b8f 100644
--- a/gdb/dwarf2/comp-unit.h
+++ b/gdb/dwarf2/comp-unit.h
@@ -89,6 +89,10 @@ struct comp_unit_head
     *bytes_read = offset_size;
     return offset;
   }
+
+  /* Read an address from BUF.  BYTES_READ is updated.  */
+  CORE_ADDR read_address (bfd *abfd, const gdb_byte *buf,
+			  unsigned int *bytes_read) const;
 };
 
 /* Expected enum dwarf_unit_type for read_comp_unit_head.  */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7c0d1d21cb6..e47f7443a58 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1243,9 +1243,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 CORE_ADDR read_address (bfd *, const gdb_byte *ptr, struct dwarf2_cu *,
-			       unsigned int *);
-
 static LONGEST read_checked_initial_length_and_offset
   (bfd *, const gdb_byte *, const struct comp_unit_head *,
    unsigned int *, unsigned int *);
@@ -13559,7 +13556,7 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
 	      overflow = true;
 	      break;
 	    }
-	  base = read_address (obfd, buffer, cu, &bytes_read);
+	  base = cu->header.read_address (obfd, buffer, &bytes_read);
 	  found_base = 1;
 	  buffer += bytes_read;
 	  break;
@@ -13569,7 +13566,8 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
 	      overflow = true;
 	      break;
 	    }
-	  range_beginning = read_address (obfd, buffer, cu, &bytes_read);
+	  range_beginning = cu->header.read_address (obfd, buffer,
+						     &bytes_read);
 	  buffer += bytes_read;
 	  range_end = (range_beginning
 		       + read_unsigned_leb128 (obfd, buffer, &bytes_read));
@@ -13602,9 +13600,10 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
 	      overflow = true;
 	      break;
 	    }
-	  range_beginning = read_address (obfd, buffer, cu, &bytes_read);
+	  range_beginning = cu->header.read_address (obfd, buffer,
+						     &bytes_read);
 	  buffer += bytes_read;
-	  range_end = read_address (obfd, buffer, cu, &bytes_read);
+	  range_end = cu->header.read_address (obfd, buffer, &bytes_read);
 	  buffer += bytes_read;
 	  break;
 	default:
@@ -13707,9 +13706,9 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
     {
       CORE_ADDR range_beginning, range_end;
 
-      range_beginning = read_address (obfd, buffer, cu, &dummy);
+      range_beginning = cu->header.read_address (obfd, buffer, &dummy);
       buffer += addr_size;
-      range_end = read_address (obfd, buffer, cu, &dummy);
+      range_end = cu->header.read_address (obfd, buffer, &dummy);
       buffer += addr_size;
       offset += 2 * addr_size;
 
@@ -18491,7 +18490,8 @@ read_attribute_value (const struct die_reader_specs *reader,
     {
     case DW_FORM_ref_addr:
       if (cu->header.version == 2)
-	DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
+	DW_UNSND (attr) = cu->header.read_address (abfd, info_ptr,
+						   &bytes_read);
       else
 	DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr,
 						  &bytes_read);
@@ -18502,7 +18502,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       info_ptr += bytes_read;
       break;
     case DW_FORM_addr:
-      DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
+      DW_ADDR (attr) = cu->header.read_address (abfd, info_ptr, &bytes_read);
       DW_ADDR (attr) = gdbarch_adjust_dwarf2_addr (gdbarch, DW_ADDR (attr));
       info_ptr += bytes_read;
       break;
@@ -18749,57 +18749,6 @@ read_attribute (const struct die_reader_specs *reader,
 			       need_reprocess);
 }
 
-static CORE_ADDR
-read_address (bfd *abfd, const gdb_byte *buf, struct dwarf2_cu *cu,
-	      unsigned int *bytes_read)
-{
-  struct comp_unit_head *cu_header = &cu->header;
-  CORE_ADDR retval = 0;
-
-  if (cu_header->signed_addr_p)
-    {
-      switch (cu_header->addr_size)
-	{
-	case 2:
-	  retval = bfd_get_signed_16 (abfd, buf);
-	  break;
-	case 4:
-	  retval = bfd_get_signed_32 (abfd, buf);
-	  break;
-	case 8:
-	  retval = bfd_get_signed_64 (abfd, buf);
-	  break;
-	default:
-	  internal_error (__FILE__, __LINE__,
-			  _("read_address: bad switch, signed [in module %s]"),
-			  bfd_get_filename (abfd));
-	}
-    }
-  else
-    {
-      switch (cu_header->addr_size)
-	{
-	case 2:
-	  retval = bfd_get_16 (abfd, buf);
-	  break;
-	case 4:
-	  retval = bfd_get_32 (abfd, buf);
-	  break;
-	case 8:
-	  retval = bfd_get_64 (abfd, buf);
-	  break;
-	default:
-	  internal_error (__FILE__, __LINE__,
-			  _("read_address: bad switch, "
-			    "unsigned [in module %s]"),
-			  bfd_get_filename (abfd));
-	}
-    }
-
-  *bytes_read = cu_header->addr_size;
-  return retval;
-}
-
 /* 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
@@ -20247,7 +20196,7 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
 		case DW_LNE_set_address:
 		  {
 		    CORE_ADDR address
-		      = read_address (abfd, line_ptr, cu, &bytes_read);
+		      = cu->header.read_address (abfd, line_ptr, &bytes_read);
 		    line_ptr += bytes_read;
 
 		    state_machine.check_line_address (cu, line_ptr,
@@ -20568,10 +20517,10 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
       unsigned int dummy;
 
       if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
-	SET_SYMBOL_VALUE_ADDRESS (sym,
-				  read_address (objfile->obfd,
-						DW_BLOCK (attr)->data + 1,
-						cu, &dummy));
+	SET_SYMBOL_VALUE_ADDRESS
+	  (sym, cu->header.read_address (objfile->obfd,
+					 DW_BLOCK (attr)->data + 1,
+					 &dummy));
       else
 	SET_SYMBOL_VALUE_ADDRESS
 	  (sym, read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1,
@@ -23037,8 +22986,8 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
 	  break;
 
 	case DW_OP_addr:
-	  stack[++stacki] = read_address (objfile->obfd, &data[i],
-					  cu, &bytes_read);
+	  stack[++stacki] = cu->header.read_address (objfile->obfd, &data[i],
+						     &bytes_read);
 	  i += bytes_read;
 	  break;
 
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 14/38] Change dwarf2_per_objfile::signatured_types to be htab_up
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (22 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 11/38] Move DWARF code to dwarf2/ subdirectory Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-02-08 16:55   ` Simon Marchi
  2020-01-23  0:57 ` [PATCH 25/38] Change file_full_name and file_file_name methods Tom Tromey
                   ` (14 subsequent siblings)
  38 siblings, 1 reply; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes dwarf2_per_objfile::signatured_types to be an htab_up.
This in turn lets us change it not to use the objfile obstack for
allocation; obstack allocation for hash tables is a bad practice
because it leads to excess memory use if the table is ever resized.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_per_objfile) <signatured_types>:
	Change type to htab_up.
	* dwarf2/read.c (create_signatured_type_table_from_index)
	(create_signatured_type_table_from_debug_names)
	(create_all_type_units, add_type_unit)
	(lookup_dwo_signatured_type, lookup_signatured_type)
	(process_skeletonless_type_unit): Update.
	(create_debug_type_hash_table, create_debug_types_hash_table):
	Change type of types_htab.
	(allocate_signatured_type_table, allocate_dwo_unit_table): Return
	htab_up.  Don't allocate on obstack.
	(create_cus_hash_table): Change type of cus_htab parameter.
	(struct dwo_file) <cus, tus>: Now htab_up.
	(lookup_dwo_signatured_type, lookup_dwo_cutu)
	(process_dwo_file_for_skeletonless_type_units, lookup_dwo_cutu)
	(queue_and_load_all_dwo_tus): Update.
	* dwarf2/index-write.c (write_gdbindex): Update.
	(write_debug_names): Update.

Change-Id: I290a209b96945fb5f415c82723b62830e9c4b467
---
 gdb/ChangeLog            | 21 +++++++++
 gdb/dwarf2/index-write.c |  4 +-
 gdb/dwarf2/read.c        | 96 ++++++++++++++++++++--------------------
 gdb/dwarf2/read.h        |  2 +-
 4 files changed, 71 insertions(+), 52 deletions(-)

diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 6744e1a44db..3d71f967b5f 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1460,7 +1460,7 @@ write_gdbindex (struct dwarf2_per_objfile *dwarf2_per_objfile, FILE *out_file,
       sig_data.objfile = objfile;
       sig_data.symtab = &symtab;
       sig_data.cu_index = dwarf2_per_objfile->all_comp_units.size ();
-      htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
+      htab_traverse_noresize (dwarf2_per_objfile->signatured_types.get (),
 			      write_one_signatured_type, &sig_data);
     }
 
@@ -1533,7 +1533,7 @@ write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
       /* It is used only for gdb_index.  */
       sig_data.info.symtab = nullptr;
       sig_data.info.cu_index = 0;
-      htab_traverse_noresize (dwarf2_per_objfile->signatured_types,
+      htab_traverse_noresize (dwarf2_per_objfile->signatured_types.get (),
 			      debug_names::write_one_signatured_type,
 			      &sig_data);
     }
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 1e64870678e..10cbc7bd231 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -727,11 +727,11 @@ struct dwo_file
      Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
      an extension to handle LLVM's Link Time Optimization output (where
      multiple source files may be compiled into a single object/dwo pair). */
-  htab_t cus {};
+  htab_up cus {};
 
   /* Table of TUs in the file.
      Each element is a struct dwo_unit.  */
-  htab_t tus {};
+  htab_up tus {};
 };
 
 /* These sections are what may appear in a DWP file.  */
@@ -1873,9 +1873,9 @@ static const gdb_byte *read_and_check_comp_unit_head
    struct dwarf2_section_info *abbrev_section, const gdb_byte *info_ptr,
    rcuh_kind section_kind);
 
-static htab_t allocate_signatured_type_table (struct objfile *objfile);
+static htab_up allocate_signatured_type_table (struct objfile *objfile);
 
-static htab_t allocate_dwo_unit_table (struct objfile *objfile);
+static htab_up allocate_dwo_unit_table (struct objfile *objfile);
 
 static struct dwo_unit *lookup_dwo_unit_in_dwp
   (struct dwarf2_per_objfile *dwarf2_per_objfile,
@@ -2744,7 +2744,7 @@ create_signatured_type_table_from_index
   gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
   dwarf2_per_objfile->all_type_units.reserve (elements / 3);
 
-  htab_t sig_types_hash = allocate_signatured_type_table (objfile);
+  htab_up sig_types_hash = allocate_signatured_type_table (objfile);
 
   for (offset_type i = 0; i < elements; i += 3)
     {
@@ -2774,13 +2774,13 @@ create_signatured_type_table_from_index
 	= OBSTACK_ZALLOC (&objfile->objfile_obstack,
 			  struct dwarf2_per_cu_quick_data);
 
-      slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
+      slot = htab_find_slot (sig_types_hash.get (), sig_type, INSERT);
       *slot = sig_type;
 
       dwarf2_per_objfile->all_type_units.push_back (sig_type);
     }
 
-  dwarf2_per_objfile->signatured_types = sig_types_hash;
+  dwarf2_per_objfile->signatured_types = std::move (sig_types_hash);
 }
 
 /* Create the signatured type hash table from .debug_names.  */
@@ -2800,7 +2800,7 @@ create_signatured_type_table_from_debug_names
   gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
   dwarf2_per_objfile->all_type_units.reserve (map.tu_count);
 
-  htab_t sig_types_hash = allocate_signatured_type_table (objfile);
+  htab_up sig_types_hash = allocate_signatured_type_table (objfile);
 
   for (uint32_t i = 0; i < map.tu_count; ++i)
     {
@@ -2831,13 +2831,13 @@ create_signatured_type_table_from_debug_names
 	= OBSTACK_ZALLOC (&objfile->objfile_obstack,
 			  struct dwarf2_per_cu_quick_data);
 
-      slot = htab_find_slot (sig_types_hash, sig_type, INSERT);
+      slot = htab_find_slot (sig_types_hash.get (), sig_type, INSERT);
       *slot = sig_type;
 
       dwarf2_per_objfile->all_type_units.push_back (sig_type);
     }
 
-  dwarf2_per_objfile->signatured_types = sig_types_hash;
+  dwarf2_per_objfile->signatured_types = std::move (sig_types_hash);
 }
 
 /* Read the address map data from the mapped index, and use it to
@@ -6407,16 +6407,13 @@ eq_signatured_type (const void *item_lhs, const void *item_rhs)
 
 /* Allocate a hash table for signatured types.  */
 
-static htab_t
+static htab_up
 allocate_signatured_type_table (struct objfile *objfile)
 {
-  return htab_create_alloc_ex (41,
-			       hash_signatured_type,
-			       eq_signatured_type,
-			       NULL,
-			       &objfile->objfile_obstack,
-			       hashtab_obstack_allocate,
-			       dummy_obstack_deallocate);
+  return htab_up (htab_create_alloc (41,
+				     hash_signatured_type,
+				     eq_signatured_type,
+				     NULL, xcalloc, xfree));
 }
 
 /* A helper function to add a signatured type CU to a table.  */
@@ -6440,7 +6437,7 @@ add_signatured_type_cu_to_table (void **slot, void *datum)
 static void
 create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 			      struct dwo_file *dwo_file,
-			      dwarf2_section_info *section, htab_t &types_htab,
+			      dwarf2_section_info *section, htab_up &types_htab,
 			      rcuh_kind section_kind)
 {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
@@ -6539,7 +6536,7 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 	  sig_type->per_cu.length = length;
 	}
 
-      slot = htab_find_slot (types_htab,
+      slot = htab_find_slot (types_htab.get (),
 			     dwo_file ? (void*) dwo_tu : (void *) sig_type,
 			     INSERT);
       gdb_assert (slot != NULL);
@@ -6591,7 +6588,7 @@ static void
 create_debug_types_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 			       struct dwo_file *dwo_file,
 			       gdb::array_view<dwarf2_section_info> type_sections,
-			       htab_t &types_htab)
+			       htab_up &types_htab)
 {
   for (dwarf2_section_info &section : type_sections)
     create_debug_type_hash_table (dwarf2_per_objfile, dwo_file, &section,
@@ -6606,7 +6603,7 @@ create_debug_types_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 static int
 create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
 {
-  htab_t types_htab = NULL;
+  htab_up types_htab;
 
   create_debug_type_hash_table (dwarf2_per_objfile, NULL,
 				&dwarf2_per_objfile->info, types_htab,
@@ -6619,12 +6616,14 @@ create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
       return 0;
     }
 
-  dwarf2_per_objfile->signatured_types = types_htab;
+  dwarf2_per_objfile->signatured_types = std::move (types_htab);
 
   gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
-  dwarf2_per_objfile->all_type_units.reserve (htab_elements (types_htab));
+  dwarf2_per_objfile->all_type_units.reserve
+    (htab_elements (dwarf2_per_objfile->signatured_types.get ()));
 
-  htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table,
+  htab_traverse_noresize (dwarf2_per_objfile->signatured_types.get (),
+			  add_signatured_type_cu_to_table,
 			  &dwarf2_per_objfile->all_type_units);
 
   return 1;
@@ -6659,7 +6658,7 @@ add_type_unit (struct dwarf2_per_objfile *dwarf2_per_objfile, ULONGEST sig,
 
   if (slot == NULL)
     {
-      slot = htab_find_slot (dwarf2_per_objfile->signatured_types,
+      slot = htab_find_slot (dwarf2_per_objfile->signatured_types.get (),
 			     sig_type, INSERT);
     }
   gdb_assert (*slot == NULL);
@@ -6740,7 +6739,7 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
      .gdb_index with this TU.  */
 
   find_sig_entry.signature = sig;
-  slot = htab_find_slot (dwarf2_per_objfile->signatured_types,
+  slot = htab_find_slot (dwarf2_per_objfile->signatured_types.get (),
 			 &find_sig_entry, INSERT);
   sig_entry = (struct signatured_type *) *slot;
 
@@ -6764,7 +6763,8 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
   if (dwo_file->tus == NULL)
     return NULL;
   find_dwo_entry.signature = sig;
-  dwo_entry = (struct dwo_unit *) htab_find (dwo_file->tus, &find_dwo_entry);
+  dwo_entry = (struct dwo_unit *) htab_find (dwo_file->tus.get (),
+					     &find_dwo_entry);
   if (dwo_entry == NULL)
     return NULL;
 
@@ -6805,7 +6805,7 @@ lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
     }
 
   find_sig_entry.signature = sig;
-  slot = htab_find_slot (dwarf2_per_objfile->signatured_types,
+  slot = htab_find_slot (dwarf2_per_objfile->signatured_types.get (),
 			 &find_sig_entry, INSERT);
   sig_entry = (struct signatured_type *) *slot;
 
@@ -6856,7 +6856,8 @@ lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
 	return NULL;
       find_entry.signature = sig;
       entry = ((struct signatured_type *)
-	       htab_find (dwarf2_per_objfile->signatured_types, &find_entry));
+	       htab_find (dwarf2_per_objfile->signatured_types.get (),
+			  &find_entry));
       return entry;
     }
 }
@@ -8083,8 +8084,8 @@ process_skeletonless_type_unit (void **slot, void *info)
     }
 
   find_entry.signature = dwo_unit->signature;
-  slot = htab_find_slot (dwarf2_per_objfile->signatured_types, &find_entry,
-			 INSERT);
+  slot = htab_find_slot (dwarf2_per_objfile->signatured_types.get (),
+			 &find_entry, INSERT);
   /* If we've already seen this type there's nothing to do.  What's happening
      is we're doing our own version of comdat-folding here.  */
   if (*slot != NULL)
@@ -8113,10 +8114,8 @@ process_dwo_file_for_skeletonless_type_units (void **slot, void *info)
   struct dwo_file *dwo_file = (struct dwo_file *) *slot;
 
   if (dwo_file->tus != NULL)
-    {
-      htab_traverse_noresize (dwo_file->tus,
-			      process_skeletonless_type_unit, info);
-    }
+    htab_traverse_noresize (dwo_file->tus.get (),
+			    process_skeletonless_type_unit, info);
 
   return 1;
 }
@@ -11528,18 +11527,15 @@ eq_dwo_unit (const void *item_lhs, const void *item_rhs)
 /* Allocate a hash table for DWO CUs,TUs.
    There is one of these tables for each of CUs,TUs for each DWO file.  */
 
-static htab_t
+static htab_up
 allocate_dwo_unit_table (struct objfile *objfile)
 {
   /* Start out with a pretty small number.
      Generally DWO files contain only one CU and maybe some TUs.  */
-  return htab_create_alloc_ex (3,
-			       hash_dwo_unit,
-			       eq_dwo_unit,
-			       NULL,
-			       &objfile->objfile_obstack,
-			       hashtab_obstack_allocate,
-			       dummy_obstack_deallocate);
+  return htab_up (htab_create_alloc (3,
+				     hash_dwo_unit,
+				     eq_dwo_unit,
+				     NULL, xcalloc, xfree));
 }
 
 /* die_reader_func for create_dwo_cu.  */
@@ -11582,7 +11578,7 @@ create_dwo_cu_reader (const struct die_reader_specs *reader,
 static void
 create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 		       dwarf2_cu *cu, struct dwo_file &dwo_file,
-		       dwarf2_section_info &section, htab_t &cus_htab)
+		       dwarf2_section_info &section, htab_up &cus_htab)
 {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   const gdb_byte *info_ptr, *end_ptr;
@@ -11630,7 +11626,7 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
       dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit);
       *dwo_unit = read_unit;
-      slot = htab_find_slot (cus_htab, dwo_unit, INSERT);
+      slot = htab_find_slot (cus_htab.get (), dwo_unit, INSERT);
       gdb_assert (slot != NULL);
       if (*slot != NULL)
 	{
@@ -13031,7 +13027,8 @@ lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
 	      memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
 	      find_dwo_cutu.signature = signature;
 	      dwo_cutu
-		= (struct dwo_unit *) htab_find (dwo_file->tus, &find_dwo_cutu);
+		= (struct dwo_unit *) htab_find (dwo_file->tus.get (),
+						 &find_dwo_cutu);
 	    }
 	  else if (!is_debug_types && dwo_file->cus)
 	    {
@@ -13039,7 +13036,7 @@ lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
 
 	      memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu));
 	      find_dwo_cutu.signature = signature;
-	      dwo_cutu = (struct dwo_unit *)htab_find (dwo_file->cus,
+	      dwo_cutu = (struct dwo_unit *)htab_find (dwo_file->cus.get (),
 						       &find_dwo_cutu);
 	    }
 
@@ -13154,7 +13151,8 @@ queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *per_cu)
 
   dwo_file = dwo_unit->dwo_file;
   if (dwo_file->tus != NULL)
-    htab_traverse_noresize (dwo_file->tus, queue_and_load_dwo_tu, per_cu);
+    htab_traverse_noresize (dwo_file->tus.get (), queue_and_load_dwo_tu,
+			    per_cu);
 }
 
 /* Read in various DIEs.  */
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 9c671806479..33ecb4a5911 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -156,7 +156,7 @@ public:
 
   /* A table mapping .debug_types signatures to its signatured_type entry.
      This is NULL if the .debug_types section hasn't been read in yet.  */
-  htab_t signatured_types {};
+  htab_up signatured_types;
 
   /* Type unit statistics, to see how well the scaling improvements
      are doing.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 08/38] Remove die_info_ptr typedef
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (17 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 33/38] Create dwarf2/comp-unit.[ch] Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 01/38] Create dwarf2/leb.[ch] Tom Tromey
                   ` (19 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

die_info_ptr is not used and so can be removed.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.h (die_info_ptr): Remove typedef.

Change-Id: Ibd0a5ad55876dc96a35b658adc36348f01e48884
---
 gdb/ChangeLog    | 4 ++++
 gdb/dwarf2read.h | 1 -
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index f3a652530ce..79e618e0a37 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -47,7 +47,6 @@ 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.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 10/38] Remove die_reader_specs::comp_dir
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (27 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 12/38] Introduce die_info::has_children Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 28/38] Move dwarf2_per_cu_data::imported_symtabs earlier Tom Tromey
                   ` (9 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

die_reader_specs::comp_dir is assigned but never read; this patch
removes it.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (struct die_reader_specs) <comp_dir>: Remove.
	(init_cu_die_reader, read_cutu_die_from_dwo): Update.

Change-Id: I9818a2593197a6972cddec23cd2f3dd0ce28f580
---
 gdb/ChangeLog    |  5 +++++
 gdb/dwarf2read.c | 11 -----------
 2 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index d5fc8e294f1..99b0551cd5a 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -903,9 +903,6 @@ struct die_reader_specs
   /* The end of the buffer.  */
   const gdb_byte *buffer_end;
 
-  /* The value of the DW_AT_comp_dir attribute.  */
-  const char *comp_dir;
-
   /* The abbreviation table to use when reading the DIEs.  */
   struct abbrev_table *abbrev_table;
 };
@@ -6921,7 +6918,6 @@ init_cu_die_reader (struct die_reader_specs *reader,
   reader->die_section = section;
   reader->buffer = section->buffer;
   reader->buffer_end = section->buffer + section->size;
-  reader->comp_dir = NULL;
   reader->abbrev_table = abbrev_table;
 }
 
@@ -7103,13 +7099,6 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
       dump_die (comp_unit_die, dwarf_die_debug);
     }
 
-  /* Save the comp_dir attribute.  If there is no DWP file then we'll read
-     TUs by skipping the stub and going directly to the entry in the DWO file.
-     However, skipping the stub means we won't get DW_AT_comp_dir, so we have
-     to get it via circuitous means.  Blech.  */
-  if (comp_dir != NULL)
-    result_reader->comp_dir = DW_STRING (comp_dir);
-
   /* Skip dummy compilation units.  */
   if (info_ptr >= begin_info_ptr + dwo_unit->length
       || peek_abbrev_code (abfd, info_ptr) == 0)
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 28/38] Move dwarf2_per_cu_data::imported_symtabs earlier
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (28 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 10/38] Remove die_reader_specs::comp_dir Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 20/38] Minor cleanups in abbrev_table Tom Tromey
                   ` (8 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves dwarf2_per_cu_data::imported_symtabs earlier, near where
the other data members are located.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct dwarf2_per_cu_data) <imported_symtabs>:
	Move earlier.

Change-Id: I314ddaa6f67c53a848e513b3f6d42913bd957833
---
 gdb/ChangeLog     |  5 +++++
 gdb/dwarf2/read.h | 52 +++++++++++++++++++++++------------------------
 2 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 9eab657e14a..646a53fadd2 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -317,6 +317,32 @@ struct dwarf2_per_cu_data
     struct dwarf2_per_cu_quick_data *quick;
   } v;
 
+  /* The CUs we import using DW_TAG_imported_unit.  This is filled in
+     while reading psymtabs, used to compute the psymtab dependencies,
+     and then cleared.  Then it is filled in again while reading full
+     symbols, and only deleted when the objfile is destroyed.
+
+     This is also used to work around a difference between the way gold
+     generates .gdb_index version <=7 and the way gdb does.  Arguably this
+     is a gold bug.  For symbols coming from TUs, gold records in the index
+     the CU that includes the TU instead of the TU itself.  This breaks
+     dw2_lookup_symbol: It assumes that if the index says symbol X lives
+     in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
+     will find X.  Alas TUs live in their own symtab, so after expanding CU Y
+     we need to look in TU Z to find X.  Fortunately, this is akin to
+     DW_TAG_imported_unit, so we just use the same mechanism: For
+     .gdb_index version <=7 this also records the TUs that the CU referred
+     to.  Concurrently with this change gdb was modified to emit version 8
+     indices so we only pay a price for gold generated indices.
+     http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
+
+     This currently needs to be a public member due to how
+     dwarf2_per_cu_data is allocated and used.  Ideally in future things
+     could be refactored to make this private.  Until then please try to
+     avoid direct access to this member, and instead use the helper
+     functions above.  */
+  std::vector <dwarf2_per_cu_data *> *imported_symtabs;
+
   /* Return true of IMPORTED_SYMTABS is empty or not yet allocated.  */
   bool imported_symtabs_empty () const
   {
@@ -347,32 +373,6 @@ struct dwarf2_per_cu_data
     delete imported_symtabs;
     imported_symtabs = nullptr;
   }
-
-  /* The CUs we import using DW_TAG_imported_unit.  This is filled in
-     while reading psymtabs, used to compute the psymtab dependencies,
-     and then cleared.  Then it is filled in again while reading full
-     symbols, and only deleted when the objfile is destroyed.
-
-     This is also used to work around a difference between the way gold
-     generates .gdb_index version <=7 and the way gdb does.  Arguably this
-     is a gold bug.  For symbols coming from TUs, gold records in the index
-     the CU that includes the TU instead of the TU itself.  This breaks
-     dw2_lookup_symbol: It assumes that if the index says symbol X lives
-     in CU/TU Y, then one need only expand Y and a subsequent lookup in Y
-     will find X.  Alas TUs live in their own symtab, so after expanding CU Y
-     we need to look in TU Z to find X.  Fortunately, this is akin to
-     DW_TAG_imported_unit, so we just use the same mechanism: For
-     .gdb_index version <=7 this also records the TUs that the CU referred
-     to.  Concurrently with this change gdb was modified to emit version 8
-     indices so we only pay a price for gold generated indices.
-     http://sourceware.org/bugzilla/show_bug.cgi?id=15021.
-
-     This currently needs to be a public member due to how
-     dwarf2_per_cu_data is allocated and used.  Ideally in future things
-     could be refactored to make this private.  Until then please try to
-     avoid direct access to this member, and instead use the helper
-     functions above.  */
-  std::vector <dwarf2_per_cu_data *> *imported_symtabs;
 };
 
 /* Entry in the signatured_types hash table.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 22/38] Minor simplification in abbrev_table::read
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (8 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 32/38] Move read_offset_1 to leb.c Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 13/38] Remove DWARF queue-related globals Tom Tromey
                   ` (28 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

abbrev_table::read increments cur_abbrev->num_attrs in the inner loop,
but there's no need to do this, as the information is already stored
in the temporary vector.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/abbrev.c (abbrev_table::read): Simplify.

Change-Id: I765f12850ffa1c6066e884bb22c94468d1abdba4
---
 gdb/ChangeLog       | 4 ++++
 gdb/dwarf2/abbrev.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
index f843e32d950..59ff138b33d 100644
--- a/gdb/dwarf2/abbrev.c
+++ b/gdb/dwarf2/abbrev.c
@@ -162,9 +162,9 @@ abbrev_table::read (struct objfile *objfile,
 	  cur_attr.name = (enum dwarf_attribute) abbrev_name;
 	  cur_attr.form = (enum dwarf_form) abbrev_form;
 	  cur_attr.implicit_const = implicit_const;
-	  ++cur_abbrev->num_attrs;
 	}
 
+      cur_abbrev->num_attrs = cur_attrs.size ();
       cur_abbrev->attrs =
 	XOBNEWVEC (&abbrev_table->m_abbrev_obstack, struct attr_abbrev,
 		   cur_abbrev->num_attrs);
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 17/38] Don't allocate DWO file hash on obstack
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (33 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 24/38] Move dwarf_always_disassemble to dwarf2/loc.c Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  1:12 ` [PATCH 03/38] Change section functions to be methods of dwarf2_section_info Tom Tromey
                   ` (3 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes allocate_dwo_file_hash_table so that it does not use the
objfile obstack to store the contents of the hash table.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (allocate_dwo_file_hash_table): Don't allocate on
	obstack.

Change-Id: Ic20a618acc7277e56aa18580c68f75c793bef97b
---
 gdb/ChangeLog     |  5 +++++
 gdb/dwarf2/read.c | 12 +++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 844ff8dc54b..2f87b9d2a50 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -11462,13 +11462,11 @@ allocate_dwo_file_hash_table (struct objfile *objfile)
       delete dwo_file;
     };
 
-  return htab_up (htab_create_alloc_ex (41,
-					hash_dwo_file,
-					eq_dwo_file,
-					delete_dwo_file,
-					&objfile->objfile_obstack,
-					hashtab_obstack_allocate,
-					dummy_obstack_deallocate));
+  return htab_up (htab_create_alloc (41,
+				     hash_dwo_file,
+				     eq_dwo_file,
+				     delete_dwo_file,
+				     xcalloc, xfree));
 }
 
 /* Lookup DWO file DWO_NAME.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 31/38] Convert dwarf2_section_size to a method
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (2 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 16/38] Change dwarf2_per_objfile::line_header_hash to htab_up Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 19/38] Change dwarf2_per_objfile::die_type_hash to htab_up Tom Tromey
                   ` (34 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes dwarf2_section_size to be a method on
dwarf2_section_info.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (dwarf2_section_size): Remove.
	(error_check_comp_unit_head, dwarf2_symbol_mark_computed):
	Update.
	* dwarf2/section.h (struct dwarf2_section_info) <get_size>: New method.

Change-Id: I12928fee5c84350ce98883e329357b86888d639b
---
 gdb/ChangeLog        |  7 +++++++
 gdb/dwarf2/read.c    | 20 ++------------------
 gdb/dwarf2/section.h | 13 +++++++++++++
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 65e39b22b4f..9db6529c4b8 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2078,22 +2078,6 @@ dwarf2_per_objfile::locate_sections (bfd *abfd, asection *sectp,
     this->has_section_at_zero = true;
 }
 
-/* A helper function that returns the size of a section in a safe way.
-   If you are positive that the section has been read before using the
-   size, then it is safe to refer to the dwarf2_section_info object's
-   "size" field directly.  In other cases, you must call this
-   function, because for compressed sections the size field is not set
-   correctly until the section has been read.  */
-
-static bfd_size_type
-dwarf2_section_size (struct objfile *objfile,
-		     struct dwarf2_section_info *info)
-{
-  if (!info->readin)
-    info->read (objfile);
-  return info->size;
-}
-
 /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and
    SECTION_NAME.  */
 
@@ -6097,7 +6081,7 @@ error_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
   const char *filename = section->get_file_name ();
 
   if (to_underlying (header->abbrev_sect_off)
-      >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
+      >= abbrev_section->get_size (dwarf2_per_objfile->objfile))
     error (_("Dwarf Error: bad offset (%s) in compilation unit header "
 	   "(offset %s + 6) [in module %s]"),
 	   sect_offset_str (header->abbrev_sect_off),
@@ -24438,7 +24422,7 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
       /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside
 	 the section.  If so, fall through to the complaint in the
 	 other branch.  */
-      && DW_UNSND (attr) < dwarf2_section_size (objfile, section))
+      && DW_UNSND (attr) < section->get_size (objfile))
     {
       struct dwarf2_loclist_baton *baton;
 
diff --git a/gdb/dwarf2/section.h b/gdb/dwarf2/section.h
index f76f1ef7bf5..8ddedcaf761 100644
--- a/gdb/dwarf2/section.h
+++ b/gdb/dwarf2/section.h
@@ -81,6 +81,19 @@ struct dwarf2_section_info
      If the section is compressed, uncompress it before returning.  */
   void read (struct objfile *objfile);
 
+  /* A helper function that returns the size of a section in a safe way.
+     If you are positive that the section has been read before using the
+     size, then it is safe to refer to the dwarf2_section_info object's
+     "size" field directly.  In other cases, you must call this
+     function, because for compressed sections the size field is not set
+     correctly until the section has been read.  */
+  bfd_size_type get_size (struct objfile *objfile)
+  {
+    if (!readin)
+      read (objfile);
+    return size;
+  }
+
   union
   {
     /* If this is a real section, the bfd section.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 04/38] Create dwarf2/abbrev.[ch]
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (25 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 18/38] Change dwp_file to use htab_up Tom Tromey
@ 2020-01-23  0:57 ` Tom Tromey
  2020-01-23  0:57 ` [PATCH 12/38] Introduce die_info::has_children Tom Tromey
                   ` (11 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  0:57 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This moves the abbrev table code out of dwarf2read.c and into new
files dwarf2/abbrev.[ch].

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (abbrev_table_up, struct abbrev_info)
	(struct attr_abbrev, ABBREV_HASH_SIZE, struct abbrev_table):
	Move.
	(read_cutu_die_from_dwo, build_type_psymtabs_1): Update.
	(abbrev_table::alloc_abbrev, abbrev_table::add_abbrev)
	(abbrev_table::lookup_abbrev, abbrev_table_read_table): Move to
	abbrev.c.
	* dwarf2/abbrev.h: New file.
	* dwarf2/abbrev.c: New file, from dwarf2read.c.
	* Makefile.in (COMMON_SFILES): Add dwarf2/abbrev.c.

Change-Id: I87911bc5297de4407587ca849fef8e8d19136c30
---
 gdb/ChangeLog       |  13 +++
 gdb/Makefile.in     |   1 +
 gdb/dwarf2/abbrev.c | 178 ++++++++++++++++++++++++++++++++++
 gdb/dwarf2/abbrev.h | 103 ++++++++++++++++++++
 gdb/dwarf2read.c    | 229 +-------------------------------------------
 5 files changed, 300 insertions(+), 224 deletions(-)
 create mode 100644 gdb/dwarf2/abbrev.c
 create mode 100644 gdb/dwarf2/abbrev.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index c10ce71a50e..2188d32c4e6 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1002,6 +1002,7 @@ COMMON_SFILES = \
 	dwarf2expr.c \
 	dwarf2loc.c \
 	dwarf2read.c \
+	dwarf2/abbrev.c \
 	dwarf2/leb.c \
 	dwarf2/section.c \
 	eval.c \
diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
new file mode 100644
index 00000000000..6bd455f012b
--- /dev/null
+++ b/gdb/dwarf2/abbrev.c
@@ -0,0 +1,178 @@
+/* DWARF 2 abbreviations
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "dwarf2read.h"
+#include "dwarf2/abbrev.h"
+#include "dwarf2/leb.h"
+#include "bfd.h"
+
+/* Abbreviation tables.
+
+   In DWARF version 2, the description of the debugging information is
+   stored in a separate .debug_abbrev section.  Before we read any
+   dies from a section we read in all abbreviations and install them
+   in a hash table.  */
+
+/* Allocate space for a struct abbrev_info object in ABBREV_TABLE.  */
+
+struct abbrev_info *
+abbrev_table::alloc_abbrev ()
+{
+  struct abbrev_info *abbrev;
+
+  abbrev = XOBNEW (&abbrev_obstack, struct abbrev_info);
+  memset (abbrev, 0, sizeof (struct abbrev_info));
+
+  return abbrev;
+}
+
+/* Add an abbreviation to the table.  */
+
+void
+abbrev_table::add_abbrev (unsigned int abbrev_number,
+			  struct abbrev_info *abbrev)
+{
+  unsigned int hash_number;
+
+  hash_number = abbrev_number % ABBREV_HASH_SIZE;
+  abbrev->next = m_abbrevs[hash_number];
+  m_abbrevs[hash_number] = abbrev;
+}
+
+/* Look up an abbrev in the table.
+   Returns NULL if the abbrev is not found.  */
+
+struct abbrev_info *
+abbrev_table::lookup_abbrev (unsigned int abbrev_number)
+{
+  unsigned int hash_number;
+  struct abbrev_info *abbrev;
+
+  hash_number = abbrev_number % ABBREV_HASH_SIZE;
+  abbrev = m_abbrevs[hash_number];
+
+  while (abbrev)
+    {
+      if (abbrev->number == abbrev_number)
+	return abbrev;
+      abbrev = abbrev->next;
+    }
+  return NULL;
+}
+
+/* Read in an abbrev table.  */
+
+abbrev_table_up
+abbrev_table_read_table (struct objfile *objfile,
+			 struct dwarf2_section_info *section,
+			 sect_offset sect_off)
+{
+  bfd *abfd = section->get_bfd_owner ();
+  const gdb_byte *abbrev_ptr;
+  struct abbrev_info *cur_abbrev;
+  unsigned int abbrev_number, bytes_read, abbrev_name;
+  unsigned int abbrev_form;
+  std::vector<struct attr_abbrev> cur_attrs;
+
+  abbrev_table_up abbrev_table (new struct abbrev_table (sect_off));
+
+  section->read (objfile);
+  abbrev_ptr = section->buffer + to_underlying (sect_off);
+  abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
+  abbrev_ptr += bytes_read;
+
+  /* Loop until we reach an abbrev number of 0.  */
+  while (abbrev_number)
+    {
+      cur_attrs.clear ();
+      cur_abbrev = abbrev_table->alloc_abbrev ();
+
+      /* read in abbrev header */
+      cur_abbrev->number = abbrev_number;
+      cur_abbrev->tag
+	= (enum dwarf_tag) read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
+      abbrev_ptr += bytes_read;
+      cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
+      abbrev_ptr += 1;
+
+      /* now read in declarations */
+      for (;;)
+	{
+	  LONGEST implicit_const;
+
+	  abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
+	  abbrev_ptr += bytes_read;
+	  abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
+	  abbrev_ptr += bytes_read;
+	  if (abbrev_form == DW_FORM_implicit_const)
+	    {
+	      implicit_const = read_signed_leb128 (abfd, abbrev_ptr,
+						   &bytes_read);
+	      abbrev_ptr += bytes_read;
+	    }
+	  else
+	    {
+	      /* Initialize it due to a false compiler warning.  */
+	      implicit_const = -1;
+	    }
+
+	  if (abbrev_name == 0)
+	    break;
+
+	  cur_attrs.emplace_back ();
+	  struct attr_abbrev &cur_attr = cur_attrs.back ();
+	  cur_attr.name = (enum dwarf_attribute) abbrev_name;
+	  cur_attr.form = (enum dwarf_form) abbrev_form;
+	  cur_attr.implicit_const = implicit_const;
+	  ++cur_abbrev->num_attrs;
+	}
+
+      cur_abbrev->attrs =
+	XOBNEWVEC (&abbrev_table->abbrev_obstack, struct attr_abbrev,
+		   cur_abbrev->num_attrs);
+      memcpy (cur_abbrev->attrs, cur_attrs.data (),
+	      cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
+
+      abbrev_table->add_abbrev (abbrev_number, cur_abbrev);
+
+      /* Get next abbreviation.
+         Under Irix6 the abbreviations for a compilation unit are not
+         always properly terminated with an abbrev number of 0.
+         Exit loop if we encounter an abbreviation which we have
+         already read (which means we are about to read the abbreviations
+         for the next compile unit) or if the end of the abbreviation
+         table is reached.  */
+      if ((unsigned int) (abbrev_ptr - section->buffer) >= section->size)
+	break;
+      abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
+      abbrev_ptr += bytes_read;
+      if (abbrev_table->lookup_abbrev (abbrev_number) != NULL)
+	break;
+    }
+
+  return abbrev_table;
+}
diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h
new file mode 100644
index 00000000000..df83c093be2
--- /dev/null
+++ b/gdb/dwarf2/abbrev.h
@@ -0,0 +1,103 @@
+/* DWARF abbrev table
+
+   Copyright (C) 1994-2020 Free Software Foundation, Inc.
+
+   Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology,
+   Inc.  with support from Florida State University (under contract
+   with the Ada Joint Program Office), and Silicon Graphics, Inc.
+   Initial contribution by Brent Benson, Harris Computer Systems, Inc.,
+   based on Fred Fish's (Cygnus Support) implementation of DWARF 1
+   support.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef GDB_DWARF2_ABBREV_H
+#define GDB_DWARF2_ABBREV_H
+
+/* This data structure holds the information of an abbrev.  */
+struct abbrev_info
+  {
+    unsigned int number;	/* number identifying abbrev */
+    enum dwarf_tag tag;		/* dwarf tag */
+    unsigned short has_children;		/* boolean */
+    unsigned short num_attrs;	/* number of attributes */
+    struct attr_abbrev *attrs;	/* an array of attribute descriptions */
+    struct abbrev_info *next;	/* next in chain */
+  };
+
+struct attr_abbrev
+  {
+    ENUM_BITFIELD(dwarf_attribute) name : 16;
+    ENUM_BITFIELD(dwarf_form) form : 16;
+
+    /* It is valid only if FORM is DW_FORM_implicit_const.  */
+    LONGEST implicit_const;
+  };
+
+/* Size of abbrev_table.abbrev_hash_table.  */
+#define ABBREV_HASH_SIZE 121
+
+/* Top level data structure to contain an abbreviation table.  */
+
+struct abbrev_table
+{
+  explicit abbrev_table (sect_offset off)
+    : sect_off (off)
+  {
+    m_abbrevs =
+      XOBNEWVEC (&abbrev_obstack, struct abbrev_info *, ABBREV_HASH_SIZE);
+    memset (m_abbrevs, 0, ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
+  }
+
+  DISABLE_COPY_AND_ASSIGN (abbrev_table);
+
+  /* Allocate space for a struct abbrev_info object in
+     ABBREV_TABLE.  */
+  struct abbrev_info *alloc_abbrev ();
+
+  /* Add an abbreviation to the table.  */
+  void add_abbrev (unsigned int abbrev_number, struct abbrev_info *abbrev);
+
+  /* Look up an abbrev in the table.
+     Returns NULL if the abbrev is not found.  */
+
+  struct abbrev_info *lookup_abbrev (unsigned int abbrev_number);
+
+
+  /* Where the abbrev table came from.
+     This is used as a sanity check when the table is used.  */
+  const sect_offset sect_off;
+
+  /* Storage for the abbrev table.  */
+  auto_obstack abbrev_obstack;
+
+private:
+
+  /* Hash table of abbrevs.
+     This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
+     It could be statically allocated, but the previous code didn't so we
+     don't either.  */
+  struct abbrev_info **m_abbrevs;
+};
+
+typedef std::unique_ptr<struct abbrev_table> abbrev_table_up;
+
+extern abbrev_table_up abbrev_table_read_table
+  (struct objfile *objfile,
+   struct dwarf2_section_info *section,
+   sect_offset sect_off);
+
+#endif /* GDB_DWARF2_ABBREV_H */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index c1fdbccd8d3..886bec1d7aa 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -30,6 +30,7 @@
 
 #include "defs.h"
 #include "dwarf2read.h"
+#include "dwarf2/abbrev.h"
 #include "dwarf-index-cache.h"
 #include "dwarf-index-common.h"
 #include "dwarf2/leb.h"
@@ -875,9 +876,6 @@ struct dwp_file
   asection **elf_sections = nullptr;
 };
 
-struct abbrev_table;
-typedef std::unique_ptr<struct abbrev_table> abbrev_table_up;
-
 /* Struct used to pass misc. parameters to read_die_and_children, et
    al.  which are used for both .debug_info and .debug_types dies.
    All parameters here are unchanging for the life of the call.  This
@@ -1235,72 +1233,6 @@ struct partial_die_info : public allocate_on_obstack
     }
   };
 
-/* This data structure holds the information of an abbrev.  */
-struct abbrev_info
-  {
-    unsigned int number;	/* number identifying abbrev */
-    enum dwarf_tag tag;		/* dwarf tag */
-    unsigned short has_children;		/* boolean */
-    unsigned short num_attrs;	/* number of attributes */
-    struct attr_abbrev *attrs;	/* an array of attribute descriptions */
-    struct abbrev_info *next;	/* next in chain */
-  };
-
-struct attr_abbrev
-  {
-    ENUM_BITFIELD(dwarf_attribute) name : 16;
-    ENUM_BITFIELD(dwarf_form) form : 16;
-
-    /* It is valid only if FORM is DW_FORM_implicit_const.  */
-    LONGEST implicit_const;
-  };
-
-/* Size of abbrev_table.abbrev_hash_table.  */
-#define ABBREV_HASH_SIZE 121
-
-/* Top level data structure to contain an abbreviation table.  */
-
-struct abbrev_table
-{
-  explicit abbrev_table (sect_offset off)
-    : sect_off (off)
-  {
-    m_abbrevs =
-      XOBNEWVEC (&abbrev_obstack, struct abbrev_info *, ABBREV_HASH_SIZE);
-    memset (m_abbrevs, 0, ABBREV_HASH_SIZE * sizeof (struct abbrev_info *));
-  }
-
-  DISABLE_COPY_AND_ASSIGN (abbrev_table);
-
-  /* Allocate space for a struct abbrev_info object in
-     ABBREV_TABLE.  */
-  struct abbrev_info *alloc_abbrev ();
-
-  /* Add an abbreviation to the table.  */
-  void add_abbrev (unsigned int abbrev_number, struct abbrev_info *abbrev);
-
-  /* Look up an abbrev in the table.
-     Returns NULL if the abbrev is not found.  */
-
-  struct abbrev_info *lookup_abbrev (unsigned int abbrev_number);
-
-
-  /* Where the abbrev table came from.
-     This is used as a sanity check when the table is used.  */
-  const sect_offset sect_off;
-
-  /* Storage for the abbrev table.  */
-  auto_obstack abbrev_obstack;
-
-private:
-
-  /* Hash table of abbrevs.
-     This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack.
-     It could be statically allocated, but the previous code didn't so we
-     don't either.  */
-  struct abbrev_info **m_abbrevs;
-};
-
 /* Attributes have a name and a value.  */
 struct attribute
   {
@@ -1515,10 +1447,6 @@ static void dwarf2_read_symtab (struct partial_symtab *,
 
 static void psymtab_to_symtab_1 (struct partial_symtab *);
 
-static abbrev_table_up abbrev_table_read_table
-  (struct dwarf2_per_objfile *dwarf2_per_objfile, struct dwarf2_section_info *,
-   sect_offset);
-
 static unsigned int peek_abbrev_code (bfd *, const gdb_byte *);
 
 static struct partial_die_info *load_partial_dies
@@ -7213,7 +7141,7 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
     }
 
   *result_dwo_abbrev_table
-    = abbrev_table_read_table (dwarf2_per_objfile, dwo_abbrev_section,
+    = abbrev_table_read_table (objfile, dwo_abbrev_section,
 			       cu->header.abbrev_sect_off);
   init_cu_die_reader (result_reader, cu, section, dwo_unit->dwo_file,
 		      result_dwo_abbrev_table->get ());
@@ -7518,7 +7446,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
   else
     {
       m_abbrev_table_holder
-	= abbrev_table_read_table (dwarf2_per_objfile, abbrev_section,
+	= abbrev_table_read_table (objfile, abbrev_section,
 				   cu->header.abbrev_sect_off);
       abbrev_table = m_abbrev_table_holder.get ();
     }
@@ -7665,7 +7593,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
     }
 
   m_abbrev_table_holder
-    = abbrev_table_read_table (dwarf2_per_objfile, abbrev_section,
+    = abbrev_table_read_table (objfile, abbrev_section,
 			       m_new_cu->header.abbrev_sect_off);
 
   init_cu_die_reader (this, m_new_cu.get (), section, dwo_file,
@@ -8161,7 +8089,7 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
 	{
 	  abbrev_offset = tu.abbrev_offset;
 	  abbrev_table =
-	    abbrev_table_read_table (dwarf2_per_objfile,
+	    abbrev_table_read_table (dwarf2_per_objfile->objfile,
 				     &dwarf2_per_objfile->abbrev,
 				     abbrev_offset);
 	  ++tu_stats->nr_uniq_abbrev_tables;
@@ -18302,153 +18230,6 @@ read_full_die (const struct die_reader_specs *reader,
   return result;
 }
 \f
-/* Abbreviation tables.
-
-   In DWARF version 2, the description of the debugging information is
-   stored in a separate .debug_abbrev section.  Before we read any
-   dies from a section we read in all abbreviations and install them
-   in a hash table.  */
-
-/* Allocate space for a struct abbrev_info object in ABBREV_TABLE.  */
-
-struct abbrev_info *
-abbrev_table::alloc_abbrev ()
-{
-  struct abbrev_info *abbrev;
-
-  abbrev = XOBNEW (&abbrev_obstack, struct abbrev_info);
-  memset (abbrev, 0, sizeof (struct abbrev_info));
-
-  return abbrev;
-}
-
-/* Add an abbreviation to the table.  */
-
-void
-abbrev_table::add_abbrev (unsigned int abbrev_number,
-			  struct abbrev_info *abbrev)
-{
-  unsigned int hash_number;
-
-  hash_number = abbrev_number % ABBREV_HASH_SIZE;
-  abbrev->next = m_abbrevs[hash_number];
-  m_abbrevs[hash_number] = abbrev;
-}
-
-/* Look up an abbrev in the table.
-   Returns NULL if the abbrev is not found.  */
-
-struct abbrev_info *
-abbrev_table::lookup_abbrev (unsigned int abbrev_number)
-{
-  unsigned int hash_number;
-  struct abbrev_info *abbrev;
-
-  hash_number = abbrev_number % ABBREV_HASH_SIZE;
-  abbrev = m_abbrevs[hash_number];
-
-  while (abbrev)
-    {
-      if (abbrev->number == abbrev_number)
-	return abbrev;
-      abbrev = abbrev->next;
-    }
-  return NULL;
-}
-
-/* Read in an abbrev table.  */
-
-static abbrev_table_up
-abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
-			 struct dwarf2_section_info *section,
-			 sect_offset sect_off)
-{
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
-  bfd *abfd = section->get_bfd_owner ();
-  const gdb_byte *abbrev_ptr;
-  struct abbrev_info *cur_abbrev;
-  unsigned int abbrev_number, bytes_read, abbrev_name;
-  unsigned int abbrev_form;
-  std::vector<struct attr_abbrev> cur_attrs;
-
-  abbrev_table_up abbrev_table (new struct abbrev_table (sect_off));
-
-  section->read (objfile);
-  abbrev_ptr = section->buffer + to_underlying (sect_off);
-  abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
-  abbrev_ptr += bytes_read;
-
-  /* Loop until we reach an abbrev number of 0.  */
-  while (abbrev_number)
-    {
-      cur_attrs.clear ();
-      cur_abbrev = abbrev_table->alloc_abbrev ();
-
-      /* read in abbrev header */
-      cur_abbrev->number = abbrev_number;
-      cur_abbrev->tag
-	= (enum dwarf_tag) read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
-      abbrev_ptr += bytes_read;
-      cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr);
-      abbrev_ptr += 1;
-
-      /* now read in declarations */
-      for (;;)
-	{
-	  LONGEST implicit_const;
-
-	  abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
-	  abbrev_ptr += bytes_read;
-	  abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
-	  abbrev_ptr += bytes_read;
-	  if (abbrev_form == DW_FORM_implicit_const)
-	    {
-	      implicit_const = read_signed_leb128 (abfd, abbrev_ptr,
-						   &bytes_read);
-	      abbrev_ptr += bytes_read;
-	    }
-	  else
-	    {
-	      /* Initialize it due to a false compiler warning.  */
-	      implicit_const = -1;
-	    }
-
-	  if (abbrev_name == 0)
-	    break;
-
-	  cur_attrs.emplace_back ();
-	  struct attr_abbrev &cur_attr = cur_attrs.back ();
-	  cur_attr.name = (enum dwarf_attribute) abbrev_name;
-	  cur_attr.form = (enum dwarf_form) abbrev_form;
-	  cur_attr.implicit_const = implicit_const;
-	  ++cur_abbrev->num_attrs;
-	}
-
-      cur_abbrev->attrs =
-	XOBNEWVEC (&abbrev_table->abbrev_obstack, struct attr_abbrev,
-		   cur_abbrev->num_attrs);
-      memcpy (cur_abbrev->attrs, cur_attrs.data (),
-	      cur_abbrev->num_attrs * sizeof (struct attr_abbrev));
-
-      abbrev_table->add_abbrev (abbrev_number, cur_abbrev);
-
-      /* Get next abbreviation.
-         Under Irix6 the abbreviations for a compilation unit are not
-         always properly terminated with an abbrev number of 0.
-         Exit loop if we encounter an abbreviation which we have
-         already read (which means we are about to read the abbreviations
-         for the next compile unit) or if the end of the abbreviation
-         table is reached.  */
-      if ((unsigned int) (abbrev_ptr - section->buffer) >= section->size)
-	break;
-      abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
-      abbrev_ptr += bytes_read;
-      if (abbrev_table->lookup_abbrev (abbrev_number) != NULL)
-	break;
-    }
-
-  return abbrev_table;
-}
 
 /* Returns nonzero if TAG represents a type that we might generate a partial
    symbol for.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 03/38] Change section functions to be methods of dwarf2_section_info
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (34 preceding siblings ...)
  2020-01-23  0:57 ` [PATCH 17/38] Don't allocate DWO file hash on obstack Tom Tromey
@ 2020-01-23  1:12 ` Tom Tromey
  2020-01-23  1:21 ` [PATCH 29/38] Add some methods to dwarf2_per_cu_data Tom Tromey
                   ` (2 subsequent siblings)
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  1:12 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes various section-related functions to be methods on
dwarf2_section_info.  I think this clarifies the role of these
functions.  This also changes one such function to return bool.

gdb/ChangeLog
2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_section_buffer_overflow_complaint)
	(dwarf2_section_size, dwarf2_get_section_info)
	(create_signatured_type_table_from_debug_names)
	(create_addrmap_from_aranges, read_debug_names_from_section)
	(get_gdb_index_contents_from_section, read_comp_unit_head)
	(error_check_comp_unit_head, read_abbrev_offset)
	(create_debug_type_hash_table, init_cu_die_reader)
	(read_cutu_die_from_dwo, dwarf2_build_psymtabs_hard)
	(read_comp_units_from_section, create_cus_hash_table)
	(create_dwp_hash_table, create_dwo_unit_in_dwp_v1)
	(create_dwp_v2_section, dwarf2_rnglists_process)
	(dwarf2_ranges_process, read_die_and_siblings, read_full_die)
	(abbrev_table_read_table, read_indirect_string_at_offset_from)
	(read_indirect_string_from_dwz, read_addr_index_1)
	(read_str_index, dwarf_decode_line_header, skip_form_bytes)
	(dwarf_decode_macro_bytes, dwarf_decode_macros)
	(fill_in_loclist_baton): Update.
	* dwarf2/section.h (struct dwarf2_section_info) <get_name,
	get_containing_section, get_bfd_owner, get_bfd_section,
	get_file_name, get_id, get_flags, empty, read>: Declare methods.
	(dwarf2_read_section, get_section_name, get_section_file_name)
	(get_containing_section, get_section_bfd_owner)
	(get_section_bfd_section, get_section_name, get_section_file_name)
	(get_section_id, get_section_flags, dwarf2_section_empty_p): Don't
	declare.
	* dwarf2/section.c (dwarf2_section_info::get_containing_section)
	(dwarf2_section_info::get_bfd_owner)
	(dwarf2_section_info::get_bfd_section)
	(dwarf2_section_info::get_name)
	(dwarf2_section_info::get_file_name, dwarf2_section_info::get_id)
	(dwarf2_section_info::get_flags, dwarf2_section_info::empty)
	(dwarf2_section_info::read): Now methods.
	* dwarf-index-write.c (class debug_names): Update.

Change-Id: Ic849f182f57a18bad6b1c7c3b9368005d307758a
---
 gdb/ChangeLog           |  36 +++++++++++
 gdb/dwarf-index-write.c |   3 +-
 gdb/dwarf2/section.c    |  81 +++++++++++------------
 gdb/dwarf2/section.h    |  87 +++++++++++--------------
 gdb/dwarf2read.c        | 138 ++++++++++++++++++++--------------------
 5 files changed, 183 insertions(+), 162 deletions(-)

diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index fd222628cf5..c43a4817b97 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -959,8 +959,7 @@ private:
       : m_abfd (dwarf2_per_objfile->objfile->obfd),
 	m_dwarf2_per_objfile (dwarf2_per_objfile)
     {
-      dwarf2_read_section (dwarf2_per_objfile->objfile,
-			   &dwarf2_per_objfile->str);
+      dwarf2_per_objfile->str.read (dwarf2_per_objfile->objfile);
       if (dwarf2_per_objfile->str.buffer == NULL)
 	return;
       for (const gdb_byte *data = dwarf2_per_objfile->str.buffer;
diff --git a/gdb/dwarf2/section.c b/gdb/dwarf2/section.c
index 618ab9adf12..5e33809117d 100644
--- a/gdb/dwarf2/section.c
+++ b/gdb/dwarf2/section.c
@@ -30,55 +30,57 @@
 #include "objfiles.h"
 
 struct dwarf2_section_info *
-get_containing_section (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_containing_section () const
 {
-  gdb_assert (section->is_virtual);
-  return section->s.containing_section;
+  gdb_assert (is_virtual);
+  return s.containing_section;
 }
 
 struct bfd *
-get_section_bfd_owner (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_bfd_owner () const
 {
-  if (section->is_virtual)
+  const dwarf2_section_info *section = this;
+  if (is_virtual)
     {
-      section = get_containing_section (section);
+      section = get_containing_section ();
       gdb_assert (!section->is_virtual);
     }
   return section->s.section->owner;
 }
 
 asection *
-get_section_bfd_section (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_bfd_section () const
 {
+  const dwarf2_section_info *section = this;
   if (section->is_virtual)
     {
-      section = get_containing_section (section);
+      section = get_containing_section ();
       gdb_assert (!section->is_virtual);
     }
   return section->s.section;
 }
 
 const char *
-get_section_name (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_name () const
 {
-  asection *sectp = get_section_bfd_section (section);
+  asection *sectp = get_bfd_section ();
 
   gdb_assert (sectp != NULL);
   return bfd_section_name (sectp);
 }
 
 const char *
-get_section_file_name (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_file_name () const
 {
-  bfd *abfd = get_section_bfd_owner (section);
+  bfd *abfd = get_bfd_owner ();
 
   return bfd_get_filename (abfd);
 }
 
 int
-get_section_id (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_id () const
 {
-  asection *sectp = get_section_bfd_section (section);
+  asection *sectp = get_bfd_section ();
 
   if (sectp == NULL)
     return 0;
@@ -86,61 +88,60 @@ get_section_id (const struct dwarf2_section_info *section)
 }
 
 int
-get_section_flags (const struct dwarf2_section_info *section)
+dwarf2_section_info::get_flags () const
 {
-  asection *sectp = get_section_bfd_section (section);
+  asection *sectp = get_bfd_section ();
 
   gdb_assert (sectp != NULL);
   return bfd_section_flags (sectp);
 }
 
-int
-dwarf2_section_empty_p (const struct dwarf2_section_info *section)
+bool
+dwarf2_section_info::empty () const
 {
-  if (section->is_virtual)
-    return section->size == 0;
-  return section->s.section == NULL || section->size == 0;
+  if (is_virtual)
+    return size == 0;
+  return s.section == NULL || size == 0;
 }
 
 void
-dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
+dwarf2_section_info::read (struct objfile *objfile)
 {
   asection *sectp;
   bfd *abfd;
   gdb_byte *buf, *retbuf;
 
-  if (info->readin)
+  if (readin)
     return;
-  info->buffer = NULL;
-  info->readin = true;
+  buffer = NULL;
+  readin = true;
 
-  if (dwarf2_section_empty_p (info))
+  if (empty ())
     return;
 
-  sectp = get_section_bfd_section (info);
+  sectp = get_bfd_section ();
 
   /* If this is a virtual section we need to read in the real one first.  */
-  if (info->is_virtual)
+  if (is_virtual)
     {
       struct dwarf2_section_info *containing_section =
-	get_containing_section (info);
+	get_containing_section ();
 
       gdb_assert (sectp != NULL);
       if ((sectp->flags & SEC_RELOC) != 0)
 	{
 	  error (_("Dwarf Error: DWP format V2 with relocations is not"
 		   " supported in section %s [in module %s]"),
-		 get_section_name (info), get_section_file_name (info));
+		 get_name (), get_file_name ());
 	}
-      dwarf2_read_section (objfile, containing_section);
+      containing_section->read (objfile);
       /* Other code should have already caught virtual sections that don't
 	 fit.  */
-      gdb_assert (info->virtual_offset + info->size
-		  <= containing_section->size);
+      gdb_assert (virtual_offset + size <= containing_section->size);
       /* If the real section is empty or there was a problem reading the
 	 section we shouldn't get here.  */
       gdb_assert (containing_section->buffer != NULL);
-      info->buffer = containing_section->buffer + info->virtual_offset;
+      buffer = containing_section->buffer + virtual_offset;
       return;
     }
 
@@ -148,12 +149,12 @@ dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
      Otherwise we attach it to the BFD.  */
   if ((sectp->flags & SEC_RELOC) == 0)
     {
-      info->buffer = gdb_bfd_map_section (sectp, &info->size);
+      buffer = gdb_bfd_map_section (sectp, &size);
       return;
     }
 
-  buf = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, info->size);
-  info->buffer = buf;
+  buf = (gdb_byte *) obstack_alloc (&objfile->objfile_obstack, size);
+  buffer = buf;
 
   /* When debugging .o files, we may need to apply relocations; see
      http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html .
@@ -162,15 +163,15 @@ dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
   retbuf = symfile_relocate_debug_section (objfile, sectp, buf);
   if (retbuf != NULL)
     {
-      info->buffer = retbuf;
+      buffer = retbuf;
       return;
     }
 
-  abfd = get_section_bfd_owner (info);
+  abfd = get_bfd_owner ();
   gdb_assert (abfd != NULL);
 
   if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0
-      || bfd_bread (buf, info->size, abfd) != info->size)
+      || bfd_bread (buf, size, abfd) != size)
     {
       error (_("Dwarf Error: Can't read DWARF data"
 	       " in section %s [in module %s]"),
diff --git a/gdb/dwarf2/section.h b/gdb/dwarf2/section.h
index a1acc5f9e66..f76f1ef7bf5 100644
--- a/gdb/dwarf2/section.h
+++ b/gdb/dwarf2/section.h
@@ -45,6 +45,42 @@
 
 struct dwarf2_section_info
 {
+  /* Return the name of this section.  */
+  const char *get_name () const;
+
+  /* Return the containing section of this section, which must be a
+     virtual section.  */
+  struct dwarf2_section_info *get_containing_section () const;
+
+  /* Return the bfd owner of this section.  */
+  struct bfd *get_bfd_owner () const;
+
+  /* Return the bfd section of this section.
+     Returns NULL if the section is not present.  */
+  asection *get_bfd_section () const;
+
+  /* Return the name of the file this section is in.  */
+  const char *get_file_name () const;
+
+  /* Return the id of this section.
+     Returns 0 if this section doesn't exist.  */
+  int get_id () const;
+
+  /* Return the flags of this section.  This section (or containing
+     section if this is a virtual section) must exist.  */
+  int get_flags () const;
+
+  /* Return true if this section does not exist or if it has no
+     contents. */
+  bool empty () const;
+
+  /* Read the contents of this section.
+     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
+     of the DWO file.
+     If the section is compressed, uncompress it before returning.  */
+  void read (struct objfile *objfile);
+
   union
   {
     /* If this is a real section, the bfd section.  */
@@ -67,55 +103,4 @@ struct dwarf2_section_info
   bool is_virtual;
 };
 
-/* 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
-   of the DWO file.
-   If the section is compressed, uncompress it before returning.  */
-
-extern void dwarf2_read_section (struct objfile *objfile,
-				 dwarf2_section_info *info);
-
-extern const char *get_section_name (const struct dwarf2_section_info *);
-
-extern const char *get_section_file_name (const struct dwarf2_section_info *);
-
-/* Return the containing section of virtual section SECTION.  */
-
-extern struct dwarf2_section_info *get_containing_section
-  (const struct dwarf2_section_info *section);
-
-/* Return the bfd owner of SECTION.  */
-
-extern struct bfd *get_section_bfd_owner
-  (const struct dwarf2_section_info *section);
-
-/* Return the bfd section of SECTION.
-   Returns NULL if the section is not present.  */
-
-extern asection *get_section_bfd_section
-  (const struct dwarf2_section_info *section);
-
-/* Return the name of SECTION.  */
-
-extern const char *get_section_name
-  (const struct dwarf2_section_info *section);
-
-/* Return the name of the file SECTION is in.  */
-
-extern const char *get_section_file_name
-  (const struct dwarf2_section_info *section);
-
-/* Return the id of SECTION.
-   Returns 0 if SECTION doesn't exist.  */
-
-extern int get_section_id (const struct dwarf2_section_info *section);
-
-/* Return the flags of SECTION.
-   SECTION (or containing section if this is a virtual section) must exist.  */
-
-extern int get_section_flags (const struct dwarf2_section_info *section);
-
-extern int dwarf2_section_empty_p (const struct dwarf2_section_info *section);
-
 #endif /* GDB_DWARF2_SECTION_H */
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4eabda98be5..c1fdbccd8d3 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2076,8 +2076,8 @@ dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section)
 {
   complaint (_("debug info runs off end of %s section"
 	       " [in module %s]"),
-	     get_section_name (section),
-	     get_section_file_name (section));
+	     section->get_name (),
+	     section->get_file_name ());
 }
 
 static void
@@ -2419,7 +2419,7 @@ dwarf2_section_size (struct objfile *objfile,
 		     struct dwarf2_section_info *info)
 {
   if (!info->readin)
-    dwarf2_read_section (objfile, info);
+    info->read (objfile);
   return info->size;
 }
 
@@ -2456,9 +2456,9 @@ dwarf2_get_section_info (struct objfile *objfile,
       gdb_assert_not_reached ("unexpected section");
     }
 
-  dwarf2_read_section (objfile, info);
+  info->read (objfile);
 
-  *sectp = get_section_bfd_section (info);
+  *sectp = info->get_bfd_section ();
   *bufp = info->buffer;
   *sizep = info->size;
 }
@@ -2958,8 +2958,8 @@ create_signatured_type_table_from_debug_names
 {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
 
-  dwarf2_read_section (objfile, section);
-  dwarf2_read_section (objfile, abbrev_section);
+  section->read (objfile);
+  abbrev_section->read (objfile);
 
   gdb_assert (dwarf2_per_objfile->all_type_units.empty ());
   dwarf2_per_objfile->all_type_units.reserve (map.tu_count);
@@ -3092,7 +3092,7 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
 	}
     }
 
-  dwarf2_read_section (objfile, section);
+  section->read (objfile);
 
   const bfd_endian dwarf5_byte_order = gdbarch_byte_order (gdbarch);
 
@@ -5219,21 +5219,21 @@ read_debug_names_from_section (struct objfile *objfile,
 			       struct dwarf2_section_info *section,
 			       mapped_debug_names &map)
 {
-  if (dwarf2_section_empty_p (section))
+  if (section->empty ())
     return false;
 
   /* Older elfutils strip versions could keep the section in the main
      executable while splitting it for the separate debug info file.  */
-  if ((get_section_flags (section) & SEC_HAS_CONTENTS) == 0)
+  if ((section->get_flags () & SEC_HAS_CONTENTS) == 0)
     return false;
 
-  dwarf2_read_section (objfile, section);
+  section->read (objfile);
 
   map.dwarf5_byte_order = gdbarch_byte_order (get_objfile_arch (objfile));
 
   const gdb_byte *addr = section->buffer;
 
-  bfd *const abfd = get_section_bfd_owner (section);
+  bfd *const abfd = section->get_bfd_owner ();
 
   unsigned int bytes_read;
   LONGEST length = read_initial_length (abfd, addr, &bytes_read);
@@ -6093,15 +6093,15 @@ get_gdb_index_contents_from_section (objfile *obj, T *section_owner)
 {
   dwarf2_section_info *section = &section_owner->gdb_index;
 
-  if (dwarf2_section_empty_p (section))
+  if (section->empty ())
     return {};
 
   /* Older elfutils strip versions could keep the section in the main
      executable while splitting it for the separate debug info file.  */
-  if ((get_section_flags (section) & SEC_HAS_CONTENTS) == 0)
+  if ((section->get_flags () & SEC_HAS_CONTENTS) == 0)
     return {};
 
-  dwarf2_read_section (obj, section);
+  section->read (obj);
 
   /* dwarf2_section_info::size is a bfd_size_type, while
      gdb::array_view works with size_t.  On 32-bit hosts, with
@@ -6296,8 +6296,8 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
 {
   int signed_addr;
   unsigned int bytes_read;
-  const char *filename = get_section_file_name (section);
-  bfd *abfd = get_section_bfd_owner (section);
+  const char *filename = section->get_file_name ();
+  bfd *abfd = section->get_bfd_owner ();
 
   cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
   cu_header->initial_length_size = bytes_read;
@@ -6424,7 +6424,7 @@ error_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
 			    struct dwarf2_section_info *section,
 			    struct dwarf2_section_info *abbrev_section)
 {
-  const char *filename = get_section_file_name (section);
+  const char *filename = section->get_file_name ();
 
   if (to_underlying (header->abbrev_sect_off)
       >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section))
@@ -6477,12 +6477,12 @@ read_abbrev_offset (struct dwarf2_per_objfile *dwarf2_per_objfile,
 		    struct dwarf2_section_info *section,
 		    sect_offset sect_off)
 {
-  bfd *abfd = get_section_bfd_owner (section);
+  bfd *abfd = section->get_bfd_owner ();
   const gdb_byte *info_ptr;
   unsigned int initial_length_size, offset_size;
   uint16_t version;
 
-  dwarf2_read_section (dwarf2_per_objfile->objfile, section);
+  section->read (dwarf2_per_objfile->objfile);
   info_ptr = section->buffer + to_underlying (sect_off);
   read_initial_length (abfd, info_ptr, &initial_length_size);
   offset_size = initial_length_size == 4 ? 4 : 8;
@@ -6620,10 +6620,10 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   if (dwarf_read_debug)
     fprintf_unfiltered (gdb_stdlog, "Reading %s for %s:\n",
-			get_section_name (section),
-			get_section_file_name (abbrev_section));
+			section->get_name (),
+			abbrev_section->get_file_name ());
 
-  dwarf2_read_section (objfile, section);
+  section->read (objfile);
   info_ptr = section->buffer;
 
   if (info_ptr == NULL)
@@ -6631,7 +6631,7 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   /* We can't set abfd until now because the section may be empty or
      not present, in which case the bfd is unknown.  */
-  abfd = get_section_bfd_owner (section);
+  abfd = section->get_bfd_owner ();
 
   /* We don't use cutu_reader here because we don't need to read
      any dies: the signature is in the header.  */
@@ -7067,7 +7067,7 @@ init_cu_die_reader (struct die_reader_specs *reader,
 		    struct abbrev_table *abbrev_table)
 {
   gdb_assert (section->readin && section->buffer != NULL);
-  reader->abfd = get_section_bfd_owner (section);
+  reader->abfd = section->get_bfd_owner ();
   reader->cu = cu;
   reader->dwo_file = dwo_file;
   reader->die_section = section;
@@ -7165,8 +7165,8 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
   /* Set up for reading the DWO CU/TU.  */
   cu->dwo_unit = dwo_unit;
   dwarf2_section_info *section = dwo_unit->section;
-  dwarf2_read_section (objfile, section);
-  abfd = get_section_bfd_owner (section);
+  section->read (objfile);
+  abfd = section->get_bfd_owner ();
   begin_info_ptr = info_ptr = (section->buffer
 			       + to_underlying (dwo_unit->sect_off));
   dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev;
@@ -7249,7 +7249,7 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
     {
       fprintf_unfiltered (gdb_stdlog,
 			  "Read die from %s@0x%x of %s:\n",
-			  get_section_name (section),
+			  section->get_name (),
 			  (unsigned) (begin_info_ptr - section->buffer),
 			  bfd_get_filename (abfd));
       dump_die (comp_unit_die, dwarf_die_debug);
@@ -7399,7 +7399,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
   struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct dwarf2_section_info *section = this_cu->section;
-  bfd *abfd = get_section_bfd_owner (section);
+  bfd *abfd = section->get_bfd_owner ();
   struct dwarf2_cu *cu;
   const gdb_byte *begin_info_ptr;
   struct signatured_type *sig_type = NULL;
@@ -7429,7 +7429,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
     }
 
   /* This is cheap if the section is already read in.  */
-  dwarf2_read_section (objfile, section);
+  section->read (objfile);
 
   begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off);
 
@@ -7620,7 +7620,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
   struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct dwarf2_section_info *section = this_cu->section;
-  bfd *abfd = get_section_bfd_owner (section);
+  bfd *abfd = section->get_bfd_owner ();
   struct dwarf2_section_info *abbrev_section;
   const gdb_byte *begin_info_ptr, *info_ptr;
   int has_children;
@@ -7637,7 +7637,7 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
 		    : get_abbrev_section_for_cu (this_cu));
 
   /* This is cheap if the section is already read in.  */
-  dwarf2_read_section (objfile, section);
+  section->read (objfile);
 
   m_new_cu.reset (new dwarf2_cu (this_cu));
 
@@ -8355,7 +8355,7 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   dwarf2_per_objfile->reading_partial_symbols = 1;
 
-  dwarf2_read_section (objfile, &dwarf2_per_objfile->info);
+  dwarf2_per_objfile->info.read (objfile);
 
   /* Any cached compilation units will be linked by the per-objfile
      read_in_chain.  Make sure to free them when we're done.  */
@@ -8434,10 +8434,10 @@ read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   if (dwarf_read_debug)
     fprintf_unfiltered (gdb_stdlog, "Reading %s for %s\n",
-			get_section_name (section),
-			get_section_file_name (section));
+			section->get_name (),
+			section->get_file_name ());
 
-  dwarf2_read_section (objfile, section);
+  section->read (objfile);
 
   info_ptr = section->buffer;
 
@@ -11783,7 +11783,7 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   const gdb_byte *info_ptr, *end_ptr;
 
-  dwarf2_read_section (objfile, &section);
+  section.read (objfile);
   info_ptr = section.buffer;
 
   if (info_ptr == NULL)
@@ -11792,8 +11792,8 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (dwarf_read_debug)
     {
       fprintf_unfiltered (gdb_stdlog, "Reading %s for %s:\n",
-			  get_section_name (&section),
-			  get_section_file_name (&section));
+			  section.get_name (),
+			  section.get_file_name ());
     }
 
   end_ptr = info_ptr + section.size;
@@ -11995,9 +11995,9 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
   else
     index = &dwp_file->sections.cu_index;
 
-  if (dwarf2_section_empty_p (index))
+  if (index->empty ())
     return NULL;
-  dwarf2_read_section (objfile, index);
+  index->read (objfile);
 
   index_ptr = index->buffer;
   index_end = index_ptr + index->size;
@@ -12287,8 +12287,8 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
     }
 
   if (i < 2
-      || dwarf2_section_empty_p (&sections.info_or_types)
-      || dwarf2_section_empty_p (&sections.abbrev))
+      || sections.info_or_types.empty ()
+      || sections.abbrev.empty ())
     {
       error (_("Dwarf Error: bad DWP hash table, missing DWO sections"
 	       " [in module %s]"),
@@ -12312,10 +12312,10 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   std::string virtual_dwo_name =
     string_printf ("virtual-dwo/%d-%d-%d-%d",
-		   get_section_id (&sections.abbrev),
-		   get_section_id (&sections.line),
-		   get_section_id (&sections.loc),
-		   get_section_id (&sections.str_offsets));
+		   sections.abbrev.get_id (),
+		   sections.line.get_id (),
+		   sections.loc.get_id (),
+		   sections.str_offsets.get_id ());
   /* Can we use an existing virtual DWO file?  */
   dwo_file_slot = lookup_dwo_file_slot (dwarf2_per_objfile,
 					virtual_dwo_name.c_str (),
@@ -12393,7 +12393,7 @@ create_dwp_v2_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (size == 0)
     return result;
 
-  sectp = get_section_bfd_section (section);
+  sectp = section->get_bfd_section ();
 
   /* Flag an error if the piece denoted by OFFSET,SIZE is outside the
      bounds of the real section.  This is a pretty-rare event, so just
@@ -14156,7 +14156,7 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
   found_base = cu->base_known;
   base = cu->base_address;
 
-  dwarf2_read_section (objfile, &dwarf2_per_objfile->rnglists);
+  dwarf2_per_objfile->rnglists.read (objfile);
   if (offset >= dwarf2_per_objfile->rnglists.size)
     {
       complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
@@ -14324,7 +14324,7 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
   found_base = cu->base_known;
   base = cu->base_address;
 
-  dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
+  dwarf2_per_objfile->ranges.read (objfile);
   if (offset >= dwarf2_per_objfile->ranges.size)
     {
       complaint (_("Offset %d out of bounds for DW_AT_ranges attribute"),
@@ -18196,7 +18196,7 @@ read_die_and_siblings (const struct die_reader_specs *reader,
     {
       fprintf_unfiltered (gdb_stdlog,
 			  "Read die from %s@0x%x of %s:\n",
-			  get_section_name (reader->die_section),
+			  reader->die_section->get_name (),
 			  (unsigned) (info_ptr - reader->die_section->buffer),
 			  bfd_get_filename (reader->abfd));
       dump_die (die, dwarf_die_debug);
@@ -18293,7 +18293,7 @@ read_full_die (const struct die_reader_specs *reader,
     {
       fprintf_unfiltered (gdb_stdlog,
 			  "Read die from %s@0x%x of %s:\n",
-			  get_section_name (reader->die_section),
+			  reader->die_section->get_name (),
 			  (unsigned) (info_ptr - reader->die_section->buffer),
 			  bfd_get_filename (reader->abfd));
       dump_die (*diep, dwarf_die_debug);
@@ -18364,7 +18364,7 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 			 sect_offset sect_off)
 {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
-  bfd *abfd = get_section_bfd_owner (section);
+  bfd *abfd = section->get_bfd_owner ();
   const gdb_byte *abbrev_ptr;
   struct abbrev_info *cur_abbrev;
   unsigned int abbrev_number, bytes_read, abbrev_name;
@@ -18373,7 +18373,7 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   abbrev_table_up abbrev_table (new struct abbrev_table (sect_off));
 
-  dwarf2_read_section (objfile, section);
+  section->read (objfile);
   abbrev_ptr = section->buffer + to_underlying (sect_off);
   abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read);
   abbrev_ptr += bytes_read;
@@ -19756,7 +19756,7 @@ read_indirect_string_at_offset_from (struct objfile *objfile,
 				     const char *form_name,
 				     const char *sect_name)
 {
-  dwarf2_read_section (objfile, sect);
+  sect->read (objfile);
   if (sect->buffer == NULL)
     error (_("%s used without %s section [in module %s]"),
 	   form_name, sect_name, bfd_get_filename (abfd));
@@ -19803,7 +19803,7 @@ static const char *
 read_indirect_string_from_dwz (struct objfile *objfile, struct dwz_file *dwz,
 			       LONGEST str_offset)
 {
-  dwarf2_read_section (objfile, &dwz->str);
+  dwz->str.read (objfile);
 
   if (dwz->str.buffer == NULL)
     error (_("DW_FORM_GNU_strp_alt used without .debug_str "
@@ -19864,7 +19864,7 @@ read_addr_index_1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
   const gdb_byte *info_ptr;
   ULONGEST addr_base_or_zero = addr_base.has_value () ? *addr_base : 0;
 
-  dwarf2_read_section (objfile, &dwarf2_per_objfile->addr);
+  dwarf2_per_objfile->addr.read (objfile);
   if (dwarf2_per_objfile->addr.buffer == NULL)
     error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"),
 	   objfile_name (objfile));
@@ -19967,17 +19967,17 @@ read_str_index (struct dwarf2_cu *cu,
   ULONGEST str_offset;
   static const char form_name[] = "DW_FORM_GNU_str_index or DW_FORM_strx";
 
-  dwarf2_read_section (objfile, str_section);
-  dwarf2_read_section (objfile, str_offsets_section);
+  str_section->read (objfile);
+  str_offsets_section->read (objfile);
   if (str_section->buffer == NULL)
     error (_("%s used without %s section"
 	     " in CU at offset %s [in module %s]"),
-	   form_name, get_section_name (str_section),
+	   form_name, str_section->get_name (),
            sect_offset_str (cu->header.sect_off), objf_name);
   if (str_offsets_section->buffer == NULL)
     error (_("%s used without %s section"
 	     " in CU at offset %s [in module %s]"),
-	   form_name, get_section_name (str_section),
+	   form_name, str_section->get_name (),
            sect_offset_str (cu->header.sect_off), objf_name);
   info_ptr = (str_offsets_section->buffer
 	      + str_offsets_base
@@ -20468,7 +20468,7 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
     = cu->per_cu->dwarf2_per_objfile;
 
   section = get_debug_line_section (cu);
-  dwarf2_read_section (dwarf2_per_objfile->objfile, section);
+  section->read (dwarf2_per_objfile->objfile);
   if (section->buffer == NULL)
     {
       if (cu->dwo_unit && cu->per_cu->is_debug_types)
@@ -20480,7 +20480,7 @@ dwarf_decode_line_header (sect_offset sect_off, struct dwarf2_cu *cu)
 
   /* We can't do this until we know the section is non-empty.
      Only then do we know we have such a section.  */
-  abfd = get_section_bfd_owner (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.  */
@@ -24478,7 +24478,7 @@ skip_form_bytes (bfd *abfd, const gdb_byte *bytes, const gdb_byte *buffer_end,
     default:
       {
 	complaint (_("invalid form 0x%x in `%s'"),
-		   form, get_section_name (section));
+		   form, section->get_name ());
 	return NULL;
       }
     }
@@ -24821,10 +24821,10 @@ dwarf_decode_macro_bytes (struct dwarf2_cu *cu,
 	      {
 		struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
 
-		dwarf2_read_section (objfile, &dwz->macro);
+		dwz->macro.read (objfile);
 
 		include_section = &dwz->macro;
-		include_bfd = get_section_bfd_owner (include_section);
+		include_bfd = include_section->get_bfd_owner ();
 		include_mac_end = dwz->macro.buffer + dwz->macro.size;
 		is_dwz = 1;
 	      }
@@ -24927,13 +24927,13 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset,
 	}
     }
 
-  dwarf2_read_section (objfile, section);
+  section->read (objfile);
   if (section->buffer == NULL)
     {
       complaint (_("missing %s section"), section_name);
       return;
     }
-  abfd = get_section_bfd_owner (section);
+  abfd = section->get_bfd_owner ();
 
   /* First pass: Find the name of the base filename.
      This filename is needed in order to process all macros whose definition
@@ -25193,7 +25193,7 @@ fill_in_loclist_baton (struct dwarf2_cu *cu,
     = cu->per_cu->dwarf2_per_objfile;
   struct dwarf2_section_info *section = cu_debug_loc_section (cu);
 
-  dwarf2_read_section (dwarf2_per_objfile->objfile, section);
+  section->read (dwarf2_per_objfile->objfile);
 
   baton->per_cu = cu->per_cu;
   gdb_assert (baton->per_cu);
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 29/38] Add some methods to dwarf2_per_cu_data
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (35 preceding siblings ...)
  2020-01-23  1:12 ` [PATCH 03/38] Change section functions to be methods of dwarf2_section_info Tom Tromey
@ 2020-01-23  1:21 ` Tom Tromey
  2020-01-23  2:34 ` [PATCH 37/38] Simplify "want_partial_unit" handling Tom Tromey
  2020-02-08 17:38 ` [PATCH 00/38] Start reorganization of DWARF code Simon Marchi
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  1:21 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes a few helper functions to be methods on
dwarf2_per_cu_data.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/loc.c (dwarf2_find_location_expression)
	(dwarf_evaluate_loc_desc::get_tls_address)
	(dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value)
	(rw_pieced_value, dwarf2_evaluate_loc_desc_full)
	(dwarf2_locexpr_baton_eval, dwarf2_evaluate_property)
	(dwarf2_compile_property_to_c)
	(dwarf2_loc_desc_get_symbol_read_needs)
	(dwarf2_compile_expr_to_ax, locexpr_describe_location)
	(locexpr_tracepoint_var_ref, locexpr_generate_c_location)
	(loclist_describe_location, loclist_tracepoint_var_ref)
	(loclist_generate_c_location): Update.
	* compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update.
	* dwarf2/loc.h (dwarf2_per_cu_objfile, dwarf2_per_cu_addr_size)
	(dwarf2_per_cu_ref_addr_size, dwarf2_per_cu_offset_size)
	(dwarf2_per_cu_text_offset, dwarf2_version): Don't declare.
	* dwarf2/read.c (dwarf2_per_cu_data::objfile)
	(dwarf2_per_cu_data::addr_size)
	(dwarf2_per_cu_data::ref_addr_size)
	(dwarf2_per_cu_data::text_offset)
	(dwarf2_per_cu_data::addr_type): Now methods.
	(per_cu_header_read_in): Make per_cu "const".
	(dwarf2_version): Remove.
	(dwarf2_per_cu_data::int_type): Now a method.
	(dwarf2_per_cu_data::_addr_sized_int_type): Likewise.
	(set_die_type, read_array_type, read_subrange_index_type)
	(read_tag_string_type, read_subrange_type): Update.
	* dwarf2/read.h (struct dwarf2_per_cu_data) <addr_size,
	offset_size, ref_addr_size, text_offset, addr_type, version,
	objfile, int_type, addr_sized_int_type>: Declare methods.

Change-Id: I07a42fa26e00795352389fa7a0cc1c12997d26f7
---
 gdb/ChangeLog               |  32 ++++++++++
 gdb/compile/compile-loc2c.c |   3 +-
 gdb/dwarf2/loc.c            |  73 +++++++++++------------
 gdb/dwarf2/loc.h            |  23 --------
 gdb/dwarf2/read.c           | 115 +++++++++++++-----------------------
 gdb/dwarf2/read.h           |  43 ++++++++++++++
 6 files changed, 155 insertions(+), 134 deletions(-)

diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
index 636c929b022..06a044de048 100644
--- a/gdb/compile/compile-loc2c.c
+++ b/gdb/compile/compile-loc2c.c
@@ -21,6 +21,7 @@
 #include "dwarf2.h"
 #include "dwarf2/expr.h"
 #include "dwarf2/loc.h"
+#include "dwarf2/read.h"
 #include "ui-file.h"
 #include "utils.h"
 #include "compile-internal.h"
@@ -718,7 +719,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream,
 	     index, not an address.  We don't support things like
 	     branching between the address and the TLS op.  */
 	  if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
-	    uoffset += dwarf2_per_cu_text_offset (per_cu);
+	    uoffset += per_cu->text_offset ();
 	  push (indent, stream, uoffset);
 	  break;
 
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index e337a02d473..ad13e8920ff 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -312,13 +312,13 @@ const gdb_byte *
 dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 				 size_t *locexpr_length, CORE_ADDR pc)
 {
-  struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu);
+  struct objfile *objfile = baton->per_cu->objfile ();
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu);
+  unsigned int addr_size = baton->per_cu->addr_size ();
   int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
   /* Adjust base_address for relocatable objects.  */
-  CORE_ADDR base_offset = dwarf2_per_cu_text_offset (baton->per_cu);
+  CORE_ADDR base_offset = baton->per_cu->text_offset ();
   CORE_ADDR base_address = baton->base_address + base_offset;
   const gdb_byte *loc_ptr, *buf_end;
 
@@ -336,7 +336,7 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 	kind = decode_debug_loc_dwo_addresses (baton->per_cu,
 					       loc_ptr, buf_end, &new_ptr,
 					       &low, &high, byte_order);
-      else if (dwarf2_version (baton->per_cu) < 5)
+      else if (baton->per_cu->version () < 5)
 	kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr,
 					   &low, &high,
 					   byte_order, addr_size,
@@ -382,7 +382,7 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 	  high += base_address;
 	}
 
-      if (dwarf2_version (baton->per_cu) < 5)
+      if (baton->per_cu->version () < 5)
 	{
 	  length = extract_unsigned_integer (loc_ptr, 2, byte_order);
 	  loc_ptr += 2;
@@ -643,7 +643,7 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context
      current thread's thread-local storage with offset OFFSET.  */
   CORE_ADDR get_tls_address (CORE_ADDR offset) override
   {
-    struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
+    struct objfile *objfile = per_cu->objfile ();
 
     return target_translate_tls_address (objfile, offset);
   }
@@ -730,12 +730,11 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context
 							(CORE_ADDR) 0);
 
     scoped_restore save_arch = make_scoped_restore (&this->gdbarch);
-    this->gdbarch
-      = get_objfile_arch (dwarf2_per_cu_objfile (per_cu));
+    this->gdbarch = get_objfile_arch (per_cu->objfile ());
     scoped_restore save_addr_size = make_scoped_restore (&this->addr_size);
-    this->addr_size = dwarf2_per_cu_addr_size (per_cu);
+    this->addr_size = per_cu->addr_size ();
     scoped_restore save_offset = make_scoped_restore (&this->offset);
-    this->offset = dwarf2_per_cu_text_offset (per_cu);
+    this->offset = per_cu->text_offset ();
 
     this->eval (data_src, size);
   }
@@ -1819,7 +1818,7 @@ rw_pieced_value (struct value *v, struct value *from)
 		break;
 	      }
 
-	    struct objfile *objfile = dwarf2_per_cu_objfile (c->per_cu);
+	    struct objfile *objfile = c->per_cu->objfile ();
 	    struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
 	    ULONGEST stack_value_size_bits
 	      = 8 * TYPE_LENGTH (value_type (p->v.value));
@@ -2176,7 +2175,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 			       LONGEST subobj_byte_offset)
 {
   struct value *retval;
-  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
+  struct objfile *objfile = per_cu->objfile ();
 
   if (subobj_type == NULL)
     {
@@ -2197,9 +2196,9 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
   scoped_value_mark free_values;
 
   ctx.gdbarch = get_objfile_arch (objfile);
-  ctx.addr_size = dwarf2_per_cu_addr_size (per_cu);
-  ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
-  ctx.offset = dwarf2_per_cu_text_offset (per_cu);
+  ctx.addr_size = per_cu->addr_size ();
+  ctx.ref_addr_size = per_cu->ref_addr_size ();
+  ctx.offset = per_cu->text_offset ();
 
   try
     {
@@ -2411,12 +2410,12 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
   ctx.per_cu = dlbaton->per_cu;
   ctx.obj_address = addr;
 
-  objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
+  objfile = dlbaton->per_cu->objfile ();
 
   ctx.gdbarch = get_objfile_arch (objfile);
-  ctx.addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
-  ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (dlbaton->per_cu);
-  ctx.offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
+  ctx.addr_size = dlbaton->per_cu->addr_size ();
+  ctx.ref_addr_size = dlbaton->per_cu->ref_addr_size ();
+  ctx.offset = dlbaton->per_cu->text_offset ();
 
   try
     {
@@ -2504,7 +2503,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
 		       CORE_ADDR on 64bit machine has 8 bytes but address
 		       size of an 32bit application is bytes.  */
 		    const int addr_size
-		      = (dwarf2_per_cu_addr_size (baton->locexpr.per_cu)
+		      = (baton->locexpr.per_cu->addr_size ()
 			 * TARGET_CHAR_BIT);
 		    const CORE_ADDR neg_mask
 		      = (~((CORE_ADDR) 0) <<  (addr_size - 1));
@@ -2610,7 +2609,7 @@ dwarf2_compile_property_to_c (string_file *stream,
 
   compile_dwarf_bounds_to_c (stream, result_name, prop, sym, pc,
 			     gdbarch, registers_used,
-			     dwarf2_per_cu_addr_size (per_cu),
+			     per_cu->addr_size (),
 			     data, data + size, per_cu);
 }
 
@@ -2732,7 +2731,7 @@ dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
 				       struct dwarf2_per_cu_data *per_cu)
 {
   int in_reg;
-  struct objfile *objfile = dwarf2_per_cu_objfile (per_cu);
+  struct objfile *objfile = per_cu->objfile ();
 
   scoped_value_mark free_values;
 
@@ -2741,9 +2740,9 @@ dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
   ctx.needs = SYMBOL_NEEDS_NONE;
   ctx.per_cu = per_cu;
   ctx.gdbarch = get_objfile_arch (objfile);
-  ctx.addr_size = dwarf2_per_cu_addr_size (per_cu);
-  ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
-  ctx.offset = dwarf2_per_cu_text_offset (per_cu);
+  ctx.addr_size = per_cu->addr_size ();
+  ctx.ref_addr_size = per_cu->ref_addr_size ();
+  ctx.offset = per_cu->text_offset ();
 
   ctx.eval (data, size);
 
@@ -2984,7 +2983,7 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc,
 	     index, not an address.  We don't support things like
 	     branching between the address and the TLS op.  */
 	  if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address)
-	    uoffset += dwarf2_per_cu_text_offset (per_cu);
+	    uoffset += per_cu->text_offset ();
 	  ax_const_l (expr, uoffset);
 	  break;
 
@@ -4292,9 +4291,9 @@ locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr,
 {
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
-  struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
-  int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
+  struct objfile *objfile = dlbaton->per_cu->objfile ();
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
+  int offset_size = dlbaton->per_cu->offset_size ();
 
   locexpr_describe_location_1 (symbol, addr, stream,
 			       dlbaton->data, dlbaton->size,
@@ -4311,7 +4310,7 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
 {
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
 
   if (dlbaton->size == 0)
     value->optimized_out = 1;
@@ -4330,7 +4329,7 @@ locexpr_generate_c_location (struct symbol *sym, string_file *stream,
 {
   struct dwarf2_locexpr_baton *dlbaton
     = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
 
   if (dlbaton->size == 0)
     error (_("symbol \"%s\" is optimized out"), sym->natural_name ());
@@ -4429,14 +4428,14 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
   struct dwarf2_loclist_baton *dlbaton
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
   const gdb_byte *loc_ptr, *buf_end;
-  struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu);
+  struct objfile *objfile = dlbaton->per_cu->objfile ();
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
-  int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
+  int offset_size = dlbaton->per_cu->offset_size ();
   int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
   /* Adjust base_address for relocatable objects.  */
-  CORE_ADDR base_offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
+  CORE_ADDR base_offset = dlbaton->per_cu->text_offset ();
   CORE_ADDR base_address = dlbaton->base_address + base_offset;
   int done = 0;
 
@@ -4520,7 +4519,7 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax,
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
   const gdb_byte *data;
   size_t size;
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
 
   data = dwarf2_find_location_expression (dlbaton, &size, ax->scope);
   if (size == 0)
@@ -4540,7 +4539,7 @@ loclist_generate_c_location (struct symbol *sym, string_file *stream,
 {
   struct dwarf2_loclist_baton *dlbaton
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym);
-  unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu);
+  unsigned int addr_size = dlbaton->per_cu->addr_size ();
   const gdb_byte *data;
   size_t size;
 
diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h
index a49a9903b11..2cc7e066a33 100644
--- a/gdb/dwarf2/loc.h
+++ b/gdb/dwarf2/loc.h
@@ -35,29 +35,6 @@ struct axs_value;
 /* `set debug entry-values' setting.  */
 extern unsigned int entry_values_debug;
 
-/* Return the OBJFILE associated with the compilation unit CU.  If CU
-   came from a separate debuginfo file, then the master objfile is
-   returned.  */
-struct objfile *dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *cu);
-
-/* Return the address size given in the compilation unit header for CU.  */
-int dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *cu);
-
-/* Return the DW_FORM_ref_addr size given in the compilation unit header for
-   CU.  */
-int dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *cu);
-
-/* Return the offset size given in the compilation unit header for CU.  */
-int dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *cu);
-
-/* Return the text offset of the CU.  The returned offset comes from
-   this CU's objfile.  If this objfile came from a separate debuginfo
-   file, then the offset may be different from the corresponding
-   offset in the parent objfile.  */
-CORE_ADDR dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *cu);
-
-short dwarf2_version (struct dwarf2_per_cu_data *per_cu);
-
 /* Find a particular location expression from a location list.  */
 const gdb_byte *dwarf2_find_location_expression
   (struct dwarf2_loclist_baton *baton,
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 6a9a1a95012..f0d39ddb7f8 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1644,13 +1644,6 @@ static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu,
 
 static void process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile);
 
-static struct type *dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data *per_cu);
-static struct type *dwarf2_per_cu_addr_sized_int_type
-	(struct dwarf2_per_cu_data *per_cu, bool unsigned_p);
-static struct type *dwarf2_per_cu_int_type
-	(struct dwarf2_per_cu_data *per_cu, int size_in_bytes,
-	 bool unsigned_p);
-
 /* Class, the destructor of which frees all allocated queue entries.  This
    will only have work to do if an error was thrown while processing the
    dwarf.  If no error was thrown then the queue entries should have all
@@ -13214,7 +13207,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
       newobj->static_link
 	= XOBNEW (&objfile->objfile_obstack, struct dynamic_prop);
       attr_to_dynamic_prop (attr, die, cu, newobj->static_link,
-			    dwarf2_per_cu_addr_type (cu->per_cu));
+			    cu->per_cu->addr_type ());
     }
 
   cu->list_in_scope = cu->get_builder ()->get_local_symbols ();
@@ -16051,8 +16044,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
   if (attr != NULL)
     {
       int stride_ok;
-      struct type *prop_type
-	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+      struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
 
       byte_stride_prop
 	= (struct dynamic_prop *) alloca (sizeof (struct dynamic_prop));
@@ -16854,13 +16846,13 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
 	  /* Pass 0 as the default as we know this attribute is constant
 	     and the default value will not be returned.  */
 	  LONGEST sz = dwarf2_get_attr_constant_value (len, 0);
-	  prop_type = dwarf2_per_cu_int_type (cu->per_cu, sz, true);
+	  prop_type = cu->per_cu->int_type (sz, true);
 	}
       else
 	{
 	  /* If the size is not specified then we assume it is the size of
 	     an address on this target.  */
-	  prop_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, true);
+	  prop_type = cu->per_cu->addr_sized_int_type (true);
 	}
 
       /* Convert the attribute into a dynamic property.  */
@@ -17462,14 +17454,12 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
   return 1;
 }
 
-/* Find an integer type SIZE_IN_BYTES bytes in size and return it.
-   UNSIGNED_P controls if the integer is unsigned or not.  */
+/* See read.h.  */
 
-static struct type *
-dwarf2_per_cu_int_type (struct dwarf2_per_cu_data *per_cu,
-			int size_in_bytes, bool unsigned_p)
+struct type *
+dwarf2_per_cu_data::int_type (int size_in_bytes, bool unsigned_p) const
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct type *int_type;
 
   /* Helper macro to examine the various builtin types.  */
@@ -17491,16 +17481,13 @@ dwarf2_per_cu_int_type (struct dwarf2_per_cu_data *per_cu,
   gdb_assert_not_reached ("unable to find suitable integer type");
 }
 
-/* Find an integer type the same size as the address size given in the
-   compilation unit header for PER_CU.  UNSIGNED_P controls if the integer
-   is unsigned or not.  */
+/* See read.h.  */
 
-static struct type *
-dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data *per_cu,
-				   bool unsigned_p)
+struct type *
+dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p) const
 {
-  int addr_size = dwarf2_per_cu_addr_size (per_cu);
-  return dwarf2_per_cu_int_type (per_cu, addr_size, unsigned_p);
+  int addr_size = this->addr_size ();
+  return int_type (addr_size, unsigned_p);
 }
 
 /* Read the DW_AT_type attribute for a sub-range.  If this attribute is not
@@ -17525,7 +17512,7 @@ read_subrange_index_type (struct die_info *die, struct dwarf2_cu *cu)
      FIXME: muller/2010-05-28: Possible references to object for low bound,
      high bound or count are not yet handled by this code.  */
   if (TYPE_CODE (index_type) == TYPE_CODE_VOID)
-    index_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+    index_type = cu->per_cu->addr_sized_int_type (false);
 
   return index_type;
 }
@@ -17655,8 +17642,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   attribute *attr_byte_stride = dwarf2_attr (die, DW_AT_byte_stride, cu);
   if (attr_byte_stride != nullptr)
     {
-      struct type *prop_type
-	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+      struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
       attr_to_dynamic_prop (attr_byte_stride, die, cu, &byte_stride_prop,
 			    prop_type);
     }
@@ -17676,8 +17662,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 	}
       else
 	{
-	  struct type *prop_type
-	    = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+	  struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
 	  attr_to_dynamic_prop (attr_bit_stride, die, cu, &bit_stride_prop,
 				prop_type);
 	}
@@ -24566,14 +24551,12 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym,
     }
 }
 
-/* Return the OBJFILE associated with the compilation unit CU.  If CU
-   came from a separate debuginfo file, then the master objfile is
-   returned.  */
+/* See read.h.  */
 
 struct objfile *
-dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::objfile () const
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
 
   /* Return the master objfile, so that we can report and look up the
      correct file containing this variable.  */
@@ -24589,7 +24572,7 @@ dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu)
 
 static const struct comp_unit_head *
 per_cu_header_read_in (struct comp_unit_head *cu_headerp,
-		       struct dwarf2_per_cu_data *per_cu)
+		       const struct dwarf2_per_cu_data *per_cu)
 {
   const gdb_byte *info_ptr;
 
@@ -24605,41 +24588,41 @@ per_cu_header_read_in (struct comp_unit_head *cu_headerp,
   return cu_headerp;
 }
 
-/* Return the address size given in the compilation unit header for CU.  */
+/* See read.h.  */
 
 int
-dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::addr_size () const
 {
   struct comp_unit_head cu_header_local;
   const struct comp_unit_head *cu_headerp;
 
-  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
+  cu_headerp = per_cu_header_read_in (&cu_header_local, this);
 
   return cu_headerp->addr_size;
 }
 
-/* Return the offset size given in the compilation unit header for CU.  */
+/* See read.h.  */
 
 int
-dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::offset_size () const
 {
   struct comp_unit_head cu_header_local;
   const struct comp_unit_head *cu_headerp;
 
-  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
+  cu_headerp = per_cu_header_read_in (&cu_header_local, this);
 
   return cu_headerp->offset_size;
 }
 
-/* See its dwarf2loc.h declaration.  */
+/* See read.h.  */
 
 int
-dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::ref_addr_size () const
 {
   struct comp_unit_head cu_header_local;
   const struct comp_unit_head *cu_headerp;
 
-  cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu);
+  cu_headerp = per_cu_header_read_in (&cu_header_local, this);
 
   if (cu_headerp->version == 2)
     return cu_headerp->addr_size;
@@ -24647,45 +24630,33 @@ dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu)
     return cu_headerp->offset_size;
 }
 
-/* Return the text offset of the CU.  The returned offset comes from
-   this CU's objfile.  If this objfile came from a separate debuginfo
-   file, then the offset may be different from the corresponding
-   offset in the parent objfile.  */
+/* See read.h.  */
 
 CORE_ADDR
-dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu)
+dwarf2_per_cu_data::text_offset () const
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
 
   return objfile->section_offsets[SECT_OFF_TEXT (objfile)];
 }
 
-/* Return a type that is a generic pointer type, the size of which matches
-   the address size given in the compilation unit header for PER_CU.  */
-static struct type *
-dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data *per_cu)
+/* See read.h.  */
+
+struct type *
+dwarf2_per_cu_data::addr_type () const
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+  struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct type *void_type = objfile_type (objfile)->builtin_void;
   struct type *addr_type = lookup_pointer_type (void_type);
-  int addr_size = dwarf2_per_cu_addr_size (per_cu);
+  int addr_size = this->addr_size ();
 
   if (TYPE_LENGTH (addr_type) == addr_size)
     return addr_type;
 
-  addr_type
-    = dwarf2_per_cu_addr_sized_int_type (per_cu, TYPE_UNSIGNED (addr_type));
+  addr_type = addr_sized_int_type (TYPE_UNSIGNED (addr_type));
   return addr_type;
 }
 
-/* Return DWARF version number of PER_CU.  */
-
-short
-dwarf2_version (struct dwarf2_per_cu_data *per_cu)
-{
-  return per_cu->dwarf_version;
-}
-
 /* Locate the .debug_info compilation unit from CU's objfile which contains
    the DIE at OFFSET.  Raises an error on failure.  */
 
@@ -24944,8 +24915,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_allocated, cu);
   if (attr != NULL && attr->form_is_block ())
     {
-      struct type *prop_type
-	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+      struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
       if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
         add_dyn_prop (DYN_PROP_ALLOCATED, prop, type);
     }
@@ -24960,8 +24930,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_associated, cu);
   if (attr != NULL && attr->form_is_block ())
     {
-      struct type *prop_type
-	= dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false);
+      struct type *prop_type = cu->per_cu->addr_sized_int_type (false);
       if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type))
         add_dyn_prop (DYN_PROP_ASSOCIATED, prop, type);
     }
@@ -24975,7 +24944,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
   /* Read DW_AT_data_location and set in type.  */
   attr = dwarf2_attr (die, DW_AT_data_location, cu);
   if (attr_to_dynamic_prop (attr, die, cu, &prop,
-			    dwarf2_per_cu_addr_type (cu->per_cu)))
+			    cu->per_cu->addr_type ()))
     add_dyn_prop (DYN_PROP_DATA_LOCATION, prop, type);
 
   if (dwarf2_per_objfile->die_type_hash == NULL)
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 646a53fadd2..4aa9c4b9029 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -373,6 +373,49 @@ struct dwarf2_per_cu_data
     delete imported_symtabs;
     imported_symtabs = nullptr;
   }
+
+  /* Return the OBJFILE associated with this compilation unit.  If
+     this compilation unit came from a separate debuginfo file, then
+     the master objfile is returned.  */
+  struct objfile *objfile () const;
+
+  /* Return the address size given in the compilation unit header for
+     this CU.  */
+  int addr_size () const;
+
+  /* Return the offset size given in the compilation unit header for
+     this CU.  */
+  int offset_size () const;
+
+  /* Return the DW_FORM_ref_addr size given in the compilation unit
+     header for this CU.  */
+  int ref_addr_size () const;
+
+  /* Return the text offset of the CU.  The returned offset comes from
+     this CU's objfile.  If this objfile came from a separate
+     debuginfo file, then the offset may be different from the
+     corresponding offset in the parent objfile.  */
+  CORE_ADDR text_offset () const;
+
+  /* Return a type that is a generic pointer type, the size of which
+     matches the address size given in the compilation unit header for
+     this CU.  */
+  struct type *addr_type () const;
+
+  /* Find an integer type SIZE_IN_BYTES bytes in size and return it.
+     UNSIGNED_P controls if the integer is unsigned or not.  */
+  struct type *int_type (int size_in_bytes, bool unsigned_p) const;
+
+  /* Find an integer type the same size as the address size given in
+     the compilation unit header for this CU.  UNSIGNED_P controls if
+     the integer is unsigned or not.  */
+  struct type *addr_sized_int_type (bool unsigned_p) const;
+
+  /* Return DWARF version number of this CU.  */
+  short version () const
+  {
+    return dwarf_version;
+  }
 };
 
 /* Entry in the signatured_types hash table.  */
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 37/38] Simplify "want_partial_unit" handling
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (36 preceding siblings ...)
  2020-01-23  1:21 ` [PATCH 29/38] Add some methods to dwarf2_per_cu_data Tom Tromey
@ 2020-01-23  2:34 ` Tom Tromey
  2020-02-08 17:38 ` [PATCH 00/38] Start reorganization of DWARF code Simon Marchi
  38 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-23  2:34 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes the "want_partial_unit" parameters to have type bool, and
also removes the parameter from process_psymtab_comp_unit_reader.
This latter change seemed like an improvement, because it avoids a
pointless function call in the case where we are not planning to read
a partial unit.

2020-01-22  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (process_psymtab_comp_unit_reader): Remove
	"want_partial_unit" parameter.
	(process_psymtab_comp_unit): Change want_partial_unit to bool.
	Inline check for DW_TAG_partial_unit.
	(dwarf2_build_psymtabs_hard, scan_partial_symbols): Update.

Change-Id: I99e647f0c4faa3346e90a6e7bacc82af57eccff1
---
 gdb/ChangeLog     |  8 ++++++++
 gdb/dwarf2/read.c | 14 +++++---------
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 09840400cec..d1a78afd8cf 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7248,7 +7248,6 @@ static void
 process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 				  const gdb_byte *info_ptr,
 				  struct die_info *comp_unit_die,
-				  int want_partial_unit,
 				  enum language pretend_language)
 {
   struct dwarf2_cu *cu = reader->cu;
@@ -7261,9 +7260,6 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
   enum pc_bounds_kind cu_bounds_kind;
   const char *filename;
 
-  if (comp_unit_die->tag == DW_TAG_partial_unit && !want_partial_unit)
-    return;
-
   gdb_assert (! per_cu->is_debug_types);
 
   prepare_one_comp_unit (cu, comp_unit_die, pretend_language);
@@ -7377,7 +7373,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 
 static void
 process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
-			   int want_partial_unit,
+			   bool want_partial_unit,
 			   enum language pretend_language)
 {
   /* If this compilation unit was already read in, free the
@@ -7397,10 +7393,10 @@ process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
   else if (this_cu->is_debug_types)
     build_type_psymtabs_reader (&reader, reader.info_ptr,
 				reader.comp_unit_die);
-  else
+  else if (want_partial_unit
+	   || reader.comp_unit_die->tag != DW_TAG_partial_unit)
     process_psymtab_comp_unit_reader (&reader, reader.info_ptr,
 				      reader.comp_unit_die,
-				      want_partial_unit,
 				      pretend_language);
 
   /* Age out any secondary CUs.  */
@@ -7760,7 +7756,7 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
 			   addrmap_create_mutable (&temp_obstack));
 
   for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
-    process_psymtab_comp_unit (per_cu, 0, language_minimal);
+    process_psymtab_comp_unit (per_cu, false, language_minimal);
 
   /* This has to wait until we read the CUs, we need the list of DWOs.  */
   process_skeletonless_type_units (dwarf2_per_objfile);
@@ -7977,7 +7973,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
 
 		/* Go read the partial unit, if needed.  */
 		if (per_cu->v.psymtab == NULL)
-		  process_psymtab_comp_unit (per_cu, 1, cu->language);
+		  process_psymtab_comp_unit (per_cu, true, cu->language);
 
 		cu->per_cu->imported_symtabs_push (per_cu);
 	      }
-- 
2.17.2

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 30/38] Unify read_initial_length implementations
  2020-01-23  0:57 ` [PATCH 30/38] Unify read_initial_length implementations Tom Tromey
@ 2020-01-27 13:31   ` Christian Biesinger via gdb-patches
  2020-01-28  0:54     ` Tom Tromey
  0 siblings, 1 reply; 48+ messages in thread
From: Christian Biesinger via gdb-patches @ 2020-01-27 13:31 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Thu, Jan 23, 2020, 02:00 Tom Tromey <tom@tromey.com> wrote:

> There are two implementations of read_initial_length in gdb.  This
> merges them and moves the resulting function to leb.c.
>
> 2020-01-22  Tom Tromey  <tom@tromey.com>
>
>         * dwarf2/read.c (read_initial_length): Move to leb.c.
>         * dwarf2/leb.h (read_initial_length): Declare.
>         * dwarf2/leb.c (read_initial_length): Move from read.c.  Add
>         handle_nonstd parameter.
>         * dwarf2/frame.c (read_initial_length): Remove.
>         (decode_frame_entry_1): Update.
>
> Change-Id: I34d37bad0f8a584bfa781432cba25e05e1bd5750
> ---
>  gdb/ChangeLog      |  9 +++++++
>  gdb/dwarf2/frame.c | 20 +--------------
>  gdb/dwarf2/leb.c   | 27 +++++++++++++++++++
>  gdb/dwarf2/leb.h   | 41 +++++++++++++++++++++++++++++
>  gdb/dwarf2/read.c  | 64 ----------------------------------------------
>  5 files changed, 78 insertions(+), 83 deletions(-)
>
> diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c
> index 7f57c28be2c..2d928670c6b 100644
> --- a/gdb/dwarf2/frame.c
> +++ b/gdb/dwarf2/frame.c
> @@ -1475,24 +1475,6 @@ const struct objfile_key<dwarf2_fde_table,
>                          gdb::noop_deleter<dwarf2_fde_table>>
>    dwarf2_frame_objfile_data;
>
> -
> -static ULONGEST
> -read_initial_length (bfd *abfd, const gdb_byte *buf,
> -                    unsigned int *bytes_read_ptr)
> -{
> -  ULONGEST result;
> -
> -  result = bfd_get_32 (abfd, buf);
> -  if (result == 0xffffffff)
> -    {
> -      result = bfd_get_64 (abfd, buf + 4);
> -      *bytes_read_ptr = 12;
> -    }
> -  else
> -    *bytes_read_ptr = 4;
> -
> -  return result;
> -}
>
>
>  /* Pointer encoding helper functions.  */
> @@ -1744,7 +1726,7 @@ decode_frame_entry_1 (struct comp_unit *unit, const
> gdb_byte *start,
>    uint64_t uleb128;
>
>    buf = start;
> -  length = read_initial_length (unit->abfd, buf, &bytes_read);
> +  length = read_initial_length (unit->abfd, buf, &bytes_read, false);
>    buf += bytes_read;
>    end = buf + (size_t) length;
>
> diff --git a/gdb/dwarf2/leb.c b/gdb/dwarf2/leb.c
> index d26b48b381c..ef7314ed2b3 100644
> --- a/gdb/dwarf2/leb.c
> +++ b/gdb/dwarf2/leb.c
> @@ -83,3 +83,30 @@ read_signed_leb128 (bfd *abfd, const gdb_byte *buf,
>    *bytes_read_ptr = num_read;
>    return result;
>  }
> +
> +/* See leb.h.  */
> +
> +LONGEST
> +read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int
> *bytes_read,
> +                    bool handle_nonstd)
> +{
> +  LONGEST length = bfd_get_32 (abfd, buf);
> +
> +  if (length == 0xffffffff)
> +    {
> +      length = bfd_get_64 (abfd, buf + 4);
> +      *bytes_read = 12;
> +    }
> +  else if (handle_nonstd && length == 0)
> +    {
> +      /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX.  */
> +      length = bfd_get_64 (abfd, buf);
> +      *bytes_read = 8;
> +    }
> +  else
> +    {
> +      *bytes_read = 4;
> +    }
> +
> +  return length;
> +}
> diff --git a/gdb/dwarf2/leb.h b/gdb/dwarf2/leb.h
> index b17ab881ba2..29fdffebfec 100644
> --- a/gdb/dwarf2/leb.h
> +++ b/gdb/dwarf2/leb.h
> @@ -89,4 +89,45 @@ extern LONGEST read_signed_leb128 (bfd *, const
> gdb_byte *, unsigned int *);
>
>  extern ULONGEST read_unsigned_leb128 (bfd *, const gdb_byte *, unsigned
> int *);
>
> +/* Read the initial length from a section.  The (draft) DWARF 3


Maybe it's time to remove the "draft" part about dwarf 3? :)

+   specification allows the initial length to take up either 4 bytes
> +   or 12 bytes.  If the first 4 bytes are 0xffffffff, then the next 8
> +   bytes describe the length and all offsets will be 8 bytes in length
> +   instead of 4.
> +
> +   An older, non-standard 64-bit format is also handled by this
> +   function.  The older format in question stores the initial length
> +   as an 8-byte quantity without an escape value.  Lengths greater
> +   than 2^32 aren't very common which means that the initial 4 bytes
> +   is almost always zero.  Since a length value of zero doesn't make
> +   sense for the 32-bit format, this initial zero can be considered to
> +   be an escape value which indicates the presence of the older 64-bit
> +   format.  As written, the code can't detect (old format) lengths
> +   greater than 4GB.  If it becomes necessary to handle lengths
> +   somewhat larger than 4GB, we could allow other small values (such
> +   as the non-sensical values of 1, 2, and 3) to also be used as
> +   escape values indicating the presence of the old format.
> +
> +   The value returned via bytes_read should be used to increment the
> +   relevant pointer after calling read_initial_length().
> +
> +   [ Note:  read_initial_length() and read_offset() are based on the
> +     document entitled "DWARF Debugging Information Format", revision
> +     3, draft 8, dated November 19, 2001.  This document was obtained
> +     from:
> +
> +       http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
> +
> +     This document is only a draft and is subject to change.  (So beware.)
> +


I wonder if this could be updated to a final version.

+     Details regarding the older, non-standard 64-bit format were
> +     determined empirically by examining 64-bit ELF files produced by
> +     the SGI toolchain on an IRIX 6.5 machine.
> +
> +     - Kevin, July 16, 2002
> +   ] */
> +extern LONGEST read_initial_length (bfd *abfd, const gdb_byte *buf,
> +                                   unsigned int *bytes_read,
> +                                   bool handle_nonstd = true);
> +
>  #endif /* GDB_DWARF2_LEB_H */
> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index f0d39ddb7f8..65e39b22b4f 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -1282,8 +1282,6 @@ static CORE_ADDR read_addr_index (struct dwarf2_cu
> *cu, unsigned int addr_index)
>  static CORE_ADDR read_address (bfd *, const gdb_byte *ptr, struct
> dwarf2_cu *,
>                                unsigned int *);
>
> -static LONGEST read_initial_length (bfd *, const gdb_byte *, unsigned int
> *);
> -
>  static LONGEST read_checked_initial_length_and_offset
>    (bfd *, const gdb_byte *, const struct comp_unit_head *,
>     unsigned int *, unsigned int *);
> @@ -19061,68 +19059,6 @@ read_address (bfd *abfd, const gdb_byte *buf,
> struct dwarf2_cu *cu,
>    return retval;
>  }
>
> -/* Read the initial length from a section.  The (draft) DWARF 3
> -   specification allows the initial length to take up either 4 bytes
> -   or 12 bytes.  If the first 4 bytes are 0xffffffff, then the next 8
> -   bytes describe the length and all offsets will be 8 bytes in length
> -   instead of 4.
> -
> -   An older, non-standard 64-bit format is also handled by this
> -   function.  The older format in question stores the initial length
> -   as an 8-byte quantity without an escape value.  Lengths greater
> -   than 2^32 aren't very common which means that the initial 4 bytes
> -   is almost always zero.  Since a length value of zero doesn't make
> -   sense for the 32-bit format, this initial zero can be considered to
> -   be an escape value which indicates the presence of the older 64-bit
> -   format.  As written, the code can't detect (old format) lengths
> -   greater than 4GB.  If it becomes necessary to handle lengths
> -   somewhat larger than 4GB, we could allow other small values (such
> -   as the non-sensical values of 1, 2, and 3) to also be used as
> -   escape values indicating the presence of the old format.
> -
> -   The value returned via bytes_read should be used to increment the
> -   relevant pointer after calling read_initial_length().
> -
> -   [ Note:  read_initial_length() and read_offset() are based on the
> -     document entitled "DWARF Debugging Information Format", revision
> -     3, draft 8, dated November 19, 2001.  This document was obtained
> -     from:
> -
> -       http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf
> -
> -     This document is only a draft and is subject to change.  (So beware.)
> -
> -     Details regarding the older, non-standard 64-bit format were
> -     determined empirically by examining 64-bit ELF files produced by
> -     the SGI toolchain on an IRIX 6.5 machine.
> -
> -     - Kevin, July 16, 2002
> -   ] */
> -
> -static LONGEST
> -read_initial_length (bfd *abfd, const gdb_byte *buf, unsigned int
> *bytes_read)
> -{
> -  LONGEST length = bfd_get_32 (abfd, buf);
> -
> -  if (length == 0xffffffff)
> -    {
> -      length = bfd_get_64 (abfd, buf + 4);
> -      *bytes_read = 12;
> -    }
> -  else if (length == 0)
> -    {
> -      /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX.  */
> -      length = bfd_get_64 (abfd, buf);
> -      *bytes_read = 8;
> -    }
> -  else
> -    {
> -      *bytes_read = 4;
> -    }
> -
> -  return length;
> -}
> -
>  /* 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
> --
> 2.17.2
>
>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 25/38] Change file_full_name and file_file_name methods
  2020-01-23  0:57 ` [PATCH 25/38] Change file_full_name and file_file_name methods Tom Tromey
@ 2020-01-27 13:31   ` Christian Biesinger via gdb-patches
  0 siblings, 0 replies; 48+ messages in thread
From: Christian Biesinger via gdb-patches @ 2020-01-27 13:31 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Thu, Jan 23, 2020, 01:59 Tom Tromey <tom@tromey.com> wrote:

> This changes file_full_name and file_file_name methods to be methods
> on line_header.  This seems more clear to me.
>
> 2020-01-22  Tom Tromey  <tom@tromey.com>
>
>         * dwarf2/read.c (struct line_header) <file_full_name,
>         file_file_name>: Declare methods.
>         (dw2_get_file_names_reader): Update.
>         (file_file_name): Now a method.
>         (file_full_name): Likewise.
>         (macro_start_file): Update.
>
> Change-Id: I50d3e91665a9637c732e1e8d8e4263764c766d9c
> ---
>  gdb/ChangeLog     |  9 +++++++++
>  gdb/dwarf2/read.c | 47 ++++++++++++++++++++++++-----------------------
>  2 files changed, 33 insertions(+), 23 deletions(-)
>
> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index c230778980e..153faac8238 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -1074,6 +1074,18 @@ struct line_header
>       header.  These point into dwarf2_per_objfile->line_buffer.  */
>    const gdb_byte *statement_program_start {}, *statement_program_end {};
>
> +  /* Return the full name of file number I in this object's file name
>

I -> FILE, I think.

+     table.  Use COMP_DIR as the name of the current directory of the
> +     compilation.  The result is allocated using xmalloc; the caller
> +     is responsible for freeing it.  */
> +  char *file_full_name (int file, const char *comp_dir);
> +
> +  /* Return file name relative to the compilation directory of file
> +     number I in this object's file name table.  The result is
>

Same

+     allocated using xmalloc; the caller is responsible for freeing
> +     it.  */
> +  char *file_file_name (int file);
> +
>   private:
>    /* The include_directories table.  Note these are observing
>       pointers.  The memory is owned by debug_line_buffer.  */
> @@ -1860,9 +1872,6 @@ struct file_and_directory
>  static file_and_directory find_file_and_directory (struct die_info *die,
>                                                    struct dwarf2_cu *cu);
>
> -static char *file_full_name (int file, struct line_header *lh,
> -                            const char *comp_dir);
> -
>  /* Expected enum dwarf_unit_type for read_comp_unit_head.  */
>  enum class rcuh_kind { COMPILE, TYPE };
>
> @@ -3401,7 +3410,7 @@ dw2_get_file_names_reader (const struct
> die_reader_specs *reader,
>    if (offset != 0)
>      qfn->file_names[0] = xstrdup (fnd.name);
>    for (int i = 0; i < lh->file_names_size (); ++i)
> -    qfn->file_names[i + offset] = file_full_name (i + 1, lh.get (),
> fnd.comp_dir);
> +    qfn->file_names[i + offset] = lh->file_full_name (i + 1,
> fnd.comp_dir);
>    qfn->real_names = NULL;
>
>    lh_cu->v.quick->file_names = qfn;
> @@ -23788,22 +23797,18 @@ dwarf_alloc_die (struct dwarf2_cu *cu, int
> num_attrs)
>
>  /* Macro support.  */
>
> -/* Return file name relative to the compilation directory of file number
> I in
> -   *LH's file name table.  The result is allocated using xmalloc; the
> caller is
> -   responsible for freeing it.  */
> -
> -static char *
> -file_file_name (int file, struct line_header *lh)
> +char *
> +line_header::file_file_name (int file)
>  {
>    /* Is the file number a valid index into the line header's file name
>       table?  Remember that file numbers start with one, not zero.  */
> -  if (lh->is_valid_file_index (file))
> +  if (is_valid_file_index (file))
>      {
> -      const file_entry *fe = lh->file_name_at (file);
> +      const file_entry *fe = file_name_at (file);
>
>        if (!IS_ABSOLUTE_PATH (fe->name))
>         {
> -         const char *dir = fe->include_dir (lh);
> +         const char *dir = fe->include_dir (this);
>           if (dir != NULL)
>             return concat (dir, SLASH_STRING, fe->name, (char *) NULL);
>         }
> @@ -23826,18 +23831,14 @@ file_file_name (int file, struct line_header *lh)
>      }
>  }
>
> -/* Return the full name of file number I in *LH's file name table.
> -   Use COMP_DIR as the name of the current directory of the
> -   compilation.  The result is allocated using xmalloc; the caller is
> -   responsible for freeing it.  */
> -static char *
> -file_full_name (int file, struct line_header *lh, const char *comp_dir)
> +char *
> +line_header::file_full_name (int file, const char *comp_dir)
>  {
>    /* Is the file number a valid index into the line header's file name
>       table?  Remember that file numbers start with one, not zero.  */
> -  if (lh->is_valid_file_index (file))
> +  if (is_valid_file_index (file))
>      {
> -      char *relative = file_file_name (file, lh);
> +      char *relative = file_file_name (file);
>
>        if (IS_ABSOLUTE_PATH (relative) || comp_dir == NULL)
>         return relative;
> @@ -23845,7 +23846,7 @@ file_full_name (int file, struct line_header *lh,
> const char *comp_dir)
>                        relative, (char *) NULL);
>      }
>    else
> -    return file_file_name (file, lh);
> +    return file_file_name (file);
>  }
>
>
> @@ -23856,7 +23857,7 @@ macro_start_file (struct dwarf2_cu *cu,
>                    struct line_header *lh)
>  {
>    /* File name relative to the compilation directory of this source
> file.  */
> -  char *file_name = file_file_name (file, lh);
> +  char *file_name = lh->file_file_name (file);
>
>    if (! current_file)
>      {
> --
> 2.17.2
>
>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 11/38] Move DWARF code to dwarf2/ subdirectory
  2020-01-23  0:57 ` [PATCH 11/38] Move DWARF code to dwarf2/ subdirectory Tom Tromey
@ 2020-01-27 13:41   ` Christian Biesinger via gdb-patches
  2020-01-28  3:12     ` Tom Tromey
  0 siblings, 1 reply; 48+ messages in thread
From: Christian Biesinger via gdb-patches @ 2020-01-27 13:41 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Thu, Jan 23, 2020, 01:59 Tom Tromey <tom@tromey.com> wrote:

> This moves all the remaining DWARF code to the new dwarf2
> subdirectory.  This is just a simple renaming, with updates to
> includes as needed.
>

Two questions:
- Why dwarf2 instead of something more generic, since this supports dwarf
2-5?
- thoughts on renaming the files to .cc?


> gdb/ChangeLog
> 2020-01-22  Tom Tromey  <tom@tromey.com>
>
>         * dwarf2/expr.c: Rename from dwarf2expr.c.
>         * dwarf2/expr.h: Rename from dwarf2expr.h.
>         * dwarf2/frame-tailcall.c: Rename from dwarf2-frame-tailcall.c.
>         * dwarf2/frame-tailcall.h: Rename from dwarf2-frame-tailcall.h.
>         * dwarf2/frame.c: Rename from dwarf2-frame.c.
>         * dwarf2/frame.h: Rename from dwarf2-frame.h.
>         * dwarf2/index-cache.c: Rename from dwarf-index-cache.c.
>         * dwarf2/index-cache.h: Rename from dwarf-index-cache.h.
>         * dwarf2/index-common.c: Rename from dwarf-index-common.c.
>         * dwarf2/index-common.h: Rename from dwarf-index-common.h.
>         * dwarf2/index-write.c: Rename from dwarf-index-write.c.
>         * dwarf2/index-write.h: Rename from dwarf-index-write.h.
>         * dwarf2/loc.c: Rename from dwarf2loc.c.
>         * dwarf2/loc.h: Rename from dwarf2loc.h.
>         * dwarf2/read.c: Rename from dwarf2read.c.
>         * dwarf2/read.h: Rename from dwarf2read.h.
>         * dwarf2/abbrev.c, aarch64-tdep.c, alpha-tdep.c,
>         amd64-darwin-tdep.c, arc-tdep.c, arm-tdep.c, bfin-tdep.c,
>         compile/compile-c-symbols.c, compile/compile-cplus-symbols.c,
>         compile/compile-loc2c.c, cris-tdep.c, csky-tdep.c, findvar.c,
>         gdbtypes.c, guile/scm-type.c, h8300-tdep.c, hppa-bsd-tdep.c,
>         hppa-linux-tdep.c, i386-darwin-tdep.c, i386-linux-tdep.c,
>         i386-tdep.c, iq2000-tdep.c, m32c-tdep.c, m68hc11-tdep.c,
>         m68k-tdep.c, microblaze-tdep.c, mips-tdep.c, mn10300-tdep.c,
>         msp430-tdep.c, nds32-tdep.c, nios2-tdep.c, or1k-tdep.c,
>         riscv-tdep.c, rl78-tdep.c, rs6000-tdep.c, rx-tdep.c, s12z-tdep.c,
>         s390-tdep.c, score-tdep.c, sh-tdep.c, sparc-linux-tdep.c,
>         sparc-tdep.c, sparc64-linux-tdep.c, sparc64-tdep.c, tic6x-tdep.c,
>         tilegx-tdep.c, v850-tdep.c, xstormy16-tdep.c, xtensa-tdep.c:
>         Update.
>         * Makefile.in (COMMON_SFILES): Update.
>         (HFILES_NO_SRCDIR): Update.
>
> Change-Id: Ied9ce1436cd27ac4a4cffef10ec92e396f181928
> ---
>  gdb/ChangeLog                                 | 35 +++++++++++++++++++
>  gdb/Makefile.in                               | 30 ++++++++--------
>  gdb/aarch64-tdep.c                            |  2 +-
>  gdb/alpha-tdep.c                              |  2 +-
>  gdb/amd64-darwin-tdep.c                       |  2 +-
>  gdb/arc-tdep.c                                |  2 +-
>  gdb/arm-tdep.c                                |  2 +-
>  gdb/bfin-tdep.c                               |  2 +-
>  gdb/compile/compile-c-symbols.c               |  2 +-
>  gdb/compile/compile-cplus-symbols.c           |  2 +-
>  gdb/compile/compile-loc2c.c                   |  6 ++--
>  gdb/cris-tdep.c                               |  2 +-
>  gdb/csky-tdep.c                               |  2 +-
>  gdb/dwarf2/abbrev.c                           |  2 +-
>  gdb/{dwarf2expr.c => dwarf2/expr.c}           |  4 +--
>  gdb/{dwarf2expr.h => dwarf2/expr.h}           |  0
>  .../frame-tailcall.c}                         |  6 ++--
>  .../frame-tailcall.h}                         |  0
>  gdb/{dwarf2-frame.c => dwarf2/frame.c}        | 10 +++---
>  gdb/{dwarf2-frame.h => dwarf2/frame.h}        |  0
>  .../index-cache.c}                            |  6 ++--
>  .../index-cache.h}                            |  2 +-
>  .../index-common.c}                           |  2 +-
>  .../index-common.h}                           |  0
>  .../index-write.c}                            |  6 ++--
>  .../index-write.h}                            |  2 +-
>  gdb/{dwarf2loc.c => dwarf2/loc.c}             |  8 ++---
>  gdb/{dwarf2loc.h => dwarf2/loc.h}             |  2 +-
>  gdb/{dwarf2read.c => dwarf2/read.c}           | 10 +++---
>  gdb/{dwarf2read.h => dwarf2/read.h}           |  2 +-
>  gdb/findvar.c                                 |  2 +-
>  gdb/gdbtypes.c                                |  2 +-
>  gdb/guile/scm-type.c                          |  2 +-
>  gdb/h8300-tdep.c                              |  2 +-
>  gdb/hppa-bsd-tdep.c                           |  2 +-
>  gdb/hppa-linux-tdep.c                         |  2 +-
>  gdb/i386-darwin-tdep.c                        |  2 +-
>  gdb/i386-linux-tdep.c                         |  2 +-
>  gdb/i386-tdep.c                               |  2 +-
>  gdb/iq2000-tdep.c                             |  2 +-
>  gdb/m32c-tdep.c                               |  4 +--
>  gdb/m68hc11-tdep.c                            |  2 +-
>  gdb/m68k-tdep.c                               |  2 +-
>  gdb/microblaze-tdep.c                         |  2 +-
>  gdb/mips-tdep.c                               |  2 +-
>  gdb/mn10300-tdep.c                            |  2 +-
>  gdb/msp430-tdep.c                             |  2 +-
>  gdb/nds32-tdep.c                              |  2 +-
>  gdb/nios2-tdep.c                              |  2 +-
>  gdb/or1k-tdep.c                               |  2 +-
>  gdb/riscv-tdep.c                              |  2 +-
>  gdb/rl78-tdep.c                               |  2 +-
>  gdb/rs6000-tdep.c                             |  2 +-
>  gdb/rx-tdep.c                                 |  2 +-
>  gdb/s12z-tdep.c                               |  2 +-
>  gdb/s390-tdep.c                               |  2 +-
>  gdb/score-tdep.c                              |  2 +-
>  gdb/sh-tdep.c                                 |  2 +-
>  gdb/sparc-linux-tdep.c                        |  2 +-
>  gdb/sparc-tdep.c                              |  2 +-
>  gdb/sparc64-linux-tdep.c                      |  2 +-
>  gdb/sparc64-tdep.c                            |  2 +-
>  gdb/tic6x-tdep.c                              |  2 +-
>  gdb/tilegx-tdep.c                             |  2 +-
>  gdb/v850-tdep.c                               |  2 +-
>  gdb/xstormy16-tdep.c                          |  2 +-
>  gdb/xtensa-tdep.c                             |  4 +--
>  67 files changed, 133 insertions(+), 98 deletions(-)
>  rename gdb/{dwarf2expr.c => dwarf2/expr.c} (99%)
>  rename gdb/{dwarf2expr.h => dwarf2/expr.h} (100%)
>  rename gdb/{dwarf2-frame-tailcall.c => dwarf2/frame-tailcall.c} (99%)
>  rename gdb/{dwarf2-frame-tailcall.h => dwarf2/frame-tailcall.h} (100%)
>  rename gdb/{dwarf2-frame.c => dwarf2/frame.c} (99%)
>  rename gdb/{dwarf2-frame.h => dwarf2/frame.h} (100%)
>  rename gdb/{dwarf-index-cache.c => dwarf2/index-cache.c} (99%)
>  rename gdb/{dwarf-index-cache.h => dwarf2/index-cache.h} (98%)
>  rename gdb/{dwarf-index-common.c => dwarf2/index-common.c} (97%)
>  rename gdb/{dwarf-index-common.h => dwarf2/index-common.h} (100%)
>  rename gdb/{dwarf-index-write.c => dwarf2/index-write.c} (99%)
>  rename gdb/{dwarf-index-write.h => dwarf2/index-write.h} (98%)
>  rename gdb/{dwarf2loc.c => dwarf2/loc.c} (99%)
>  rename gdb/{dwarf2loc.h => dwarf2/loc.h} (99%)
>  rename gdb/{dwarf2read.c => dwarf2/read.c} (99%)
>  rename gdb/{dwarf2read.h => dwarf2/read.h} (99%)
>
> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> index e652e4f971a..37c5d250ff0 100644
> --- a/gdb/Makefile.in
> +++ b/gdb/Makefile.in
> @@ -994,17 +994,17 @@ COMMON_SFILES = \
>         disasm.c \
>         disasm-selftests.c \
>         dummy-frame.c \
> -       dwarf-index-cache.c \
> -       dwarf-index-common.c \
> -       dwarf-index-write.c \
> -       dwarf2-frame.c \
> -       dwarf2-frame-tailcall.c \
> -       dwarf2expr.c \
> -       dwarf2loc.c \
> -       dwarf2read.c \
>         dwarf2/abbrev.c \
>         dwarf2/attribute.c \
> +       dwarf2/expr.c \
> +       dwarf2/frame-tailcall.c \
> +       dwarf2/frame.c \
> +       dwarf2/index-cache.c \
> +       dwarf2/index-common.c \
> +       dwarf2/index-write.c \
>         dwarf2/leb.c \
> +       dwarf2/loc.c \
> +       dwarf2/read.c \
>         dwarf2/section.c \
>         eval.c \
>         event-loop.c \
> @@ -1234,13 +1234,13 @@ HFILES_NO_SRCDIR = \
>         dictionary.h \
>         disasm.h \
>         dummy-frame.h \
> -       dwarf-index-cache.h \
> -       dwarf-index-common.h \
> -       dwarf2-frame.h \
> -       dwarf2-frame-tailcall.h \
> -       dwarf2expr.h \
> -       dwarf2loc.h \
> -       dwarf2read.h \
> +       dwarf2/frame-tailcall.h \
> +       dwarf2/frame.h \
> +       dwarf2/expr.h \
> +       dwarf2/index-cache.h \
> +       dwarf2/index-common.h \
> +       dwarf2/loc.h \
> +       dwarf2/read.h \
>         event-loop.h \
>         event-top.h \
>         exceptions.h \
> diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
> index 1631178f8c2..6d099fbf35d 100644
> --- a/gdb/aarch64-tdep.c
> +++ b/gdb/aarch64-tdep.c
> @@ -34,7 +34,7 @@
>  #include "trad-frame.h"
>  #include "objfiles.h"
>  #include "dwarf2.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "gdbtypes.h"
>  #include "prologue-value.h"
>  #include "target-descriptions.h"
> diff --git a/gdb/alpha-tdep.c b/gdb/alpha-tdep.c
> index 390f865edad..aabd202b1cc 100644
> --- a/gdb/alpha-tdep.c
> +++ b/gdb/alpha-tdep.c
> @@ -21,7 +21,7 @@
>  #include "frame.h"
>  #include "frame-unwind.h"
>  #include "frame-base.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "inferior.h"
>  #include "symtab.h"
>  #include "value.h"
> diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
> index 5e8f352ffc9..447e272f4ea 100644
> --- a/gdb/amd64-darwin-tdep.c
> +++ b/gdb/amd64-darwin-tdep.c
> @@ -36,7 +36,7 @@
>  #include "i386-darwin-tdep.h"
>  #include "solib.h"
>  #include "solib-darwin.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>
>  /* Offsets into the struct x86_thread_state64 where we'll find the saved
> regs.
>     From <mach/i386/thread_status.h> and amd64-tdep.h.  */
> diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
> index 13da0226f78..ac98f03efc1 100644
> --- a/gdb/arc-tdep.c
> +++ b/gdb/arc-tdep.c
> @@ -22,7 +22,7 @@
>  #include "defs.h"
>  #include "arch-utils.h"
>  #include "disasm.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
>  #include "gdbcore.h"
> diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
> index 0e72bcc651a..d4fed8977e7 100644
> --- a/gdb/arm-tdep.c
> +++ b/gdb/arm-tdep.c
> @@ -38,7 +38,7 @@
>  #include "frame-base.h"
>  #include "trad-frame.h"
>  #include "objfiles.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "gdbtypes.h"
>  #include "prologue-value.h"
>  #include "remote.h"
> diff --git a/gdb/bfin-tdep.c b/gdb/bfin-tdep.c
> index 23591d4a5f0..55fb6a61d6d 100644
> --- a/gdb/bfin-tdep.c
> +++ b/gdb/bfin-tdep.c
> @@ -31,7 +31,7 @@
>  #include "dis-asm.h"
>  #include "sim-regno.h"
>  #include "gdb/sim-bfin.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "symtab.h"
>  #include "elf-bfd.h"
>  #include "elf/bfin.h"
> diff --git a/gdb/compile/compile-c-symbols.c
> b/gdb/compile/compile-c-symbols.c
> index 7af85d62cd4..eb5af8e015f 100644
> --- a/gdb/compile/compile-c-symbols.c
> +++ b/gdb/compile/compile-c-symbols.c
> @@ -29,7 +29,7 @@
>  #include "value.h"
>  #include "exceptions.h"
>  #include "gdbtypes.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/loc.h"
>
>
>
> diff --git a/gdb/compile/compile-cplus-symbols.c
> b/gdb/compile/compile-cplus-symbols.c
> index 34cae4a6d8f..fee2651e47f 100644
> --- a/gdb/compile/compile-cplus-symbols.c
> +++ b/gdb/compile/compile-cplus-symbols.c
> @@ -30,7 +30,7 @@
>  #include "value.h"
>  #include "exceptions.h"
>  #include "gdbtypes.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/loc.h"
>  #include "cp-support.h"
>  #include "gdbcmd.h"
>  #include "compile-c.h"
> diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c
> index 0f911821115..636c929b022 100644
> --- a/gdb/compile/compile-loc2c.c
> +++ b/gdb/compile/compile-loc2c.c
> @@ -19,15 +19,15 @@
>
>  #include "defs.h"
>  #include "dwarf2.h"
> -#include "dwarf2expr.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/expr.h"
> +#include "dwarf2/loc.h"
>  #include "ui-file.h"
>  #include "utils.h"
>  #include "compile-internal.h"
>  #include "compile-c.h"
>  #include "compile.h"
>  #include "block.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "gdbsupport/gdb_vecs.h"
>  #include "value.h"
>  #include "gdbarch.h"
> diff --git a/gdb/cris-tdep.c b/gdb/cris-tdep.c
> index 6885d237f3a..cc45a7f8ebf 100644
> --- a/gdb/cris-tdep.c
> +++ b/gdb/cris-tdep.c
> @@ -25,7 +25,7 @@
>  #include "frame-unwind.h"
>  #include "frame-base.h"
>  #include "trad-frame.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "symtab.h"
>  #include "inferior.h"
>  #include "gdbtypes.h"
> diff --git a/gdb/csky-tdep.c b/gdb/csky-tdep.c
> index 583298ce74c..955238bb014 100644
> --- a/gdb/csky-tdep.c
> +++ b/gdb/csky-tdep.c
> @@ -49,7 +49,7 @@
>  #include "floatformat.h"
>  #include "remote.h"
>  #include "target-descriptions.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "user-regs.h"
>  #include "valprint.h"
>  #include "csky-tdep.h"
> diff --git a/gdb/dwarf2/abbrev.c b/gdb/dwarf2/abbrev.c
> index 6bd455f012b..544d5793add 100644
> --- a/gdb/dwarf2/abbrev.c
> +++ b/gdb/dwarf2/abbrev.c
> @@ -25,7 +25,7 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.
> */
>
>  #include "defs.h"
> -#include "dwarf2read.h"
> +#include "dwarf2/read.h"
>  #include "dwarf2/abbrev.h"
>  #include "dwarf2/leb.h"
>  #include "bfd.h"
> diff --git a/gdb/dwarf2expr.c b/gdb/dwarf2/expr.c
> similarity index 99%
> rename from gdb/dwarf2expr.c
> rename to gdb/dwarf2/expr.c
> index ad82cbec2f7..243f493084b 100644
> --- a/gdb/dwarf2expr.c
> +++ b/gdb/dwarf2/expr.c
> @@ -25,8 +25,8 @@
>  #include "value.h"
>  #include "gdbcore.h"
>  #include "dwarf2.h"
> -#include "dwarf2expr.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/expr.h"
> +#include "dwarf2/loc.h"
>  #include "gdbsupport/underlying.h"
>  #include "gdbarch.h"
>
> diff --git a/gdb/dwarf2expr.h b/gdb/dwarf2/expr.h
> similarity index 100%
> rename from gdb/dwarf2expr.h
> rename to gdb/dwarf2/expr.h
> diff --git a/gdb/dwarf2-frame-tailcall.c b/gdb/dwarf2/frame-tailcall.c
> similarity index 99%
> rename from gdb/dwarf2-frame-tailcall.c
> rename to gdb/dwarf2/frame-tailcall.c
> index fca1d3d0235..3dc300df60a 100644
> --- a/gdb/dwarf2-frame-tailcall.c
> +++ b/gdb/dwarf2/frame-tailcall.c
> @@ -19,15 +19,15 @@
>
>  #include "defs.h"
>  #include "frame.h"
> -#include "dwarf2-frame-tailcall.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/frame-tailcall.h"
> +#include "dwarf2/loc.h"
>  #include "frame-unwind.h"
>  #include "block.h"
>  #include "hashtab.h"
>  #include "gdbtypes.h"
>  #include "regcache.h"
>  #include "value.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "gdbarch.h"
>
>  /* Contains struct tailcall_cache indexed by next_bottom_frame.  */
> diff --git a/gdb/dwarf2-frame-tailcall.h b/gdb/dwarf2/frame-tailcall.h
> similarity index 100%
> rename from gdb/dwarf2-frame-tailcall.h
> rename to gdb/dwarf2/frame-tailcall.h
> diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2/frame.c
> similarity index 99%
> rename from gdb/dwarf2-frame.c
> rename to gdb/dwarf2/frame.c
> index 9daa66b0a29..7f57c28be2c 100644
> --- a/gdb/dwarf2-frame.c
> +++ b/gdb/dwarf2/frame.c
> @@ -20,7 +20,7 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.
> */
>
>  #include "defs.h"
> -#include "dwarf2expr.h"
> +#include "dwarf2/expr.h"
>  #include "dwarf2.h"
>  #include "dwarf2/leb.h"
>  #include "frame.h"
> @@ -35,11 +35,11 @@
>  #include "record.h"
>
>  #include "complaints.h"
> -#include "dwarf2-frame.h"
> -#include "dwarf2read.h"
> +#include "dwarf2/frame.h"
> +#include "dwarf2/read.h"
>  #include "ax.h"
> -#include "dwarf2loc.h"
> -#include "dwarf2-frame-tailcall.h"
> +#include "dwarf2/loc.h"
> +#include "dwarf2/frame-tailcall.h"
>  #include "gdbsupport/gdb_binary_search.h"
>  #if GDB_SELF_TEST
>  #include "gdbsupport/selftest.h"
> diff --git a/gdb/dwarf2-frame.h b/gdb/dwarf2/frame.h
> similarity index 100%
> rename from gdb/dwarf2-frame.h
> rename to gdb/dwarf2/frame.h
> diff --git a/gdb/dwarf-index-cache.c b/gdb/dwarf2/index-cache.c
> similarity index 99%
> rename from gdb/dwarf-index-cache.c
> rename to gdb/dwarf2/index-cache.c
> index 977fcc1b20c..7b4d9975905 100644
> --- a/gdb/dwarf-index-cache.c
> +++ b/gdb/dwarf2/index-cache.c
> @@ -18,15 +18,15 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.
> */
>
>  #include "defs.h"
> -#include "dwarf-index-cache.h"
> +#include "dwarf2/index-cache.h"
>
>  #include "build-id.h"
>  #include "cli/cli-cmds.h"
>  #include "command.h"
>  #include "gdbsupport/scoped_mmap.h"
>  #include "gdbsupport/pathstuff.h"
> -#include "dwarf-index-write.h"
> -#include "dwarf2read.h"
> +#include "dwarf2/index-write.h"
> +#include "dwarf2/read.h"
>  #include "objfiles.h"
>  #include "gdbsupport/selftest.h"
>  #include <string>
> diff --git a/gdb/dwarf-index-cache.h b/gdb/dwarf2/index-cache.h
> similarity index 98%
> rename from gdb/dwarf-index-cache.h
> rename to gdb/dwarf2/index-cache.h
> index bc1b30aa45f..07e93fa853c 100644
> --- a/gdb/dwarf-index-cache.h
> +++ b/gdb/dwarf2/index-cache.h
> @@ -20,7 +20,7 @@
>  #ifndef DWARF_INDEX_CACHE_H
>  #define DWARF_INDEX_CACHE_H
>
> -#include "dwarf-index-common.h"
> +#include "dwarf2/index-common.h"
>  #include "gdbsupport/array-view.h"
>  #include "symfile.h"
>
> diff --git a/gdb/dwarf-index-common.c b/gdb/dwarf2/index-common.c
> similarity index 97%
> rename from gdb/dwarf-index-common.c
> rename to gdb/dwarf2/index-common.c
> index 0baf869e41e..13c6f0f8ab9 100644
> --- a/gdb/dwarf-index-common.c
> +++ b/gdb/dwarf2/index-common.c
> @@ -18,7 +18,7 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.
> */
>
>  #include "defs.h"
> -#include "dwarf-index-common.h"
> +#include "dwarf2/index-common.h"
>
>  /* See dwarf-index-common.h.  */
>
> diff --git a/gdb/dwarf-index-common.h b/gdb/dwarf2/index-common.h
> similarity index 100%
> rename from gdb/dwarf-index-common.h
> rename to gdb/dwarf2/index-common.h
> diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf2/index-write.c
> similarity index 99%
> rename from gdb/dwarf-index-write.c
> rename to gdb/dwarf2/index-write.c
> index c43a4817b97..6744e1a44db 100644
> --- a/gdb/dwarf-index-write.c
> +++ b/gdb/dwarf2/index-write.c
> @@ -19,7 +19,7 @@
>
>  #include "defs.h"
>
> -#include "dwarf-index-write.h"
> +#include "dwarf2/index-write.h"
>
>  #include "addrmap.h"
>  #include "cli/cli-decode.h"
> @@ -29,9 +29,9 @@
>  #include "gdbsupport/pathstuff.h"
>  #include "gdbsupport/scoped_fd.h"
>  #include "complaints.h"
> -#include "dwarf-index-common.h"
> +#include "dwarf2/index-common.h"
>  #include "dwarf2.h"
> -#include "dwarf2read.h"
> +#include "dwarf2/read.h"
>  #include "gdb/gdb-index.h"
>  #include "gdbcmd.h"
>  #include "objfiles.h"
> diff --git a/gdb/dwarf-index-write.h b/gdb/dwarf2/index-write.h
> similarity index 98%
> rename from gdb/dwarf-index-write.h
> rename to gdb/dwarf2/index-write.h
> index d78ff2ac073..5ba17251a9f 100644
> --- a/gdb/dwarf-index-write.h
> +++ b/gdb/dwarf2/index-write.h
> @@ -21,7 +21,7 @@
>  #define DWARF_INDEX_WRITE_H
>
>  #include "symfile.h"
> -#include "dwarf2read.h"
> +#include "dwarf2/read.h"
>
>  /* Create index files for OBJFILE in the directory DIR.
>
> diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2/loc.c
> similarity index 99%
> rename from gdb/dwarf2loc.c
> rename to gdb/dwarf2/loc.c
> index 9cfc852c9e1..03333602820 100644
> --- a/gdb/dwarf2loc.c
> +++ b/gdb/dwarf2/loc.c
> @@ -34,10 +34,10 @@
>  #include "gdbcmd.h"
>  #include "complaints.h"
>  #include "dwarf2.h"
> -#include "dwarf2expr.h"
> -#include "dwarf2loc.h"
> -#include "dwarf2read.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/expr.h"
> +#include "dwarf2/loc.h"
> +#include "dwarf2/read.h"
> +#include "dwarf2/frame.h"
>  #include "dwarf2/leb.h"
>  #include "compile/compile.h"
>  #include "gdbsupport/selftest.h"
> diff --git a/gdb/dwarf2loc.h b/gdb/dwarf2/loc.h
> similarity index 99%
> rename from gdb/dwarf2loc.h
> rename to gdb/dwarf2/loc.h
> index d0bc23b37d8..a49a9903b11 100644
> --- a/gdb/dwarf2loc.h
> +++ b/gdb/dwarf2/loc.h
> @@ -20,7 +20,7 @@
>  #if !defined (DWARF2LOC_H)
>  #define DWARF2LOC_H
>
> -#include "dwarf2expr.h"
> +#include "dwarf2/expr.h"
>
>  struct symbol_computed_ops;
>  struct objfile;
> diff --git a/gdb/dwarf2read.c b/gdb/dwarf2/read.c
> similarity index 99%
> rename from gdb/dwarf2read.c
> rename to gdb/dwarf2/read.c
> index 99b0551cd5a..c4879865532 100644
> --- a/gdb/dwarf2read.c
> +++ b/gdb/dwarf2/read.c
> @@ -29,11 +29,11 @@
>     E.g., load_partial_dies, read_partial_die.  */
>
>  #include "defs.h"
> -#include "dwarf2read.h"
> +#include "dwarf2/read.h"
>  #include "dwarf2/abbrev.h"
>  #include "dwarf2/attribute.h"
> -#include "dwarf-index-cache.h"
> -#include "dwarf-index-common.h"
> +#include "dwarf2/index-cache.h"
> +#include "dwarf2/index-common.h"
>  #include "dwarf2/leb.h"
>  #include "bfd.h"
>  #include "elf-bfd.h"
> @@ -48,8 +48,8 @@
>  #include "macrotab.h"
>  #include "language.h"
>  #include "complaints.h"
> -#include "dwarf2expr.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/expr.h"
> +#include "dwarf2/loc.h"
>  #include "cp-support.h"
>  #include "hashtab.h"
>  #include "command.h"
> diff --git a/gdb/dwarf2read.h b/gdb/dwarf2/read.h
> similarity index 99%
> rename from gdb/dwarf2read.h
> rename to gdb/dwarf2/read.h
> index a2228200257..9752abc5e4c 100644
> --- a/gdb/dwarf2read.h
> +++ b/gdb/dwarf2/read.h
> @@ -21,7 +21,7 @@
>  #define DWARF2READ_H
>
>  #include <unordered_map>
> -#include "dwarf-index-cache.h"
> +#include "dwarf2/index-cache.h"
>  #include "dwarf2/section.h"
>  #include "filename-seen-cache.h"
>  #include "gdb_obstack.h"
> diff --git a/gdb/findvar.c b/gdb/findvar.c
> index 5cf1cd4137b..a836c63dc5d 100644
> --- a/gdb/findvar.c
> +++ b/gdb/findvar.c
> @@ -31,7 +31,7 @@
>  #include "block.h"
>  #include "objfiles.h"
>  #include "language.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/loc.h"
>  #include "gdbsupport/selftest.h"
>
>  /* Basic byte-swapping routines.  All 'extract' functions return a
> diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
> index 1d5bfd4bc20..85758930491 100644
> --- a/gdb/gdbtypes.c
> +++ b/gdb/gdbtypes.c
> @@ -36,7 +36,7 @@
>  #include "hashtab.h"
>  #include "cp-support.h"
>  #include "bcache.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/loc.h"
>  #include "gdbcore.h"
>  #include "floatformat.h"
>
> diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
> index 52817ea4ede..bf2f751ce4d 100644
> --- a/gdb/guile/scm-type.c
> +++ b/gdb/guile/scm-type.c
> @@ -27,7 +27,7 @@
>  #include "objfiles.h"
>  #include "language.h"
>  #include "bcache.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/loc.h"
>  #include "typeprint.h"
>  #include "guile-internal.h"
>
> diff --git a/gdb/h8300-tdep.c b/gdb/h8300-tdep.c
> index 5e8ba94b72f..79c74001bc8 100644
> --- a/gdb/h8300-tdep.c
> +++ b/gdb/h8300-tdep.c
> @@ -29,7 +29,7 @@
>  #include "gdbcore.h"
>  #include "objfiles.h"
>  #include "dis-asm.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
>
> diff --git a/gdb/hppa-bsd-tdep.c b/gdb/hppa-bsd-tdep.c
> index 34dec20298f..2a00a27dbbd 100644
> --- a/gdb/hppa-bsd-tdep.c
> +++ b/gdb/hppa-bsd-tdep.c
> @@ -26,7 +26,7 @@
>
>  #include "hppa-tdep.h"
>  #include "hppa-bsd-tdep.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "solib-svr4.h"
>
>  static CORE_ADDR
> diff --git a/gdb/hppa-linux-tdep.c b/gdb/hppa-linux-tdep.c
> index 51c84d8e4f0..6a38d7200be 100644
> --- a/gdb/hppa-linux-tdep.c
> +++ b/gdb/hppa-linux-tdep.c
> @@ -26,7 +26,7 @@
>  #include "glibc-tdep.h"
>  #include "frame-unwind.h"
>  #include "trad-frame.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "value.h"
>  #include "regset.h"
>  #include "regcache.h"
> diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
> index a1c226ba66f..a796a8544f0 100644
> --- a/gdb/i386-darwin-tdep.c
> +++ b/gdb/i386-darwin-tdep.c
> @@ -34,7 +34,7 @@
>  #include "i386-darwin-tdep.h"
>  #include "solib.h"
>  #include "solib-darwin.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include <algorithm>
>
>  /* Offsets into the struct i386_thread_state where we'll find the saved
> regs.
> diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
> index 6f702b59e7f..f4a5f0a7616 100644
> --- a/gdb/i386-linux-tdep.c
> +++ b/gdb/i386-linux-tdep.c
> @@ -26,7 +26,7 @@
>  #include "inferior.h"
>  #include "osabi.h"
>  #include "reggroups.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "i386-tdep.h"
>  #include "i386-linux-tdep.h"
>  #include "linux-tdep.h"
> diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
> index f120438081d..f71444f6528 100644
> --- a/gdb/i386-tdep.c
> +++ b/gdb/i386-tdep.c
> @@ -22,7 +22,7 @@
>  #include "arch-utils.h"
>  #include "command.h"
>  #include "dummy-frame.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
> diff --git a/gdb/iq2000-tdep.c b/gdb/iq2000-tdep.c
> index 4b3419ead7b..7864d810d75 100644
> --- a/gdb/iq2000-tdep.c
> +++ b/gdb/iq2000-tdep.c
> @@ -24,7 +24,7 @@
>  #include "frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "gdbtypes.h"
>  #include "value.h"
>  #include "dis-asm.h"
> diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c
> index 31f4d24cac5..585fa337745 100644
> --- a/gdb/m32c-tdep.c
> +++ b/gdb/m32c-tdep.c
> @@ -27,8 +27,8 @@
>  #include "arch-utils.h"
>  #include "frame.h"
>  #include "frame-unwind.h"
> -#include "dwarf2-frame.h"
> -#include "dwarf2expr.h"
> +#include "dwarf2/frame.h"
> +#include "dwarf2/expr.h"
>  #include "symtab.h"
>  #include "gdbcore.h"
>  #include "value.h"
> diff --git a/gdb/m68hc11-tdep.c b/gdb/m68hc11-tdep.c
> index 4e63c2f2fa0..fb3b18ac718 100644
> --- a/gdb/m68hc11-tdep.c
> +++ b/gdb/m68hc11-tdep.c
> @@ -24,7 +24,7 @@
>  #include "frame.h"
>  #include "frame-unwind.h"
>  #include "frame-base.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "trad-frame.h"
>  #include "symtab.h"
>  #include "gdbtypes.h"
> diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
> index ec754a62af9..5ed5087da1f 100644
> --- a/gdb/m68k-tdep.c
> +++ b/gdb/m68k-tdep.c
> @@ -18,7 +18,7 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.
> */
>
>  #include "defs.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
> diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
> index a05088c36a1..5c804133040 100644
> --- a/gdb/microblaze-tdep.c
> +++ b/gdb/microblaze-tdep.c
> @@ -31,7 +31,7 @@
>  #include "target.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "osabi.h"
>  #include "target-descriptions.h"
>  #include "opcodes/microblaze-opcm.h"
> diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
> index 90ec3707c5d..2599f825e83 100644
> --- a/gdb/mips-tdep.c
> +++ b/gdb/mips-tdep.c
> @@ -51,7 +51,7 @@
>  #include "infcall.h"
>  #include "remote.h"
>  #include "target-descriptions.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "user-regs.h"
>  #include "valprint.h"
>  #include "ax.h"
> diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
> index d779ad1dd0d..8e487241e70 100644
> --- a/gdb/mn10300-tdep.c
> +++ b/gdb/mn10300-tdep.c
> @@ -28,7 +28,7 @@
>  #include "frame-unwind.h"
>  #include "frame-base.h"
>  #include "symtab.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "osabi.h"
>  #include "infcall.h"
>  #include "prologue-value.h"
> diff --git a/gdb/msp430-tdep.c b/gdb/msp430-tdep.c
> index 0893274686e..88597660b53 100644
> --- a/gdb/msp430-tdep.c
> +++ b/gdb/msp430-tdep.c
> @@ -32,7 +32,7 @@
>  #include "frame-base.h"
>  #include "value.h"
>  #include "gdbcore.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "reggroups.h"
>
>  #include "elf/msp430.h"
> diff --git a/gdb/nds32-tdep.c b/gdb/nds32-tdep.c
> index 5238fe54a71..220ad1e968d 100644
> --- a/gdb/nds32-tdep.c
> +++ b/gdb/nds32-tdep.c
> @@ -34,7 +34,7 @@
>  #include "dis-asm.h"
>  #include "user-regs.h"
>  #include "elf-bfd.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "remote.h"
>  #include "target-descriptions.h"
>
> diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
> index cb669da2480..02cdaea738e 100644
> --- a/gdb/nios2-tdep.c
> +++ b/gdb/nios2-tdep.c
> @@ -24,7 +24,7 @@
>  #include "frame-unwind.h"
>  #include "frame-base.h"
>  #include "trad-frame.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "symtab.h"
>  #include "inferior.h"
>  #include "gdbtypes.h"
> diff --git a/gdb/or1k-tdep.c b/gdb/or1k-tdep.c
> index 772ecff3349..61901a7689e 100644
> --- a/gdb/or1k-tdep.c
> +++ b/gdb/or1k-tdep.c
> @@ -35,7 +35,7 @@
>  #include "arch-utils.h"
>  #include "frame-unwind.h"
>  #include "frame-base.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "trad-frame.h"
>  #include "regset.h"
>  #include "remote.h"
> diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
> index d585b0be5ab..a14ef4db083 100644
> --- a/gdb/riscv-tdep.c
> +++ b/gdb/riscv-tdep.c
> @@ -47,7 +47,7 @@
>  #include "floatformat.h"
>  #include "remote.h"
>  #include "target-descriptions.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "user-regs.h"
>  #include "valprint.h"
>  #include "gdbsupport/common-defs.h"
> diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c
> index 3705efdbe89..aca7649fe06 100644
> --- a/gdb/rl78-tdep.c
> +++ b/gdb/rl78-tdep.c
> @@ -32,7 +32,7 @@
>  #include "frame-base.h"
>  #include "value.h"
>  #include "gdbcore.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "reggroups.h"
>
>  #include "elf/rl78.h"
> diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
> index ccffc39508a..919bebc71b2 100644
> --- a/gdb/rs6000-tdep.c
> +++ b/gdb/rs6000-tdep.c
> @@ -37,7 +37,7 @@
>  #include "sim-regno.h"
>  #include "gdb/sim-ppc.h"
>  #include "reggroups.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "target-descriptions.h"
>  #include "user-regs.h"
>  #include "record-full.h"
> diff --git a/gdb/rx-tdep.c b/gdb/rx-tdep.c
> index 766eaa06ed3..c14ce20282c 100644
> --- a/gdb/rx-tdep.c
> +++ b/gdb/rx-tdep.c
> @@ -32,7 +32,7 @@
>  #include "frame-base.h"
>  #include "value.h"
>  #include "gdbcore.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "remote.h"
>  #include "target-descriptions.h"
>
> diff --git a/gdb/s12z-tdep.c b/gdb/s12z-tdep.c
> index 922268d1ef2..4d2febadc9b 100644
> --- a/gdb/s12z-tdep.c
> +++ b/gdb/s12z-tdep.c
> @@ -21,7 +21,7 @@
>  #include "defs.h"
>
>  #include "arch-utils.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "gdbsupport/errors.h"
>  #include "frame-unwind.h"
>  #include "gdbcore.h"
> diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
> index e01505549e6..5f3cb7e81e7 100644
> --- a/gdb/s390-tdep.c
> +++ b/gdb/s390-tdep.c
> @@ -21,7 +21,7 @@
>
>  #include "arch-utils.h"
>  #include "ax-gdb.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "elf/s390.h"
>  #include "elf-bfd.h"
>  #include "frame-base.h"
> diff --git a/gdb/score-tdep.c b/gdb/score-tdep.c
> index 14eeee9eb8c..c5c183628ab 100644
> --- a/gdb/score-tdep.c
> +++ b/gdb/score-tdep.c
> @@ -34,7 +34,7 @@
>  #include "frame-unwind.h"
>  #include "frame-base.h"
>  #include "trad-frame.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "score-tdep.h"
>
>  #define G_FLD(_i,_ms,_ls) \
> diff --git a/gdb/sh-tdep.c b/gdb/sh-tdep.c
> index b69313d050f..9e831fb42e0 100644
> --- a/gdb/sh-tdep.c
> +++ b/gdb/sh-tdep.c
> @@ -24,7 +24,7 @@
>  #include "frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "symtab.h"
>  #include "gdbtypes.h"
>  #include "gdbcmd.h"
> diff --git a/gdb/sparc-linux-tdep.c b/gdb/sparc-linux-tdep.c
> index 1c4adb83674..247fde21657 100644
> --- a/gdb/sparc-linux-tdep.c
> +++ b/gdb/sparc-linux-tdep.c
> @@ -18,7 +18,7 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.
> */
>
>  #include "defs.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "frame.h"
>  #include "frame-unwind.h"
>  #include "gdbtypes.h"
> diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c
> index e048f872c2a..a0c41722440 100644
> --- a/gdb/sparc-tdep.c
> +++ b/gdb/sparc-tdep.c
> @@ -21,7 +21,7 @@
>  #include "arch-utils.h"
>  #include "dis-asm.h"
>  #include "dwarf2.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
> diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
> index de6c0479009..a7f439fbb04 100644
> --- a/gdb/sparc64-linux-tdep.c
> +++ b/gdb/sparc64-linux-tdep.c
> @@ -20,7 +20,7 @@
>  #include "defs.h"
>  #include "frame.h"
>  #include "frame-unwind.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "regset.h"
>  #include "regcache.h"
>  #include "gdbarch.h"
> diff --git a/gdb/sparc64-tdep.c b/gdb/sparc64-tdep.c
> index a11da6ab2e8..ac915d468fd 100644
> --- a/gdb/sparc64-tdep.c
> +++ b/gdb/sparc64-tdep.c
> @@ -19,7 +19,7 @@
>
>  #include "defs.h"
>  #include "arch-utils.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
> diff --git a/gdb/tic6x-tdep.c b/gdb/tic6x-tdep.c
> index a05675c570c..50031c100a5 100644
> --- a/gdb/tic6x-tdep.c
> +++ b/gdb/tic6x-tdep.c
> @@ -24,7 +24,7 @@
>  #include "frame-unwind.h"
>  #include "frame-base.h"
>  #include "trad-frame.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "symtab.h"
>  #include "inferior.h"
>  #include "gdbtypes.h"
> diff --git a/gdb/tilegx-tdep.c b/gdb/tilegx-tdep.c
> index 9290bc3878b..70c4add90b1 100644
> --- a/gdb/tilegx-tdep.c
> +++ b/gdb/tilegx-tdep.c
> @@ -21,7 +21,7 @@
>  #include "frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "trad-frame.h"
>  #include "symtab.h"
>  #include "gdbtypes.h"
> diff --git a/gdb/v850-tdep.c b/gdb/v850-tdep.c
> index 9b2e9b62e71..fd5a9ff4587 100644
> --- a/gdb/v850-tdep.c
> +++ b/gdb/v850-tdep.c
> @@ -22,7 +22,7 @@
>  #include "frame-base.h"
>  #include "trad-frame.h"
>  #include "frame-unwind.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "gdbtypes.h"
>  #include "inferior.h"
>  #include "gdbcore.h"
> diff --git a/gdb/xstormy16-tdep.c b/gdb/xstormy16-tdep.c
> index 0206af8bebc..1715dc81e38 100644
> --- a/gdb/xstormy16-tdep.c
> +++ b/gdb/xstormy16-tdep.c
> @@ -21,7 +21,7 @@
>  #include "frame.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
> -#include "dwarf2-frame.h"
> +#include "dwarf2/frame.h"
>  #include "symtab.h"
>  #include "gdbtypes.h"
>  #include "gdbcmd.h"
> diff --git a/gdb/xtensa-tdep.c b/gdb/xtensa-tdep.c
> index bbd92d5cf8f..2ea11212601 100644
> --- a/gdb/xtensa-tdep.c
> +++ b/gdb/xtensa-tdep.c
> @@ -35,8 +35,8 @@
>
>  #include "dummy-frame.h"
>  #include "dwarf2.h"
> -#include "dwarf2-frame.h"
> -#include "dwarf2loc.h"
> +#include "dwarf2/frame.h"
> +#include "dwarf2/loc.h"
>  #include "frame-base.h"
>  #include "frame-unwind.h"
>
> --
> 2.17.2
>
>

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 30/38] Unify read_initial_length implementations
  2020-01-27 13:31   ` Christian Biesinger via gdb-patches
@ 2020-01-28  0:54     ` Tom Tromey
  0 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-28  0:54 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Tom Tromey, gdb-patches

>>>>> "Christian" == Christian Biesinger <cbiesinger@google.com> writes:

Christian>  +/* Read the initial length from a section.  The (draft) DWARF 3

Christian> Maybe it's time to remove the "draft" part about dwarf 3? :)

I'll tack on a separate patch to fix up the comment.
Thanks for pointing this out.

Tom

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 11/38] Move DWARF code to dwarf2/ subdirectory
  2020-01-27 13:41   ` Christian Biesinger via gdb-patches
@ 2020-01-28  3:12     ` Tom Tromey
  0 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-01-28  3:12 UTC (permalink / raw)
  To: Christian Biesinger; +Cc: Tom Tromey, gdb-patches

>>>>> "Christian" == Christian Biesinger <cbiesinger@google.com> writes:

>  This moves all the remaining DWARF code to the new dwarf2
>  subdirectory.  This is just a simple renaming, with updates to
>  includes as needed.

Christian> Two questions:
Christian> - Why dwarf2 instead of something more generic, since this supports dwarf 2-5?

I suppose everything was named "dwarf2" historically because v2 was a
big change from v1.  However, there doesn't seem to be a need to
preserve this distinction any more.

Christian> - thoughts on renaming the files to .cc?

I'm personally ambivalent.  I would do it if there's consensus though.

Tom

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 14/38] Change dwarf2_per_objfile::signatured_types to be htab_up
  2020-01-23  0:57 ` [PATCH 14/38] Change dwarf2_per_objfile::signatured_types to be htab_up Tom Tromey
@ 2020-02-08 16:55   ` Simon Marchi
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Marchi @ 2020-02-08 16:55 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index 1e64870678e..10cbc7bd231 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -727,11 +727,11 @@ struct dwo_file
>       Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
>       an extension to handle LLVM's Link Time Optimization output (where
>       multiple source files may be compiled into a single object/dwo pair). */
> -  htab_t cus {};
> +  htab_up cus {};
>  
>    /* Table of TUs in the file.
>       Each element is a struct dwo_unit.  */
> -  htab_t tus {};
> +  htab_up tus {};
>  };

You can remove the {} here.

Simon

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 38/38] Remove "keep" parameter from cutu_reader constructor
  2020-01-23  0:57 ` [PATCH 38/38] Remove "keep" parameter from cutu_reader constructor Tom Tromey
@ 2020-02-08 17:36   ` Simon Marchi
  0 siblings, 0 replies; 48+ messages in thread
From: Simon Marchi @ 2020-02-08 17:36 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

> diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
> index d1a78afd8cf..754b752dc5d 100644
> --- a/gdb/dwarf2/read.c
> +++ b/gdb/dwarf2/read.c
> @@ -881,14 +881,14 @@ public:
>  
>    cutu_reader (struct dwarf2_per_cu_data *this_cu,
>  	       struct abbrev_table *abbrev_table,
> -	       int use_existing_cu, int keep,
> +	       int use_existing_cu,
>  	       bool skip_partial);
>  
>    explicit cutu_reader (struct dwarf2_per_cu_data *this_cu,
>  			struct dwarf2_cu *parent_cu = nullptr,
>  			struct dwo_file *dwo_file = nullptr);
>  
> -  ~cutu_reader ();
> +  ~cutu_reader () = default;

Can't you just delete this line?

Simon

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 00/38] Start reorganization of DWARF code
  2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
                   ` (37 preceding siblings ...)
  2020-01-23  2:34 ` [PATCH 37/38] Simplify "want_partial_unit" handling Tom Tromey
@ 2020-02-08 17:38 ` Simon Marchi
  2020-02-08 20:45   ` Tom Tromey
  38 siblings, 1 reply; 48+ messages in thread
From: Simon Marchi @ 2020-02-08 17:38 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2020-01-22 7:56 p.m., Tom Tromey wrote:
> Most of the DWARF-related code in gdb is in one file, dwarf2read.c --
> the single largest source file in gdb proper (I didn't check the
> libraries).  As a consequence it is disorganized.
> 
> I've thought for a while that dwarf2read.c should be split up, and
> this series is the start of this project.  This series does several
> things:
> 
> * Splits some code out of dwarf2read.c into new files;
> * In one or two cases, unifies code that is duplicated;
> * Moves all the DWARF-related code to a subdirectory;
> * Cleans up various APIs in small ways (like turning functions into
>   methods on the appropriate class);
> * Fixes a few minor bugs (I got distracted mid-series by moving hash
>   tables off the objfile obstack, a gdb practice that's bothered me
>   for years).
> 
> This series only shrinks dwarf2read.c from 26279 lines to 24744.  So,
> there's clearly still much more to do.  The line number program state
> machine or the macro-reading code seem like good candidates for
> splitting out.
> 
> Tested by the buildbot.
> 
> Tom

Hi Tom,

I've looked through the series, I think this is very nice and I agree with
all the changes you did.  Impressive work!

Simon

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 00/38] Start reorganization of DWARF code
  2020-02-08 17:38 ` [PATCH 00/38] Start reorganization of DWARF code Simon Marchi
@ 2020-02-08 20:45   ` Tom Tromey
  0 siblings, 0 replies; 48+ messages in thread
From: Tom Tromey @ 2020-02-08 20:45 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

Simon> I've looked through the series, I think this is very nice and I
Simon> agree with all the changes you did.  Impressive work!

Thanks.

I've fixed up the two things you pointed out, and I am going to commit
it shortly.

Tom

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2020-02-08 20:45 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
2020-01-23  0:57 ` [PATCH 35/38] Convert read_address to a method on comp_unit_head Tom Tromey
2020-01-23  0:57 ` [PATCH 07/38] Change attr_form_is_block to be a method Tom Tromey
2020-01-23  0:57 ` [PATCH 16/38] Change dwarf2_per_objfile::line_header_hash to htab_up Tom Tromey
2020-01-23  0:57 ` [PATCH 31/38] Convert dwarf2_section_size to a method Tom Tromey
2020-01-23  0:57 ` [PATCH 19/38] Change dwarf2_per_objfile::die_type_hash to htab_up Tom Tromey
2020-01-23  0:57 ` [PATCH 27/38] Move DWARF line_header to new file Tom Tromey
2020-01-23  0:57 ` [PATCH 38/38] Remove "keep" parameter from cutu_reader constructor Tom Tromey
2020-02-08 17:36   ` Simon Marchi
2020-01-23  0:57 ` [PATCH 05/38] Create dwarf2/attribute.[ch] Tom Tromey
2020-01-23  0:57 ` [PATCH 32/38] Move read_offset_1 to leb.c Tom Tromey
2020-01-23  0:57 ` [PATCH 22/38] Minor simplification in abbrev_table::read Tom Tromey
2020-01-23  0:57 ` [PATCH 13/38] Remove DWARF queue-related globals Tom Tromey
2020-01-23  0:57 ` [PATCH 02/38] Create dwarf2/section.[ch] Tom Tromey
2020-01-23  0:57 ` [PATCH 34/38] Convert read_offset to method on comp_unit_head Tom Tromey
2020-01-23  0:57 ` [PATCH 21/38] Use htab_up in abbrev_table Tom Tromey
2020-01-23  0:57 ` [PATCH 36/38] Move two more functions to dwarf2/leb.h Tom Tromey
2020-01-23  0:57 ` [PATCH 15/38] Change dwarf2_per_objfile::type_unit_groups to htab_up Tom Tromey
2020-01-23  0:57 ` [PATCH 23/38] Change dwarf2_per_objfile::quick_file_names_table " Tom Tromey
2020-01-23  0:57 ` [PATCH 33/38] Create dwarf2/comp-unit.[ch] Tom Tromey
2020-01-23  0:57 ` [PATCH 08/38] Remove die_info_ptr typedef Tom Tromey
2020-01-23  0:57 ` [PATCH 01/38] Create dwarf2/leb.[ch] Tom Tromey
2020-01-23  0:57 ` [PATCH 26/38] Change line_table methods to return unique_xmalloc_ptr Tom Tromey
2020-01-23  0:57 ` [PATCH 06/38] Change some attribute functions to be methods Tom Tromey
2020-01-23  0:57 ` [PATCH 11/38] Move DWARF code to dwarf2/ subdirectory Tom Tromey
2020-01-27 13:41   ` Christian Biesinger via gdb-patches
2020-01-28  3:12     ` Tom Tromey
2020-01-23  0:57 ` [PATCH 14/38] Change dwarf2_per_objfile::signatured_types to be htab_up Tom Tromey
2020-02-08 16:55   ` Simon Marchi
2020-01-23  0:57 ` [PATCH 25/38] Change file_full_name and file_file_name methods Tom Tromey
2020-01-27 13:31   ` Christian Biesinger via gdb-patches
2020-01-23  0:57 ` [PATCH 18/38] Change dwp_file to use htab_up Tom Tromey
2020-01-23  0:57 ` [PATCH 04/38] Create dwarf2/abbrev.[ch] Tom Tromey
2020-01-23  0:57 ` [PATCH 12/38] Introduce die_info::has_children Tom Tromey
2020-01-23  0:57 ` [PATCH 10/38] Remove die_reader_specs::comp_dir Tom Tromey
2020-01-23  0:57 ` [PATCH 28/38] Move dwarf2_per_cu_data::imported_symtabs earlier Tom Tromey
2020-01-23  0:57 ` [PATCH 20/38] Minor cleanups in abbrev_table Tom Tromey
2020-01-23  0:57 ` [PATCH 30/38] Unify read_initial_length implementations Tom Tromey
2020-01-27 13:31   ` Christian Biesinger via gdb-patches
2020-01-28  0:54     ` Tom Tromey
2020-01-23  0:57 ` [PATCH 09/38] Don't declare die_info in dwarf2read.h Tom Tromey
2020-01-23  0:57 ` [PATCH 24/38] Move dwarf_always_disassemble to dwarf2/loc.c Tom Tromey
2020-01-23  0:57 ` [PATCH 17/38] Don't allocate DWO file hash on obstack Tom Tromey
2020-01-23  1:12 ` [PATCH 03/38] Change section functions to be methods of dwarf2_section_info Tom Tromey
2020-01-23  1:21 ` [PATCH 29/38] Add some methods to dwarf2_per_cu_data Tom Tromey
2020-01-23  2:34 ` [PATCH 37/38] Simplify "want_partial_unit" handling Tom Tromey
2020-02-08 17:38 ` [PATCH 00/38] Start reorganization of DWARF code Simon Marchi
2020-02-08 20:45   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).