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 15/20] Add attribute::get_unsigned method
Date: Sat, 28 Mar 2020 13:22:03 -0600	[thread overview]
Message-ID: <20200328192208.11324-16-tom@tromey.com> (raw)
In-Reply-To: <20200328192208.11324-1-tom@tromey.com>

This introduces a new attribute::get_unsigned method and changes a few
spots to use it.

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

	* dwarf2/read.c (dw2_get_file_names_reader)
	(dwarf2_build_include_psymtabs, handle_DW_AT_stmt_list)
	(dwarf2_cu::setup_type_unit_groups, fill_in_loclist_baton)
	(dwarf2_symbol_mark_computed): Use get_unsigned.
	* dwarf2/attribute.h (struct attribute) <get_unsigned>: New
	method.
	<form_is_section_offset>: Update comment.
---
 gdb/ChangeLog          | 10 ++++++++++
 gdb/dwarf2/attribute.h | 11 ++++++++++-
 gdb/dwarf2/read.c      | 22 +++++++++++-----------
 3 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index 9b387e5df05..546156283b3 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -82,9 +82,18 @@ struct attribute
     return u.unsnd;
   }
 
+  /* Return the unsigned value.  Requires that the form be an unsigned
+     form, and that reprocessing not be needed.  */
+  ULONGEST get_unsigned () const
+  {
+    gdb_assert (form_is_unsigned ());
+    gdb_assert (!requires_reprocessing);
+    return u.unsnd;
+  }
+
   /* 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.
+     You may use the get_unsigned method 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
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index efa59fcab4d..abeb0e1a4e9 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -3046,11 +3046,11 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
   sect_offset line_offset {};
 
   attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu);
-  if (attr != nullptr)
+  if (attr != nullptr && attr->form_is_unsigned ())
     {
       struct quick_file_names find_entry;
 
-      line_offset = (sect_offset) DW_UNSND (attr);
+      line_offset = (sect_offset) attr->get_unsigned ();
 
       /* We may have already read in this line header (TU line header sharing).
 	 If we have we're done.  */
@@ -5892,8 +5892,8 @@ dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
   struct attribute *attr;
 
   attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
-  if (attr != nullptr)
-    lh = dwarf_decode_line_header ((sect_offset) DW_UNSND (attr), cu);
+  if (attr != nullptr && attr->form_is_unsigned ())
+    lh = dwarf_decode_line_header ((sect_offset) attr->get_unsigned (), cu);
   if (lh == NULL)
     return;  /* No linetable, so no includes.  */
 
@@ -10560,10 +10560,10 @@ handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu,
   gdb_assert (! cu->per_cu->is_debug_types);
 
   attr = dwarf2_attr (die, DW_AT_stmt_list, cu);
-  if (attr == NULL)
+  if (attr == NULL || !attr->form_is_unsigned ())
     return;
 
-  sect_offset line_offset = (sect_offset) DW_UNSND (attr);
+  sect_offset line_offset = (sect_offset) attr->get_unsigned ();
 
   /* The line header hash table is only created if needed (it exists to
      prevent redundant reading of the line table for partial_units).
@@ -10752,9 +10752,9 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die)
   /* We have to handle the case of both a missing DW_AT_stmt_list or bad
      debug info.  */
   line_header_up lh;
-  if (attr != NULL)
+  if (attr != NULL && attr->form_is_unsigned ())
     {
-      sect_offset line_offset = (sect_offset) DW_UNSND (attr);
+      sect_offset line_offset = (sect_offset) attr->get_unsigned ();
       lh = dwarf_decode_line_header (line_offset, this);
     }
   if (lh == NULL)
@@ -22526,8 +22526,8 @@ fill_in_loclist_baton (struct dwarf2_cu *cu,
   gdb_assert (baton->per_cu);
   /* We don't know how long the location list is, but make sure we
      don't run off the edge of the section.  */
-  baton->size = section->size - DW_UNSND (attr);
-  baton->data = section->buffer + DW_UNSND (attr);
+  baton->size = section->size - attr->get_unsigned ();
+  baton->data = section->buffer + attr->get_unsigned ();
   if (cu->base_address.has_value ())
     baton->base_address = *cu->base_address;
   else
@@ -22548,7 +22548,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) < section->get_size (objfile))
+      && attr->get_unsigned () < section->get_size (objfile))
     {
       struct dwarf2_loclist_baton *baton;
 
-- 
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 ` [PATCH 10/20] Use setter for attribute's unsigned value Tom Tromey
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 ` Tom Tromey [this message]
2020-03-30 15:57   ` [PATCH 15/20] Add attribute::get_unsigned method 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-16-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).