public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: elfutils-devel@sourceware.org
Cc: Mark Wielaard <mark@klomp.org>
Subject: [PATCH] libdw: Add support for DWARF5 DW_FORM_data16.
Date: Fri, 09 Feb 2018 20:58:00 -0000	[thread overview]
Message-ID: <1518209921-30243-1-git-send-email-mark@klomp.org> (raw)

The DWARF5 spec says DW_FORM_data16 is constant class (128bit value).
But we treat it as if it is block class. So to use a attribute that is
encoded as DW_FORM_data16 use dwarf_formblock, not dwarf_form[us]data.

We cannot use dwarf_form[us]data since they return a Dwarf_Word/Sword,
which are only 64bits.

This does mean we don't try to convert the value but just return it as
a block of 16 raw bytes.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 libdw/ChangeLog         |  5 +++++
 libdw/dwarf_formblock.c | 12 +++++++++++-
 src/ChangeLog           |  4 ++++
 src/readelf.c           |  3 ++-
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index f52ce58..3841d56 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,5 +1,10 @@
 2018-02-09  Mark Wielaard  <mark@klomp.org>
 
+	* dwarf_formblock.c (dwarf_formblock): Handle DW_FORM_data16 as a
+	16 byte block.
+
+2018-02-09  Mark Wielaard  <mark@klomp.org>
+
 	* dwarf_child.c (__libdw_find_attr): Handle DW_FORM_implicit_const.
 	* dwarf_formsdata.c (dwarf_formsdata): Likewise.
 	* dwarf_formudata.c (dwarf_formudata): Likewise.
diff --git a/libdw/dwarf_formblock.c b/libdw/dwarf_formblock.c
index 13f9e72..924baf4 100644
--- a/libdw/dwarf_formblock.c
+++ b/libdw/dwarf_formblock.c
@@ -1,5 +1,5 @@
 /* Return block represented by attribute.
-   Copyright (C) 2004-2010, 2014 Red Hat, Inc.
+   Copyright (C) 2004-2010, 2014, 2018 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2004.
 
@@ -75,6 +75,16 @@ dwarf_formblock (Dwarf_Attribute *attr, Dwarf_Block *return_block)
       return_block->data = (unsigned char *) datap;
       break;
 
+    case DW_FORM_data16:
+      /* The DWARFv5 spec calls this constant class, but we interpret
+	 it as a block that the user will need to interpret when
+	 converting to a value.  */
+      if (unlikely (endp - datap < 16))
+	goto invalid;
+      return_block->length = 16;
+      return_block->data = (unsigned char *) datap;
+      break;
+
     default:
       __libdw_seterrno (DWARF_E_NO_BLOCK);
       return -1;
diff --git a/src/ChangeLog b/src/ChangeLog
index ebd6f55..26f3938 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,9 @@
 2018-02-09  Mark Wielaard  <mark@klomp.org>
 
+	* readelf.c (attr_callback): Handle DW_FORM_data16 as Dwarf_Block.
+
+2018-02-09  Mark Wielaard  <mark@klomp.org>
+
 	* readelf.c (print_debug_abbrev_section): Print the value of a
 	DW_FORM_implicit_const using dwarf_getabbrevattr_data.
 	(attr_callback): Handle DW_FORM_implicit_const.
diff --git a/src/readelf.c b/src/readelf.c
index c57d7fe..af20175 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -6083,7 +6083,7 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
     case DW_FORM_implicit_const:
     case DW_FORM_udata:
     case DW_FORM_sdata:
-    case DW_FORM_data8:
+    case DW_FORM_data8: /* Note no data16 here, we see that as block. */
     case DW_FORM_data4:
     case DW_FORM_data2:
     case DW_FORM_data1:;
@@ -6276,6 +6276,7 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
     case DW_FORM_block2:
     case DW_FORM_block1:
     case DW_FORM_block:
+    case DW_FORM_data16: /* DWARF5 calls this a constant class.  */
       if (cbargs->silent)
 	break;
       Dwarf_Block block;
-- 
1.8.3.1

             reply	other threads:[~2018-02-09 20:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-09 20:58 Mark Wielaard [this message]
2018-02-21 16:23 ` Mark Wielaard

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=1518209921-30243-1-git-send-email-mark@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@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).