From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 123900 invoked by alias); 10 Apr 2018 14:23:29 -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 123451 invoked by uid 89); 10 Apr 2018 14:23:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.99.4 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.2 spammy=fde, ppc32, SPARC, cie X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS 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; Tue, 10 Apr 2018 14:23:26 +0000 Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 85B6031F8B5C; Tue, 10 Apr 2018 16:23:24 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id 451D641C66B7; Tue, 10 Apr 2018 16:23:24 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] libdwfl: Handle unwind frame when the return address register isn't set. Date: Tue, 10 Apr 2018 14:23:00 -0000 Message-Id: <1523370202-534-1-git-send-email-mark@klomp.org> X-Mailer: git-send-email 1.8.3.1 X-Spam-Flag: NO X-IsSubscribed: yes X-SW-Source: 2018-q2/txt/msg00005.txt.bz2 When we have unwound the frame and then cannot set the return address we wouldn't set any error. That meant that a dwfl_thread_getframes () call could end in an error, but without any dwfl_errno set, producing the "no error" error message. If we cannot set the return address at the end of unwinding the frame that means that either the return address register is bogus (error), or that the return address is undefined (end of the call stack). This fixes the run-backtrace-native-biarch.sh testcase for me on an i386 on x86_64 setup with gcc 7.2.1 and glibc 2.17. Signed-off-by: Mark Wielaard --- libdwfl/ChangeLog | 5 +++++ libdwfl/frame_unwind.c | 46 ++++++++++++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index 9776f1c..b6262c2 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,3 +1,8 @@ +2018-04-10 Mark Wielaard + + * frame_unwind.c (unwind): If __libdwfl_frame_reg_get fails for + the return address either set an error or mark the pc undefined. + 2018-03-17 Mark Wielaard * libdwflP.h (struct __libdwfl_remote_mem_cache): New. diff --git a/libdwfl/frame_unwind.c b/libdwfl/frame_unwind.c index eaea495..8da691e 100644 --- a/libdwfl/frame_unwind.c +++ b/libdwfl/frame_unwind.c @@ -632,24 +632,38 @@ handle_cfi (Dwfl_Frame *state, Dwarf_Addr pc, Dwarf_CFI *cfi, Dwarf_Addr bias) ra_set = true; } } - if (unwound->pc_state == DWFL_FRAME_STATE_ERROR - && __libdwfl_frame_reg_get (unwound, - frame->fde->cie->return_address_register, - &unwound->pc)) + if (unwound->pc_state == DWFL_FRAME_STATE_ERROR) { - /* PPC32 __libc_start_main properly CFI-unwinds PC as zero. Currently - none of the archs supported for unwinding have zero as a valid PC. */ - if (unwound->pc == 0) - unwound->pc_state = DWFL_FRAME_STATE_PC_UNDEFINED; + if (__libdwfl_frame_reg_get (unwound, + frame->fde->cie->return_address_register, + &unwound->pc)) + { + /* PPC32 __libc_start_main properly CFI-unwinds PC as zero. + Currently none of the archs supported for unwinding have + zero as a valid PC. */ + if (unwound->pc == 0) + unwound->pc_state = DWFL_FRAME_STATE_PC_UNDEFINED; + else + { + unwound->pc_state = DWFL_FRAME_STATE_PC_SET; + /* In SPARC the return address register actually contains + the address of the call instruction instead of the return + address. Therefore we add here an offset defined by the + backend. Most likely 0. */ + unwound->pc += ebl_ra_offset (ebl); + } + } else - { - unwound->pc_state = DWFL_FRAME_STATE_PC_SET; - /* In SPARC the return address register actually contains - the address of the call instruction instead of the return - address. Therefore we add here an offset defined by the - backend. Most likely 0. */ - unwound->pc += ebl_ra_offset (ebl); - } + { + /* We couldn't set the return register, either it was bogus, + or the return pc is undefined, maybe end of call stack. */ + unsigned pcreg = frame->fde->cie->return_address_register; + if (! ebl_dwarf_to_regno (ebl, &pcreg) + || pcreg >= ebl_frame_nregs (ebl)) + __libdwfl_seterrno (DWFL_E_INVALID_REGISTER); + else + unwound->pc_state = DWFL_FRAME_STATE_PC_UNDEFINED; + } } free (frame); } -- 1.8.3.1