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 v2 17/20] Change die_info methods to check the attribute's form
Date: Sat,  4 Apr 2020 08:43:17 -0600	[thread overview]
Message-ID: <20200404144320.18851-18-tom@tromey.com> (raw)
In-Reply-To: <20200404144320.18851-1-tom@tromey.com>

This changes two die_info methods to check the form of the attribute
before using it.

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

	* dwarf2/die.h (struct die_info) <addr_base, ranges_base>: Check
	the attribute's form.
---
 gdb/ChangeLog    |  5 +++++
 gdb/dwarf2/die.h | 22 +++++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/gdb/dwarf2/die.h b/gdb/dwarf2/die.h
index 5522ebdf311..4bc15d631e3 100644
--- a/gdb/dwarf2/die.h
+++ b/gdb/dwarf2/die.h
@@ -20,6 +20,8 @@
 #ifndef GDB_DWARF2_DIE_H
 #define GDB_DWARF2_DIE_H
 
+#include "complaints.h"
+
 /* This data structure holds a complete die structure.  */
 struct die_info
 {
@@ -40,10 +42,15 @@ struct die_info
   {
     for (unsigned i = 0; i < num_attrs; ++i)
       if (attrs[i].name == DW_AT_addr_base
-	  || attrs[i].name == DW_AT_GNU_addr_base)
+	   || attrs[i].name == DW_AT_GNU_addr_base)
 	{
-	  /* If both exist, just use the first one.  */
-	  return DW_UNSND (&attrs[i]);
+	  if (attrs[i].form_is_unsigned ())
+	    {
+	      /* If both exist, just use the first one.  */
+	      return attrs[i].as_unsigned ();
+	    }
+	  complaint (_("address base attribute (offset %s) as wrong form"),
+		     sect_offset_str (sect_off));
 	}
     return gdb::optional<ULONGEST> ();
   }
@@ -57,8 +64,13 @@ struct die_info
       if (attrs[i].name == DW_AT_rnglists_base
 	  || attrs[i].name == DW_AT_GNU_ranges_base)
 	{
-	  /* If both exist, just use the first one.  */
-	  return DW_UNSND (&attrs[i]);
+	  if (attrs[i].form_is_unsigned ())
+	    {
+	      /* If both exist, just use the first one.  */
+	      return attrs[i].as_unsigned ();
+	    }
+	  complaint (_("ranges base attribute (offset %s) as wrong form"),
+		     sect_offset_str (sect_off));
 	}
     return 0;
   }
-- 
2.17.2


  parent reply	other threads:[~2020-04-04 14:43 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-04 14:43 [PATCH v2 00/20] Make DWARF attribute references safe Tom Tromey
2020-04-04 14:43 ` [PATCH v2 01/20] Add attribute::value_as_string method Tom Tromey
2020-04-04 14:43 ` [PATCH v2 02/20] Rename struct attribute accessors Tom Tromey
2020-04-04 14:43 ` [PATCH v2 03/20] Avoid using DW_* macros in dwarf2/attribute.c Tom Tromey
2020-04-04 14:43 ` [PATCH v2 04/20] Change some uses of DW_STRING to string method Tom Tromey
2020-09-30 15:11   ` Tom de Vries
2020-09-30 19:50     ` [committed][gdb] Fix regression in dwarf2_name Tom de Vries
2020-04-04 14:43 ` [PATCH v2 05/20] Remove some uses of DW_STRING_IS_CANONICAL Tom Tromey
2020-04-04 14:43 ` [PATCH v2 06/20] Remove DW_STRING and DW_STRING_IS_CANONICAL Tom Tromey
2020-04-04 14:43 ` [PATCH v2 07/20] Remove DW_BLOCK Tom Tromey
2020-04-04 14:43 ` [PATCH v2 08/20] Remove DW_SIGNATURE Tom Tromey
2020-04-04 14:43 ` [PATCH v2 09/20] Remove DW_SND Tom Tromey
2020-04-04 14:43 ` [PATCH v2 10/20] Use setter for attribute's unsigned value Tom Tromey
2020-04-04 14:43 ` [PATCH v2 11/20] Add reprocessing flag to struct attribute Tom Tromey
2020-04-04 14:43 ` [PATCH v2 12/20] Remove DW_ADDR Tom Tromey
2020-04-04 14:43 ` [PATCH v2 13/20] Change how reprocessing is done Tom Tromey
2020-04-04 14:43 ` [PATCH v2 14/20] Change how accessibility is handled in dwarf2/read.c Tom Tromey
2020-04-04 14:43 ` [PATCH v2 15/20] Add attribute::as_unsigned method Tom Tromey
2020-04-04 14:43 ` [PATCH v2 16/20] Change is_valid_DW_AT_defaulted to a method on attribute Tom Tromey
2020-04-04 14:43 ` Tom Tromey [this message]
2020-04-04 14:43 ` [PATCH v2 18/20] Add attribute::as_virtuality method Tom Tromey
2020-04-04 14:43 ` [PATCH v2 19/20] Add attribute::as_boolean method Tom Tromey
2020-04-04 14:43 ` [PATCH v2 20/20] Remove DW_UNSND Tom Tromey
2020-09-30  8:35   ` Tom de Vries
2020-09-30 16:41     ` Tom Tromey
2020-09-30  2:28 ` [PATCH v2 00/20] Make DWARF attribute references safe 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=20200404144320.18851-18-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).