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 04/10] Add attribute::value_as_string method
Date: Wed, 25 Mar 2020 14:07:09 -0600	[thread overview]
Message-ID: <20200325200715.12947-5-tom@tromey.com> (raw)
In-Reply-To: <20200325200715.12947-1-tom@tromey.com>

The full DIE reader checks that an attribute has a "string" form in
some spots, but the partial DIE reader does not.  This patch brings
the two readers in sync for one specific case, namely when examining
the linkage name.  This avoids regressions in an existing DWARF test
case.

A full fix for this problem would be preferable.  An accessor like
DW_STRING should always check the form.  However, I haven't attempted
that in this series.

Also the fact that the partial and full readers can disagree like this
is a design flaw.

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

	* dwarf2/read.c (partial_die_info::read) <case
	DW_AT_linkage_name>: Use value_as_string.
	(dwarf2_string_attr): Use value_as_string.
	* dwarf2/attribute.h (struct attribute) <value_as_string>: Declare
	method.
	* dwarf2/attribute.c (attribute::value_as_string): New method.
---
 gdb/ChangeLog          |  9 +++++++++
 gdb/dwarf2/attribute.c | 18 ++++++++++++++++++
 gdb/dwarf2/attribute.h |  4 ++++
 gdb/dwarf2/read.c      | 15 +++------------
 4 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/gdb/dwarf2/attribute.c b/gdb/dwarf2/attribute.c
index 6efff3e2c0a..273f17a2cb0 100644
--- a/gdb/dwarf2/attribute.c
+++ b/gdb/dwarf2/attribute.c
@@ -59,6 +59,24 @@ attribute::value_as_address () const
 
 /* See attribute.h.  */
 
+const char *
+attribute::value_as_string () const
+{
+  if (form == DW_FORM_strp || form == DW_FORM_line_strp
+      || form == DW_FORM_string
+      || form == DW_FORM_strx
+      || form == DW_FORM_strx1
+      || form == DW_FORM_strx2
+      || form == DW_FORM_strx3
+      || form == DW_FORM_strx4
+      || form == DW_FORM_GNU_str_index
+      || form == DW_FORM_GNU_strp_alt)
+    return DW_STRING (this);
+  return nullptr;
+}
+
+/* See attribute.h.  */
+
 bool
 attribute::form_is_block () const
 {
diff --git a/gdb/dwarf2/attribute.h b/gdb/dwarf2/attribute.h
index c2602310715..e697e6d5fc8 100644
--- a/gdb/dwarf2/attribute.h
+++ b/gdb/dwarf2/attribute.h
@@ -45,6 +45,10 @@ struct attribute
      attribute's form into account.  */
   CORE_ADDR value_as_address () const;
 
+  /* If the attribute has a string form, return the string value;
+     otherwise return NULL.  */
+  const char *value_as_string () const;
+
   /* 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.
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index d5cdd49a086..a48552a4c6e 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -18031,7 +18031,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
 	  /* Note that both forms of linkage name might appear.  We
 	     assume they will be the same, and we only store the last
 	     one we see.  */
-	  linkage_name = DW_STRING (&attr);
+	  linkage_name = attr.value_as_string ();
 	  /* rustc emits invalid values for DW_AT_linkage_name.  Ignore these.
 	     See https://github.com/rust-lang/rust/issues/32925.  */
 	  if (cu->language == language_rust && linkage_name != NULL
@@ -19200,17 +19200,8 @@ dwarf2_string_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *c
 
   if (attr != NULL)
     {
-      if (attr->form == DW_FORM_strp || attr->form == DW_FORM_line_strp
-	  || attr->form == DW_FORM_string
-	  || attr->form == DW_FORM_strx
-	  || attr->form == DW_FORM_strx1
-	  || attr->form == DW_FORM_strx2
-	  || attr->form == DW_FORM_strx3
-	  || attr->form == DW_FORM_strx4
-	  || attr->form == DW_FORM_GNU_str_index
-	  || attr->form == DW_FORM_GNU_strp_alt)
-	str = DW_STRING (attr);
-      else
+      str = attr->value_as_string ();
+      if (str == nullptr)
         complaint (_("string type expected for attribute %s for "
 		     "DIE at %s in module %s"),
 		   dwarf_attr_name (name), sect_offset_str (die->sect_off),
-- 
2.17.2


  parent reply	other threads:[~2020-03-25 20:07 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-25 20:07 [PATCH 00/10] Fix two name-related bugs in DWARF reader Tom Tromey
2020-03-25 20:07 ` [PATCH 01/10] Convert symbol_set_demangled_name to a method Tom Tromey
2020-03-25 20:07 ` [PATCH 02/10] Move the rust "{" hack Tom Tromey
2020-03-25 20:07 ` [PATCH 03/10] Fix two latent Rust bugs Tom Tromey
2020-03-25 20:07 ` Tom Tromey [this message]
2020-03-25 20:07 ` [PATCH 05/10] Introduce new add_psymbol_to_list overload Tom Tromey
2020-03-25 20:07 ` [PATCH 06/10] Use the " Tom Tromey
2020-03-25 20:07 ` [PATCH 07/10] Don't call compute_and_set_names for partial symbols Tom Tromey
2020-03-25 20:07 ` [PATCH 08/10] Use the linkage name if it exists Tom Tromey
2020-04-24 16:06   ` Tom de Vries
2020-04-24 18:09     ` Tom de Vries
2020-04-24 20:50       ` Tom Tromey
2020-04-24 21:27         ` [committed][gdb/testsuite] Fix language in dw2-bad-mips-linkage-name.exp Tom de Vries
2020-04-24 21:34           ` Tom Tromey
2020-03-25 20:07 ` [PATCH 09/10] Fix Rust test cases Tom Tromey
2020-03-25 20:07 ` [PATCH 10/10] Remove symbol_get_demangled_name Tom Tromey
2020-03-25 22:48 ` [PATCH 00/10] Fix two name-related bugs in DWARF reader Christian Biesinger
2020-03-25 23:50   ` Tom Tromey
2020-04-24 14:18 ` Tom de Vries
2020-04-24 14: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=20200325200715.12947-5-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).