Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 22/22] Change two functions to be methods on struct attribute
Date: Sun, 22 Mar 2020 12:45:23 -0600	[thread overview]
Message-ID: <20200322184523.28959-23-tom@tromey.com> (raw)
In-Reply-To: <20200322184523.28959-1-tom@tromey.com>

This changes dwarf2_get_ref_die_offset and
dwarf2_get_attr_constant_value to be methods on struct attribute.

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

	* dwarf2/read.c (handle_data_member_location, dwarf2_add_field)
	(mark_common_block_symbol_computed, read_tag_string_type)
	(attr_to_dynamic_prop, read_subrange_type): Update.
	(dwarf2_get_ref_die_offset, dwarf2_get_attr_constant_value): Move
	to be methods on struct attribute.
	(skip_one_die, process_imported_unit_die, read_namespace_alias)
	(read_call_site_scope, partial_die_info::read)
	(partial_die_info::read, lookup_die_type, follow_die_ref):
	Update.
	* dwarf2/attribute.c (attribute::get_ref_die_offset): New method,
	from dwarf2_get_ref_die_offset.
	(attribute::constant_value): New method, from
	dwarf2_get_attr_constant_value.
	* dwarf2/attribute.h (struct attribute) <get_ref_die_offset>:
	Declare method.
	<constant_value>: New method.
---
 gdb/ChangeLog          | 19 ++++++++++
 gdb/dwarf2/attribute.c | 37 ++++++++++++++++++++
 gdb/dwarf2/attribute.h | 12 +++++++
 gdb/dwarf2/read.c      | 78 ++++++++++--------------------------------
 4 files changed, 86 insertions(+), 60 deletions(-)

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 6efff3e2c0a..0e5a8c8f536 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -26,6 +26,8 @@
 
 #include "defs.h"
 #include "dwarf2/attribute.h"
+#include "dwarf2/stringify.h"
+#include "complaints.h"
 
 /* See attribute.h.  */
 
@@ -119,3 +121,38 @@ attribute::form_is_ref () const
       return false;
     }
 }
+
+/* See attribute.h.  */
+
+sect_offset
+attribute::get_ref_die_offset () const
+{
+  if (form_is_ref ())
+    return (sect_offset) DW_UNSND (this);
+
+  complaint (_("unsupported die ref attribute form: '%s'"),
+	     dwarf_form_name (form));
+  return {};
+}
+
+/* See attribute.h.  */
+
+LONGEST
+attribute::constant_value (int default_value) const
+{
+  if (form == DW_FORM_sdata || form == DW_FORM_implicit_const)
+    return DW_SND (this);
+  else if (form == DW_FORM_udata
+	   || form == DW_FORM_data1
+	   || form == DW_FORM_data2
+	   || form == DW_FORM_data4
+	   || form == DW_FORM_data8)
+    return DW_UNSND (this);
+  else
+    {
+      /* For DW_FORM_data16 see attribute::form_is_constant.  */
+      complaint (_("Attribute value is not a constant (%s)"),
+		 dwarf_form_name (form));
+      return default_value;
+    }
+}
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index c2602310715..483b805433b 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -28,6 +28,7 @@
 #define GDB_DWARF2_ATTRIBUTE_H
 
 #include "dwarf2.h"
+#include "gdbtypes.h"
 
 /* Blocks are a bunch of untyped bytes.  */
 struct dwarf_block
@@ -84,6 +85,17 @@ struct attribute
 
   bool form_is_block () const;
 
+  /* Return DIE offset of this attribute.  Return 0 with complaint if
+     the attribute is not of the required kind.  */
+
+  sect_offset get_ref_die_offset () const;
+
+  /* Return the constant value held by this attribute.  Return
+     DEFAULT_VALUE if the value held by the attribute is not
+     constant.  */
+
+  LONGEST constant_value (int default_value) const;
+
 
   ENUM_BITFIELD(dwarf_attribute) name : 16;
   ENUM_BITFIELD(dwarf_form) form : 15;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 87305ec3688..73df64d15fd 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1419,10 +1419,6 @@ static void dump_die_1 (struct ui_file *, int level, int max_level,
 static void store_in_ref_table (struct die_info *,
 				struct dwarf2_cu *);
 
-static sect_offset dwarf2_get_ref_die_offset (const struct attribute *);
-
-static LONGEST dwarf2_get_attr_constant_value (const struct attribute *, int);
-
 static struct die_info *follow_die_ref_or_sig (struct die_info *,
 					       const struct attribute *,
 					       struct dwarf2_cu **);
@@ -8476,7 +8472,7 @@ skip_one_die (const struct die_reader_specs *reader, const gdb_byte *info_ptr,
 	    complaint (_("ignoring absolute DW_AT_sibling"));
 	  else
 	    {
-	      sect_offset off = dwarf2_get_ref_die_offset (&attr);
+	      sect_offset off = attr.get_ref_die_offset ();
 	      const gdb_byte *sibling_ptr = buffer + to_underlying (off);
 
 	      if (sibling_ptr < info_ptr)
@@ -9643,7 +9639,7 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
   attr = dwarf2_attr (die, DW_AT_import, cu);
   if (attr != NULL)
     {
-      sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
+      sect_offset sect_off = attr->get_ref_die_offset ();
       bool is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
       dwarf2_per_cu_data *per_cu
 	= dwarf2_find_containing_comp_unit (sect_off, is_dwz,
@@ -10296,7 +10292,7 @@ read_namespace_alias (struct die_info *die, struct dwarf2_cu *cu)
       if (attr != NULL)
 	{
 	  struct type *type;
-	  sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
+	  sect_offset sect_off = attr->get_ref_die_offset ();
 
 	  type = get_die_type_at_offset (sect_off, cu->per_cu);
 	  if (type != NULL && TYPE_CODE (type) == TYPE_CODE_NAMESPACE)
@@ -13224,8 +13220,7 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 	{
 	  parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET;
 
-	  sect_offset sect_off
-	    = (sect_offset) dwarf2_get_ref_die_offset (origin);
+	  sect_offset sect_off = origin->get_ref_die_offset ();
 	  if (!cu->header.offset_in_cu_p (sect_off))
 	    {
 	      /* As DW_OP_GNU_parameter_ref uses CU-relative offset this
@@ -14059,7 +14054,7 @@ handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu,
 	 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 ())
-	*offset = dwarf2_get_attr_constant_value (attr, 0);
+	*offset = attr->constant_value (0);
       else if (attr->form_is_section_offset ())
 	dwarf2_complex_location_expr_complaint ();
       else if (attr->form_is_block ())
@@ -14186,7 +14181,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       attr = dwarf2_attr (die, DW_AT_data_bit_offset, cu);
       if (attr != NULL)
 	SET_FIELD_BITPOS (*fp, (FIELD_BITPOS (*fp)
-				+ dwarf2_get_attr_constant_value (attr, 0)));
+				+ attr->constant_value (0)));
 
       /* Get name of field.  */
       fieldname = dwarf2_name (die, cu);
@@ -15860,7 +15855,7 @@ mark_common_block_symbol_computed (struct symbol *sym,
 
   if (member_loc->form_is_constant ())
     {
-      offset = dwarf2_get_attr_constant_value (member_loc, 0);
+      offset = member_loc->constant_value (0);
       baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size;
     }
   else
@@ -16452,7 +16447,7 @@ 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);
+	  LONGEST sz = len->constant_value (0);
 	  prop_type = cu->per_cu->int_type (sz, true);
 	}
       else
@@ -16474,12 +16469,12 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
 	 indirection.  There's no need to create a dynamic property in this
 	 case.  Pass 0 for the default value as we know it will not be
 	 returned in this case.  */
-      length = dwarf2_get_attr_constant_value (attr, 0);
+      length = attr->constant_value (0);
     }
   else if ((attr = dwarf2_attr (die, DW_AT_byte_size, cu)) != nullptr)
     {
       /* We don't currently support non-constant byte sizes for strings.  */
-      length = dwarf2_get_attr_constant_value (attr, 1);
+      length = attr->constant_value (1);
     }
   else
     {
@@ -17058,7 +17053,7 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
     }
   else if (attr->form_is_constant ())
     {
-      prop->data.const_val = dwarf2_get_attr_constant_value (attr, 0);
+      prop->data.const_val = attr->constant_value (0);
       prop->kind = PROP_CONST;
     }
   else
@@ -17236,7 +17231,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 && bias_attr->form_is_constant ())
-    bias = dwarf2_get_attr_constant_value (bias_attr, 0);
+    bias = bias_attr->constant_value (0);
 
   /* Normally, the DWARF producers are expected to use a signed
      constant form (Eg. DW_FORM_sdata) to express negative bounds.
@@ -17942,7 +17937,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
 	case DW_AT_specification:
 	case DW_AT_extension:
 	  has_specification = 1;
-	  spec_offset = dwarf2_get_ref_die_offset (&attr);
+	  spec_offset = attr.get_ref_die_offset ();
 	  spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt
 				   || cu->per_cu->is_dwz);
 	  break;
@@ -17954,7 +17949,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
 	  else
 	    {
 	      const gdb_byte *buffer = reader->buffer;
-	      sect_offset off = dwarf2_get_ref_die_offset (&attr);
+	      sect_offset off = attr.get_ref_die_offset ();
 	      const gdb_byte *sibling_ptr = buffer + to_underlying (off);
 
 	      if (sibling_ptr < info_ptr)
@@ -17999,7 +17994,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
 	case DW_AT_import:
 	  if (tag == DW_TAG_imported_unit)
 	    {
-	      d.sect_off = dwarf2_get_ref_die_offset (&attr);
+	      d.sect_off = attr.get_ref_die_offset ();
 	      is_dwz = (attr.form == DW_FORM_GNU_ref_alt
 				  || cu->per_cu->is_dwz);
 	    }
@@ -20703,7 +20698,7 @@ lookup_die_type (struct die_info *die, const struct attribute *attr,
   if (attr->form == DW_FORM_GNU_ref_alt)
     {
       struct dwarf2_per_cu_data *per_cu;
-      sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
+      sect_offset sect_off = attr->get_ref_die_offset ();
 
       per_cu = dwarf2_find_containing_comp_unit (sect_off, 1,
 						 dwarf2_per_objfile);
@@ -20711,7 +20706,7 @@ lookup_die_type (struct die_info *die, const struct attribute *attr,
     }
   else if (attr->form_is_ref ())
     {
-      sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
+      sect_offset sect_off = attr->get_ref_die_offset ();
 
       this_type = get_die_type_at_offset (sect_off, cu->per_cu);
     }
@@ -21513,43 +21508,6 @@ store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu)
   *slot = die;
 }
 
-/* Return DIE offset of ATTR.  Return 0 with complaint if ATTR is not of the
-   required kind.  */
-
-static sect_offset
-dwarf2_get_ref_die_offset (const struct attribute *attr)
-{
-  if (attr->form_is_ref ())
-    return (sect_offset) DW_UNSND (attr);
-
-  complaint (_("unsupported die ref attribute form: '%s'"),
-	     dwarf_form_name (attr->form));
-  return {};
-}
-
-/* Return the constant value held by ATTR.  Return DEFAULT_VALUE if
- * the value held by the attribute is not constant.  */
-
-static LONGEST
-dwarf2_get_attr_constant_value (const struct attribute *attr, int default_value)
-{
-  if (attr->form == DW_FORM_sdata || attr->form == DW_FORM_implicit_const)
-    return DW_SND (attr);
-  else if (attr->form == DW_FORM_udata
-           || attr->form == DW_FORM_data1
-           || attr->form == DW_FORM_data2
-           || attr->form == DW_FORM_data4
-           || attr->form == DW_FORM_data8)
-    return DW_UNSND (attr);
-  else
-    {
-      /* 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;
-    }
-}
-
 /* Follow reference or signature attribute ATTR of SRC_DIE.
    On entry *REF_CU is the CU of SRC_DIE.
    On exit *REF_CU is the CU of the result.  */
@@ -21640,7 +21598,7 @@ static struct die_info *
 follow_die_ref (struct die_info *src_die, const struct attribute *attr,
 		struct dwarf2_cu **ref_cu)
 {
-  sect_offset sect_off = dwarf2_get_ref_die_offset (attr);
+  sect_offset sect_off = attr->get_ref_die_offset ();
   struct dwarf2_cu *cu = *ref_cu;
   struct die_info *die;
 
-- 
2.17.2



  parent reply	other threads:[~2020-03-22 18:45 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-22 18:45 [PATCH 00/22] More splitting of dwarf2/read.c Tom Tromey
2020-03-22 18:45 ` [PATCH 01/22] Introduce dwarf2/dwz.h Tom Tromey
2020-03-22 18:45 ` [PATCH 02/22] Add dwz.c and dwz_file::read_string Tom Tromey
2020-03-22 18:45 ` [PATCH 03/22] Change dwarf_decode_macro_bytes calling convention Tom Tromey
2020-03-22 18:45 ` [PATCH 04/22] Split dwarf_decode_macros into two overloads Tom Tromey
2020-03-23 16:13   ` Christian Biesinger
2020-03-26  2:09     ` Tom Tromey
2020-03-24  1:58   ` Simon Marchi
2020-03-26  2:10     ` Tom Tromey
2020-03-22 18:45 ` [PATCH 05/22] Move dwarf2_section_buffer_overflow_complaint to dwarf2/section.c Tom Tromey
2020-03-22 18:45 ` [PATCH 06/22] Convert dwarf2_section_buffer_overflow_complaint to a method Tom Tromey
2020-03-22 18:45 ` [PATCH 07/22] Add dwarf2_section_info::read_string method Tom Tromey
2020-03-22 18:45 ` [PATCH 08/22] Move code to new file dwarf2/macro.c Tom Tromey
2020-03-22 18:45 ` [PATCH 09/22] Make some line_header methods const Tom Tromey
2020-03-22 18:45 ` [PATCH 10/22] Use a const line_header in macro reader Tom Tromey
2020-03-22 18:45 ` [PATCH 11/22] Use a const dwarf2_section_info " Tom Tromey
2020-03-22 18:45 ` [PATCH 12/22] Trivial fix in dwarf_decode_macro_bytes Tom Tromey
2020-03-22 18:45 ` [PATCH 13/22] Convert read_indirect_line_string to a method Tom Tromey
2020-03-24  2:49   ` Simon Marchi
2020-03-22 18:45 ` [PATCH 14/22] Move more code to line-header.c Tom Tromey
2020-03-22 18:45 ` [PATCH 15/22] Move die_info to new header Tom Tromey
2020-03-22 18:45 ` [PATCH 16/22] Remove dwarf2_cu::base_known Tom Tromey
2020-03-22 18:45 ` [PATCH 17/22] Change dwarf2_attr_no_follow to be a method Tom Tromey
2020-03-22 18:45 ` [PATCH 18/22] Remove sibling_die Tom Tromey
2020-03-22 18:45 ` [PATCH 19/22] Change two more functions to be methods on die_info Tom Tromey
2020-03-23 19:07   ` Christian Biesinger
2020-03-26  2:17     ` Tom Tromey
2020-03-22 18:45 ` [PATCH 20/22] Rewrite new die_info methods Tom Tromey
2020-03-22 18:45 ` [PATCH 21/22] Move DWARF-constant stringifying code to new file Tom Tromey
2020-03-22 18:45 ` Tom Tromey [this message]
2020-03-24 13:34 ` [PATCH 00/22] More splitting of dwarf2/read.c Simon Marchi
2020-03-26 15:32   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200322184523.28959-23-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox