From patchwork Fri Dec 2 18:35:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 128932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 662FCB6F64 for ; Sat, 3 Dec 2011 05:36:22 +1100 (EST) Received: (qmail 6611 invoked by alias); 2 Dec 2011 18:36:20 -0000 Received: (qmail 6336 invoked by uid 22791); 2 Dec 2011 18:36:19 -0000 X-SWARE-Spam-Status: No, hits=-7.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 02 Dec 2011 18:36:03 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pB2Ia0xC017741 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 2 Dec 2011 13:36:00 -0500 Received: from psique (ovpn-112-33.phx2.redhat.com [10.3.112.33]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id pB2IZrxO032212; Fri, 2 Dec 2011 13:35:55 -0500 From: Sergio Durigan Junior To: Ramana Radhakrishnan Cc: gcc-patches@gcc.gnu.org, Tom Tromey , Bernd Schmidt Subject: Re: [PATCH] Implement stap probe on ARM's unwinder References: Date: Fri, 02 Dec 2011 16:35:53 -0200 In-Reply-To: (Ramana Radhakrishnan's message of "Thu, 1 Dec 2011 12:01:21 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Ramana Radhakrishnan writes: > Sergio: Other than a few minor tweaks to the Changelog it largely > looks obvious to me. Hello Ramana, Thanks for the review. Here is the updated version of the patch. I asked Tom Tromey to commit it for me, since I don't have write permission on the repository. Thank you again, Sergio. diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index e7f18e2..0901cae 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,14 @@ +2011-12-02 Sergio Durigan Junior + + * unwind-arm-common.inc: Include `tconfig.h', `tsystem.h' and + `sys/sdt.h'. + (_Unwind_DebugHook): New function. + (uw_restore_core_regs): New define. + (unwind_phase2): Use uw_restore_core_regs instead of + restore_core_regs. + (unwind_phase2_forced): Likewise. + (__gnu_Unwind_Resume): Likewise. + 2011-11-30 John David Anglin PR other/51272 diff --git a/libgcc/unwind-arm-common.inc b/libgcc/unwind-arm-common.inc index 0713056..bf16902 100644 --- a/libgcc/unwind-arm-common.inc +++ b/libgcc/unwind-arm-common.inc @@ -21,8 +21,15 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ +#include "tconfig.h" +#include "tsystem.h" #include "unwind.h" +/* Used for SystemTap unwinder probe. */ +#ifdef HAVE_SYS_SDT_H +#include +#endif + /* We add a prototype for abort here to avoid creating a dependency on target headers. */ extern void abort (void); @@ -105,6 +112,44 @@ static inline _uw selfrel_offset31 (const _uw *p); static _uw __gnu_unwind_get_pr_addr (int idx); +static void _Unwind_DebugHook (void *, void *) + __attribute__ ((__noinline__, __used__, __noclone__)); + +/* This function is called during unwinding. It is intended as a hook + for a debugger to intercept exceptions. CFA is the CFA of the + target frame. HANDLER is the PC to which control will be + transferred. */ + +static void +_Unwind_DebugHook (void *cfa __attribute__ ((__unused__)), + void *handler __attribute__ ((__unused__))) +{ + /* We only want to use stap probes starting with v3. Earlier + versions added too much startup cost. */ +#if defined (HAVE_SYS_SDT_H) && defined (STAP_PROBE2) && _SDT_NOTE_TYPE >= 3 + STAP_PROBE2 (libgcc, unwind, cfa, handler); +#else + asm (""); +#endif +} + +/* This is a wrapper to be called when we need to restore core registers. + It will call `_Unwind_DebugHook' before restoring the registers, thus + making it possible to intercept and debug exceptions. + + When calling `_Unwind_DebugHook', the first argument (the CFA) is zero + because we are not interested in it. However, it must be there (even + being zero) because GDB expects to find it when using the probe. */ + +#define uw_restore_core_regs(TARGET, CORE) \ + do \ + { \ + void *handler = __builtin_frob_return_addr ((void *) VRS_PC (TARGET)); \ + _Unwind_DebugHook (0, handler); \ + restore_core_regs (CORE); \ + } \ + while (0) + /* Perform a binary search for RETURN_ADDRESS in TABLE. The table contains NREC entries. */ @@ -253,8 +298,8 @@ unwind_phase2 (_Unwind_Control_Block * ucbp, phase2_vrs * vrs) if (pr_result != _URC_INSTALL_CONTEXT) abort(); - - restore_core_regs (&vrs->core); + + uw_restore_core_regs (vrs, &vrs->core); } /* Perform phase2 forced unwinding. */ @@ -339,7 +384,7 @@ unwind_phase2_forced (_Unwind_Control_Block *ucbp, phase2_vrs *entry_vrs, return _URC_FAILURE; } - restore_core_regs (&saved_vrs.core); + uw_restore_core_regs (&saved_vrs, &saved_vrs.core); } /* This is a very limited implementation of _Unwind_GetCFA. It returns @@ -450,7 +495,7 @@ __gnu_Unwind_Resume (_Unwind_Control_Block * ucbp, phase2_vrs * entry_vrs) { case _URC_INSTALL_CONTEXT: /* Upload the registers to enter the landing pad. */ - restore_core_regs (&entry_vrs->core); + uw_restore_core_regs (entry_vrs, &entry_vrs->core); case _URC_CONTINUE_UNWIND: /* Continue unwinding the next frame. */