From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 93392 invoked by alias); 7 Dec 2017 21:39:09 -0000 Mailing-List: contact elfutils-devel-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Post: List-Help: List-Subscribe: Sender: elfutils-devel-owner@sourceware.org Received: (qmail 93378 invoked by uid 89); 7 Dec 2017 21:39:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.2 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT autolearn=ham version=3.3.2 spammy=kids, H*M:stream, arl, H*f:sk:1512660 X-Spam-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,KAM_SHORT autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: gnu.wildebeest.org Received: from wildebeest.demon.nl (HELO gnu.wildebeest.org) (212.238.236.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Dec 2017 21:39:06 +0000 Received: from stream.wildebeest.org (deer0x13.wildebeest.org [172.31.17.149]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id B4A6532B90E0; Thu, 7 Dec 2017 22:39:03 +0100 (CET) Received: by stream.wildebeest.org (Postfix, from userid 1000) id 60FB1106F95; Thu, 7 Dec 2017 22:39:05 +0100 (CET) Date: Thu, 07 Dec 2017 21:39:00 -0000 From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: tom@tromey.com Subject: Re: [PATCH] readelf: Print arguments to DW_OP_call2 and DW_OP_call4 as DIE offsets. Message-ID: <20171207213905.GA12145@stream> References: <1512660759-4911-1-git-send-email-mark@klomp.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="TB36FDmn/VVEgNH/" Content-Disposition: inline In-Reply-To: <1512660759-4911-1-git-send-email-mark@klomp.org> User-Agent: Mutt/1.9.1 (2017-09-22) X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2017-q4/txt/msg00088.txt.bz2 --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 288 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. --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-readelf-Handle-DW_OP_call2-and-DW_OP_call4-correctly.patch" Content-length: 9353 >From bbbf5f9cb84828cac051267aa8359d2df2da5787 Mon Sep 17 00:00:00 2001 From: Mark Wielaard 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 --- 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 + + * 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 * 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 + + * 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 * 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 . + +. $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 - <1%7-}ud9XYI&DKuwsS z1V{!%EKJY@8W)ArL%6n~hNgrPdMA>bC_Oa{o}m3n8VEc!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!+DKQjH5iq@+3~6-)_8Lgz{WkkB0lAd1kvO#vCC1V$v<2GRz}v4|kjSY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