public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] readelf: Print arguments to DW_OP_call2 and DW_OP_call4 as DIE offsets.
@ 2017-12-07 15:32 Mark Wielaard
  2017-12-07 21:39 ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2017-12-07 15:32 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

That makes it easier to follow the call to the actual DIE.

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

diff --git a/src/ChangeLog b/src/ChangeLog
index c56c323..364a30f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2017-12-07  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (print_ops): Print arguments to DW_OP_call2 and
+	DW_OP_call4 as DIE offsets.
+
 2017-11-21  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (attr_callback): Print attribute name and form in error
diff --git a/src/readelf.c b/src/readelf.c
index a9168d1..34e9a49 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4323,7 +4323,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 
 	case DW_OP_call2:
 	  NEED (2);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu16 "\n",
+	  printf ("%*s[%4" PRIuMAX "] %s [%6" PRIx16 "]\n",
 		  indent, "", (uintmax_t) offset, op_name,
 		  read_2ubyte_unaligned (dbg, data));
 	  CONSUME (2);
@@ -4332,7 +4332,7 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 
 	case DW_OP_call4:
 	  NEED (4);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu32 "\n",
+	  printf ("%*s[%4" PRIuMAX "] %s [%6" PRIx32 "]\n",
 		  indent, "", (uintmax_t) offset, op_name,
 		  read_4ubyte_unaligned (dbg, data));
 	  CONSUME (4);
-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] readelf: Print arguments to DW_OP_call2 and DW_OP_call4 as DIE offsets.
  2017-12-07 15:32 [PATCH] readelf: Print arguments to DW_OP_call2 and DW_OP_call4 as DIE offsets Mark Wielaard
@ 2017-12-07 21:39 ` Mark Wielaard
  2017-12-11 23:13   ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2017-12-07 21:39 UTC (permalink / raw)
  To: elfutils-devel; +Cc: tom

[-- Attachment #1: Type: text/plain, Size: 288 bytes --]

On Thu, Dec 07, 2017 at 04:32:39PM +0100, Mark Wielaard wrote:
> That makes it easier to follow the call to the actual DIE.

That only made it more clear we weren't handling DW_OP_call2/4
correctly. We were not updating the data pointer. Now includes
a somewhat interesting Ada testcase.

[-- Attachment #2: 0001-readelf-Handle-DW_OP_call2-and-DW_OP_call4-correctly.patch --]
[-- Type: text/plain, Size: 9352 bytes --]

From bbbf5f9cb84828cac051267aa8359d2df2da5787 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Thu, 7 Dec 2017 16:31:54 +0100
Subject: [PATCH] readelf: Handle DW_OP_call2 and DW_OP_call4 correctly.

DW_OP_call2 and DW_OP_call4 didn't correctly advance the data pointer.
This caused print_ops to produce garbage operands. Also format the
arguments as DIE offsets. That makes it easier to follow the call to the
actual dwarf_procedure DIE.

Testcase from https://sourceware.org/bugzilla/show_bug.cgi?id=22532

The testcase only checks the eu-readelf output is correct for the
byte_size attribute. But it might be interesting to write a full
expression parser to check the actual sizes.

 [    3e]    structure_type
             name                 (strp) "pck__rec"
             byte_size            (exprloc)
              [   0] push_object_address
              [   1] deref_size 1
              [   3] call4 [    95]
              [   8] plus_uconst 7
              [  10] const1s -4
              [  12] and

 [    95]    dwarf_procedure
             location             (exprloc)
              [   0] dup
              [   1] lit1
              [   2] ne
              [   3] bra 10
              [   6] lit4
              [   7] skip 31
              [  10] dup
              [  11] lit4
              [  12] ne
              [  13] bra 20
              [  16] lit0
              [  17] skip 31
              [  20] dup
              [  21] lit3
              [  22] eq
              [  23] bra 30
              [  26] lit0
              [  27] skip 31
              [  30] lit4
              [  31] swap
              [  32] drop

The "answer" depends on the Discr value (first byte at object address),
and is rounded up to 4 or 8 bytes.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 src/ChangeLog                  |   5 +++
 src/readelf.c                  |   6 ++-
 tests/ChangeLog                |   8 ++++
 tests/Makefile.am              |   2 +
 tests/run-readelf-variant.sh   |  89 +++++++++++++++++++++++++++++++++++++++++
 tests/testfile-ada-variant.bz2 | Bin 0 -> 1305 bytes
 6 files changed, 108 insertions(+), 2 deletions(-)
 create mode 100755 tests/run-readelf-variant.sh
 create mode 100644 tests/testfile-ada-variant.bz2

diff --git a/src/ChangeLog b/src/ChangeLog
index c56c323..3c53c5c 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2017-12-07  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (print_ops): Update data pointer and print arguments
+	to DW_OP_call2 and DW_OP_call4 as DIE offsets.
+
 2017-11-21  Mark Wielaard  <mark@klomp.org>
 
 	* readelf.c (attr_callback): Print attribute name and form in error
diff --git a/src/readelf.c b/src/readelf.c
index a9168d1..6a194ee 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -4323,19 +4323,21 @@ print_ops (Dwfl_Module *dwflmod, Dwarf *dbg, int indent, int indentrest,
 
 	case DW_OP_call2:
 	  NEED (2);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu16 "\n",
+	  printf ("%*s[%4" PRIuMAX "] %s [%6" PRIx16 "]\n",
 		  indent, "", (uintmax_t) offset, op_name,
 		  read_2ubyte_unaligned (dbg, data));
 	  CONSUME (2);
+	  data += 2;
 	  offset += 3;
 	  break;
 
 	case DW_OP_call4:
 	  NEED (4);
-	  printf ("%*s[%4" PRIuMAX "] %s %" PRIu32 "\n",
+	  printf ("%*s[%4" PRIuMAX "] %s [%6" PRIx32 "]\n",
 		  indent, "", (uintmax_t) offset, op_name,
 		  read_4ubyte_unaligned (dbg, data));
 	  CONSUME (4);
+	  data += 4;
 	  offset += 5;
 	  break;
 
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 0162034..9eb6839 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,11 @@
+2017-12-07  Mark Wielaard  <mark@klomp.org>
+
+	* run-readelf-variant.sh: New test.
+	* testfile-ada-variant.bz2: New testfile.
+	* Makefile.am (TESTS): Add run-readelf-variant.sh.
+	(EXTRA_DISTS): Add run-readelf-variant.sh and
+	testfile-ada-variant.bz2.
+
 2017-11-16  Mark Wielaard  <mark@klomp.org>
 
 	* varlocs.c (main): Fix cfi_debug => cfi_debug_bias typo in assert.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d502054..fca0072 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -110,6 +110,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
 	run-low_high_pc.sh run-macro-test.sh run-elf_cntl_gelf_getshdr.sh \
 	run-test-archive64.sh run-readelf-vmcoreinfo.sh \
 	run-readelf-mixed-corenote.sh run-dwfllines.sh \
+	run-readelf-variant.sh \
 	run-dwfl-report-elf-align.sh run-addr2line-test.sh \
 	run-addr2line-i-test.sh run-addr2line-i-lex-test.sh \
 	run-addr2line-i-demangle-test.sh run-addr2line-alt-debugpath.sh \
@@ -264,6 +265,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
 	     testfilebazdynppc64.bz2 testfilebazmdbppc64.bz2 \
 	     testfilebazminppc64.bz2 testfilebazminppc64_pl.bz2 \
 	     testfilebazminppc64_plr.bz2 testfilebaztabppc64.bz2 \
+	     run-readelf-variant.sh testfile-ada-variant.bz2 \
 	     run-dwflsyms.sh \
 	     run-unstrip-n.sh testcore-rtlib.bz2 testcore-rtlib-ppc.bz2 \
 	     run-low_high_pc.sh testfile_low_high_pc.bz2 \
diff --git a/tests/run-readelf-variant.sh b/tests/run-readelf-variant.sh
new file mode 100755
index 0000000..1a559f6
--- /dev/null
+++ b/tests/run-readelf-variant.sh
@@ -0,0 +1,89 @@
+#! /bin/sh
+# Copyright (C) 2017 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# Tests exprloc for an Ada record variants byte_size.
+
+# = pck.ads
+#
+# with System;
+#
+# package Pck is
+#
+#    type One_To_Five is range 1 .. 5;
+#
+#    type Rec (Discr : One_To_Five) is
+#    record
+#       case Discr is
+#          when 1 => Field1 : Integer;
+#          when 4 => null;
+#          when 3 => Field3 : Boolean;
+#          when 5 => null;
+#          when others => null;
+#       end case;
+#    end record;
+#
+#    procedure Do_Nothing (A : System.Address);
+#
+# end Pck;
+
+# = pck.adb
+#
+# package body Pck is
+#
+#    procedure Do_Nothing (A : System.Address) is
+#    begin
+#       null;
+#    end Do_Nothing;
+#
+# end Pck;
+
+# = foo.adb
+#
+# with Pck; use Pck;
+#
+# procedure Foo is
+#
+#    R : Rec (1);
+#
+# begin
+#    Do_Nothing (R'Address);
+# end Foo;
+
+# gnatmake -g -fgnat-encodings=minimal foo.adb -cargs
+
+testfiles testfile-ada-variant
+
+tempfiles testfile.temp testfile2.temp
+
+testrun ${abs_top_builddir}/src/readelf --debug-dump=info \
+        testfile-ada-variant > testfile.temp
+
+grep -A6 byte_size testfile.temp | grep -A6 exprloc > testfile2.temp
+
+diff -u testfile2.temp - <<EOF
+             byte_size            (exprloc) 
+              [   0] push_object_address
+              [   1] deref_size 1
+              [   3] call4 [    95]
+              [   8] plus_uconst 7
+              [  10] const1s -4
+              [  12] and
+EOF
+
+exit 0
diff --git a/tests/testfile-ada-variant.bz2 b/tests/testfile-ada-variant.bz2
new file mode 100644
index 0000000000000000000000000000000000000000..459774d6effdd5fbe94eaada613e7031002366c6
GIT binary patch
literal 1305
zcmV+!1?KufT4*^jL0KkKS;~eaZ~z2&|NsC0|Nd`h|NH;tR>1%7-}ud9XYI&DKuwsS
z1V{!%EKJY@8W)ArL%6n~hNgrPdMA>bC_Oa{o}m3n<vm88qa)f)OeUHG2+8Qw$kC^$
z05sD>8VEc!PfawQ(t}7QMvW5)(?JQe)Ha~dXwWvJ(f|Mr000000B8UM)B%YJ4F;+D
zrpjp3Oqn$DOn?|eK+pptMt}_(02vwsMj@ay13)0eVHper!7?#0Oad4Hi~%s1nix$C
zm?4B=7$KpPBPIbNl&7ia&=b_tCPN{nnl!-}jGAQAL6b&|nrOi?GzLtA00_u588l%u
z0IZ)j6ENXd?}Vb8GWvcZ5EI22;hgEI?t9pMF70eBY~`(J+MFTIyU23u^6R=c-wwMq
z8kQi7j#xEhbfY^ZHHl)ns!+D<RHs5aYlacPPa~VrKvbj=?8+8mRL*wZ-yrQjBQ#M+
zG8hLznL4O(a7EBjasZV*q@6eL@0fD~pBa0R36;y%Kznm#?NE0fW0ZARnnucq2NZ{q
zAOWC2BH}v<F{hD?U}wEQ9|N=N*ns-3<vwF71FCV5h!*<S+|-#-X(OB*K~03j5IKlN
zrGjuF{T2Yh3$qCwd2%VwLxWLJa4I4K-!)Fe7wi&O%?V7jpw;sN3`w+<+at7;t3o5N
zjKl>KQjH5iq@+3~6-)_8Lgz{WkkB0lAd1kvO#vCC1V$v<2GRz}v4|kjSYt^LV37$V
z0W|p>_W`+8$crWBlQLW8^>oHpRP%i^#W7--G9tWThPYaH&bk(?jDEC%!U3i%XTH~V
zzH9-46zU~0j0Ln2fC(#<270{3ymWSnjB0#r1<-xHOKb>ZOpQ*#`m@92_T4y&NJLgo
zYByt|bSMFwiPU~^q<I|*dOCoIkYlrI^nj5j$WF8<tV(5oU8gle1W9tGvHy14@QldO
z<l-Sh6>D5)#Az;Y@vyi+N`o^KDw3OM5ONO3V<>|%5}-xA<`7T`0#J4(R}eB){fc5Y
z$c%s~28bY11W#K`HZ&3PPLZhPKxd#O9lW{xOqc-?21GNHe;P;%=~%c}KoIw^aNe-Z
zb^>v=eM!vn^+Ke|&ujg2sER=VL7w6|t7BU~``Ud13;~$7+-;$=m0ERH(T)<PSocsI
zMy_;E4KT=6&}1UaJAu_IAN7h`v_j<}FyqX^C!)ht0CfP%%PuTHRwEd|3C~NnXwE_P
zJfvV68YZ(i7rmkJ;t2w9uKMz;w&G7fnj2YAsh})Nm8p<obL>(z=zxO@mC(gYftM&k
zNFt%-Q!mQeP^;J#SQ&S3pa+zrB=cfJ9XDW^7-fFQ-9=+D7A5FbR`CHbVD?vH>{~oJ
z=F!Mby={&02sp%$vMEu;n4av>gEbXMj13oIj3Kl%*@tVnAfI;{g^33B(4zoi6(W{5
zC4$Flq7KXz34}^KLG)ZjaCPm41saGz!a*R4{e!CPod~lC;a8{f;U5aH{oGtuZOHg#
z5n@)JnbsK6D=?8@F!iQ!`fHN<l}@+}Wmkd_6k%bhMCy#h8YGPdcKU%^swSulVEinV
z=)?jt5jEF>Cqbr_Zn~;<6IDVzY|#N+Q;K)oQeHrFIRJ2-qLB%skW|62mx9g`qbb~T
z;-kZ9C`kids=wvj%hsG=Yo<CII#5W(OZm!6kd$xI2>TLB*x@e+kT=zu8EY|7X^)UJ
P@&6ZcML1B9%7!Fx;HpJf

literal 0
HcmV?d00001

-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] readelf: Print arguments to DW_OP_call2 and DW_OP_call4 as DIE offsets.
  2017-12-07 21:39 ` Mark Wielaard
@ 2017-12-11 23:13   ` Mark Wielaard
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Wielaard @ 2017-12-11 23:13 UTC (permalink / raw)
  To: elfutils-devel; +Cc: tom

On Thu, 2017-12-07 at 22:39 +0100, Mark Wielaard wrote:
> DW_OP_call2 and DW_OP_call4 didn't correctly advance the data pointer.
> This caused print_ops to produce garbage operands. Also format the
> arguments as DIE offsets. That makes it easier to follow the call to
> the actual dwarf_procedure DIE.

Pushed to master.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-11 23:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-07 15:32 [PATCH] readelf: Print arguments to DW_OP_call2 and DW_OP_call4 as DIE offsets Mark Wielaard
2017-12-07 21:39 ` Mark Wielaard
2017-12-11 23:13   ` Mark Wielaard

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).