public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 07/38] Change attr_form_is_block to be a method
Date: Thu, 23 Jan 2020 00:57:00 -0000	[thread overview]
Message-ID: <20200123005710.7978-8-tom@tromey.com> (raw)
In-Reply-To: <20200123005710.7978-1-tom@tromey.com>

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

  parent reply	other threads:[~2020-01-23  0:57 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-23  0:57 [PATCH 00/38] Start reorganization of DWARF code 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 20/38] Minor cleanups in abbrev_table 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  0:57 ` [PATCH 09/38] Don't declare die_info in dwarf2read.h Tom Tromey
2020-01-23  0:57 ` [PATCH 18/38] Change dwp_file to use htab_up Tom Tromey
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 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 28/38] Move dwarf2_per_cu_data::imported_symtabs earlier Tom Tromey
2020-01-23  0:57 ` [PATCH 10/38] Remove die_reader_specs::comp_dir Tom Tromey
2020-01-23  0:57 ` [PATCH 12/38] Introduce die_info::has_children Tom Tromey
2020-01-23  0:57 ` [PATCH 04/38] Create dwarf2/abbrev.[ch] Tom Tromey
2020-01-23  0:57 ` [PATCH 33/38] Create dwarf2/comp-unit.[ch] Tom Tromey
2020-01-23  0:57 ` [PATCH 23/38] Change dwarf2_per_objfile::quick_file_names_table to htab_up Tom Tromey
2020-01-23  0:57 ` [PATCH 15/38] Change dwarf2_per_objfile::type_unit_groups " 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 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 02/38] Create dwarf2/section.[ch] 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 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 01/38] Create dwarf2/leb.[ch] Tom Tromey
2020-01-23  0:57 ` [PATCH 08/38] Remove die_info_ptr typedef 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 31/38] Convert dwarf2_section_size to 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 ` Tom Tromey [this message]
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 13/38] Remove DWARF queue-related globals Tom Tromey
2020-01-23  0:57 ` [PATCH 22/38] Minor simplification in abbrev_table::read 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 05/38] Create dwarf2/attribute.[ch] 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 27/38] Move DWARF line_header to new file 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

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=20200123005710.7978-8-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).