From patchwork Thu Sep 27 07:42:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Metzger, Markus T" X-Patchwork-Id: 29559 Received: (qmail 129411 invoked by alias); 27 Sep 2018 07:42:44 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 129129 invoked by uid 89); 27 Sep 2018 07:42:43 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY autolearn=ham version=3.3.2 spammy=H*r:LOCAL, fname, our X-HELO: mga14.intel.com Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Sep 2018 07:42:41 +0000 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Sep 2018 00:42:40 -0700 Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga004.jf.intel.com with ESMTP; 27 Sep 2018 00:42:30 -0700 Received: from ulvlx001.iul.intel.com (ulvlx001.iul.intel.com [172.28.207.17]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w8R7gTwC009023; Thu, 27 Sep 2018 08:42:29 +0100 Received: from ulvlx001.iul.intel.com (localhost [127.0.0.1]) by ulvlx001.iul.intel.com with ESMTP id w8R7gTSJ012424; Thu, 27 Sep 2018 09:42:29 +0200 Received: (from mmetzger@localhost) by ulvlx001.iul.intel.com with LOCAL id w8R7gTfh012420; Thu, 27 Sep 2018 09:42:29 +0200 From: Markus Metzger To: gdb-patches@sourceware.org Cc: Markus Metzger Subject: [PATCH] btrace: check for indirect jump return in _Unwind_RaiseException Date: Thu, 27 Sep 2018 09:42:28 +0200 Message-Id: <1538034149-12136-1-git-send-email-markus.t.metzger@intel.com> X-IsSubscribed: yes Some versions of _Unwind_RaiseException, e.g. on Fedora 28, use an indirect jump to return to the exception handler. This messes up the output of "record function-call-history /c" since the return is interpreted as cross-function goto. It had been detected by gdb.btrace/exception.exp. Add a heuristic for "_Unwind_*" functions to interpret an indirect jump that ends in one of our caller functions as return to the first instance of that function in our call stack. Signed-off-by: Markus Metzger gdb/ * btrace.c (ftrace_update_function): Add indirect jump heuristic. --- gdb/btrace.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gdb/btrace.c b/gdb/btrace.c index e25f047ce24..d3ad0ab7de8 100644 --- a/gdb/btrace.c +++ b/gdb/btrace.c @@ -620,6 +620,20 @@ ftrace_update_function (struct btrace_thread_info *btinfo, CORE_ADDR pc) if (start == pc) return ftrace_new_tailcall (btinfo, mfun, fun); + /* Some versions of _Unwind_RaiseException use an indirect + jump to 'return' to the exception handler of the caller + handling the exception instead of a return. Let's restrict + this heuristic to that and related functions. */ + const char *fname = ftrace_print_function_name (bfun); + if (strncmp (fname, "_Unwind_", strlen ("_Unwind_")) == 0) + { + struct btrace_function *caller + = ftrace_find_call_by_number (btinfo, bfun->up); + caller = ftrace_find_caller (btinfo, caller, mfun, fun); + if (caller != NULL) + return ftrace_new_return (btinfo, mfun, fun); + } + /* If we can't determine the function for PC, we treat a jump at the end of the block as tail call if we're switching functions and as an intra-function branch if we don't. */