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 10/20] Use setter for attribute's unsigned value
Date: Sat, 28 Mar 2020 13:21:58 -0600	[thread overview]
Message-ID: <20200328192208.11324-11-tom@tromey.com> (raw)
In-Reply-To: <20200328192208.11324-1-tom@tromey.com>

This adds form_is_unsigned and an unsigned setter method to struct
attribute, and updates the remaining code.  Now DW_UNSND is no longer
used as an lvalue.

gdb/ChangeLog
2020-03-28  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.c (read_attribute_value): Update.
	* dwarf2/attribute.h (struct attribute) <form_is_unsigned,
	set_unsigned>: New methods.
	* dwarf2/attribute.c (attribute::form_is_unsigned): New method.
---
 gdb/ChangeLog          |  7 ++++++
 gdb/dwarf2/attribute.c | 23 +++++++++++++++++++
 gdb/dwarf2/attribute.h | 10 ++++++++
 gdb/dwarf2/read.c      | 52 +++++++++++++++++++++---------------------
 4 files changed, 66 insertions(+), 26 deletions(-)

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index fdf202033e9..72ec13c11f9 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -183,3 +183,26 @@ attribute::constant_value (int default_value) const
       return default_value;
     }
 }
+
+/* See attribute.h.  */
+
+bool
+attribute::form_is_unsigned () const
+{
+  return (form == DW_FORM_ref_addr
+	  || form == DW_FORM_GNU_ref_alt
+	  || form == DW_FORM_data2
+	  || form == DW_FORM_data4
+	  || form == DW_FORM_data8
+	  || form == DW_FORM_sec_offset
+	  || form == DW_FORM_data1
+	  || form == DW_FORM_flag
+	  || form == DW_FORM_flag_present
+	  || form == DW_FORM_udata
+	  || form == DW_FORM_rnglistx
+	  || form == DW_FORM_ref1
+	  || form == DW_FORM_ref2
+	  || form == DW_FORM_ref4
+	  || form == DW_FORM_ref8
+	  || form == DW_FORM_ref_udata);
+}
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index a08c5a13e44..0a4c8647f6e 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -115,6 +115,9 @@ struct attribute
   /* Check if the attribute's form is a string form.  */
   bool form_is_string () const;
 
+  /* Check if the attribute's form is an unsigned integer form.  */
+  bool form_is_unsigned () const;
+
   /* Return DIE offset of this attribute.  Return 0 with complaint if
      the attribute is not of the required kind.  */
 
@@ -169,6 +172,13 @@ struct attribute
     u.snd = snd;
   }
 
+  /* Set this attribute to an unsigned integer.  */
+  void set_unsigned (ULONGEST unsnd)
+  {
+    gdb_assert (form_is_unsigned ());
+    u.unsnd = unsnd;
+  }
+
 
   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 6eecf051c84..75ac56efc02 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18360,15 +18360,16 @@ read_attribute_value (const struct die_reader_specs *reader,
     {
     case DW_FORM_ref_addr:
       if (cu->header.version == 2)
-	DW_UNSND (attr) = cu->header.read_address (abfd, info_ptr,
-						   &bytes_read);
+	attr->set_unsigned (cu->header.read_address (abfd, info_ptr,
+						     &bytes_read));
       else
-	DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr,
-						  &bytes_read);
+	attr->set_unsigned (cu->header.read_offset (abfd, info_ptr,
+						    &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_GNU_ref_alt:
-      DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr, &bytes_read);
+      attr->set_unsigned (cu->header.read_offset (abfd, info_ptr,
+						  &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_addr:
@@ -18393,15 +18394,15 @@ read_attribute_value (const struct die_reader_specs *reader,
       attr->set_block (blk);
       break;
     case DW_FORM_data2:
-      DW_UNSND (attr) = read_2_bytes (abfd, info_ptr);
+      attr->set_unsigned (read_2_bytes (abfd, info_ptr));
       info_ptr += 2;
       break;
     case DW_FORM_data4:
-      DW_UNSND (attr) = read_4_bytes (abfd, info_ptr);
+      attr->set_unsigned (read_4_bytes (abfd, info_ptr));
       info_ptr += 4;
       break;
     case DW_FORM_data8:
-      DW_UNSND (attr) = read_8_bytes (abfd, info_ptr);
+      attr->set_unsigned (read_8_bytes (abfd, info_ptr));
       info_ptr += 8;
       break;
     case DW_FORM_data16:
@@ -18412,7 +18413,8 @@ read_attribute_value (const struct die_reader_specs *reader,
       attr->set_block (blk);
       break;
     case DW_FORM_sec_offset:
-      DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr, &bytes_read);
+      attr->set_unsigned (cu->header.read_offset (abfd, info_ptr,
+						  &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_string:
@@ -18467,15 +18469,12 @@ read_attribute_value (const struct die_reader_specs *reader,
       attr->set_block (blk);
       break;
     case DW_FORM_data1:
-      DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
-      info_ptr += 1;
-      break;
     case DW_FORM_flag:
-      DW_UNSND (attr) = read_1_byte (abfd, info_ptr);
+      attr->set_unsigned (read_1_byte (abfd, info_ptr));
       info_ptr += 1;
       break;
     case DW_FORM_flag_present:
-      DW_UNSND (attr) = 1;
+      attr->set_unsigned (1);
       break;
     case DW_FORM_sdata:
       attr->set_signed (read_signed_leb128 (abfd, info_ptr, &bytes_read));
@@ -18483,27 +18482,27 @@ read_attribute_value (const struct die_reader_specs *reader,
       break;
     case DW_FORM_udata:
     case DW_FORM_rnglistx:
-      DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read);
+      attr->set_unsigned (read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
       info_ptr += bytes_read;
       break;
     case DW_FORM_ref1:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-			 + read_1_byte (abfd, info_ptr));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+			   + read_1_byte (abfd, info_ptr)));
       info_ptr += 1;
       break;
     case DW_FORM_ref2:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-			 + read_2_bytes (abfd, info_ptr));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+			   + read_2_bytes (abfd, info_ptr)));
       info_ptr += 2;
       break;
     case DW_FORM_ref4:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-			 + read_4_bytes (abfd, info_ptr));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+			   + read_4_bytes (abfd, info_ptr)));
       info_ptr += 4;
       break;
     case DW_FORM_ref8:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-			 + read_8_bytes (abfd, info_ptr));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+			   + read_8_bytes (abfd, info_ptr)));
       info_ptr += 8;
       break;
     case DW_FORM_ref_sig8:
@@ -18511,8 +18510,9 @@ read_attribute_value (const struct die_reader_specs *reader,
       info_ptr += 8;
       break;
     case DW_FORM_ref_udata:
-      DW_UNSND (attr) = (to_underlying (cu->header.sect_off)
-			 + read_unsigned_leb128 (abfd, info_ptr, &bytes_read));
+      attr->set_unsigned ((to_underlying (cu->header.sect_off)
+			   + read_unsigned_leb128 (abfd, info_ptr,
+						   &bytes_read)));
       info_ptr += bytes_read;
       break;
     case DW_FORM_indirect:
@@ -18595,7 +18595,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       complaint
         (_("Suspicious DW_AT_byte_size value treated as zero instead of %s"),
          hex_string (DW_UNSND (attr)));
-      DW_UNSND (attr) = 0;
+      attr->set_unsigned (0);
     }
 
   return info_ptr;
-- 
2.17.2


  parent reply	other threads:[~2020-03-28 19:22 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-28 19:21 [PATCH 00/20] Make DWARF attribute references safe Tom Tromey
2020-03-28 19:21 ` [PATCH 01/20] Add attribute::value_as_string method Tom Tromey
2020-03-28 19:21 ` [PATCH 02/20] Rename struct attribute accessors Tom Tromey
2020-03-30  8:58   ` Aktemur, Tankut Baris
2020-03-30 23:39     ` Tom Tromey
2020-03-30 14:45   ` Simon Marchi
2020-03-30 23:39     ` Tom Tromey
2020-03-28 19:21 ` [PATCH 03/20] Avoid using DW_* macros in dwarf2/attribute.c Tom Tromey
2020-03-28 19:21 ` [PATCH 04/20] Change some uses of DW_STRING to string method Tom Tromey
2020-03-30 14:56   ` Simon Marchi
2020-03-30 23:53     ` Tom Tromey
2020-03-28 19:21 ` [PATCH 05/20] Remove some uses of DW_STRING_IS_CANONICAL Tom Tromey
2020-03-30 15:02   ` Simon Marchi
2020-03-31  0:01     ` Tom Tromey
2020-03-28 19:21 ` [PATCH 06/20] Remove DW_STRING and DW_STRING_IS_CANONICAL Tom Tromey
2020-03-30 15:10   ` Simon Marchi
2020-03-31  0:23     ` Tom Tromey
2020-03-28 19:21 ` [PATCH 07/20] Remove DW_BLOCK Tom Tromey
2020-03-30 15:13   ` Simon Marchi
2020-03-28 19:21 ` [PATCH 08/20] Remove DW_SIGNATURE Tom Tromey
2020-03-28 19:21 ` [PATCH 09/20] Remove DW_SND Tom Tromey
2020-03-28 19:21 ` Tom Tromey [this message]
2020-03-28 19:21 ` [PATCH 11/20] Add reprocessing flag to struct attribute Tom Tromey
2020-03-30 15:32   ` Simon Marchi
2020-04-04 14:02     ` Tom Tromey
2020-03-28 19:22 ` [PATCH 12/20] Remove DW_ADDR Tom Tromey
2020-03-30 15:40   ` Simon Marchi
2020-04-04 14:05     ` Tom Tromey
2020-03-28 19:22 ` [PATCH 13/20] Change how reprocessing is done Tom Tromey
2020-03-30 15:46   ` Simon Marchi
2020-04-04 14:14     ` Tom Tromey
2020-03-28 19:22 ` [PATCH 14/20] Change how accessibility is handled in dwarf2/read.c Tom Tromey
2020-03-30 15:50   ` Simon Marchi
2020-03-28 19:22 ` [PATCH 15/20] Add attribute::get_unsigned method Tom Tromey
2020-03-30 15:57   ` Simon Marchi
2020-04-04 14:17     ` Tom Tromey
2020-03-28 19:22 ` [PATCH 16/20] Change is_valid_DW_AT_defaulted to a method on attribute Tom Tromey
2020-03-30 16:00   ` Simon Marchi
2020-04-04 14:23     ` Tom Tromey
2020-03-28 19:22 ` [PATCH 17/20] Change die_info methods to check the attribute's form Tom Tromey
2020-03-30 16:02   ` Simon Marchi
2020-03-30 19:04     ` Tom Tromey
2020-03-30 20:18       ` Simon Marchi
2020-03-30 20:26         ` Tom Tromey
2020-03-28 19:22 ` [PATCH 18/20] Add attribute::virtuality method Tom Tromey
2020-03-28 19:22 ` [PATCH 19/20] Add attribute::boolean method Tom Tromey
2020-03-28 19:22 ` [PATCH 20/20] Remove DW_UNSND 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=20200328192208.11324-11-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).