Bug 26847 - readelf -wi should print DWARF forms
Summary: readelf -wi should print DWARF forms
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-05 19:15 UTC by Tom Tromey
Modified: 2020-11-09 10:39 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Proposed patch (1.04 KB, patch)
2020-11-06 10:47 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Tromey 2020-11-05 19:15:29 UTC
When examining DWARF, it is sometimes useful to see the
DWARF form for attributes.  It would be handy if readelf
and objdump could display this.

Note that eu-readelf does:

 [    2e]    variable             abbrev: 2
             name                 (strp) "ada_main__gnat_argc"

The "(strp)" indicates the form.
Comment 1 Nick Clifton 2020-11-06 10:47:20 UTC
Created attachment 12943 [details]
Proposed patch

Hi Tom,

  Something like this patch ?

  With it applied the output looks like this:

  [...]
 <0><b>: Abbrev Number: 2 (DW_TAG_partial_unit)
    <c>   DW_AT_stmt_list   : (sec_offset) 0x0
    <10>   DW_AT_comp_dir    : (strp) (offset: 0x4a2146): /usr/src/debug/gcc-10.2.1-6.fc32.x86_64/obj-x86_64-redhat-linux/x86_64-r
edhat-linux/libgcc
 <1><14>: Abbrev Number: 111 (DW_TAG_base_type)
    <15>   DW_AT_byte_size   : (data1) 4
    <16>   DW_AT_encoding    : (data1) 5	(signed)
   [...]

   There is one caveat with this patch: the form name is only displayed when --wide is enabled.  This meant that I did not have to fix up all the binutils tests that run regexps over readelf's output, and it seemed to me to be a reasonable compromise.

Cheers
  Nick
Comment 2 Tom Tromey 2020-11-06 17:52:26 UTC
I didn't try it, but it looks like exactly what I'd like :)
Thank you!
Comment 3 Sourceware Commits 2020-11-09 10:38:37 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=521d4b194f89ca8f7d5d3cce1ecdc4fc7559205c

commit 521d4b194f89ca8f7d5d3cce1ecdc4fc7559205c
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Nov 9 10:37:51 2020 +0000

    Extend the DWARF decoder to display FORM names when operating in wide mode.
    
            PR 26847
            * dwarf.c (read_and_display_attr_value): In wide mode, display the
            name of the form.
Comment 4 Nick Clifton 2020-11-09 10:39:09 UTC
Okey dokey - patch applied.