From patchwork Mon Aug 29 13:08:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 112043 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 8F1F2B6F9A for ; Mon, 29 Aug 2011 23:08:27 +1000 (EST) Received: (qmail 30433 invoked by alias); 29 Aug 2011 13:08:24 -0000 Received: (qmail 30001 invoked by uid 22791); 29 Aug 2011 13:08:23 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 29 Aug 2011 13:08:06 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 076662BB14A; Mon, 29 Aug 2011 09:08:06 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id PKUj-4EmFK7q; Mon, 29 Aug 2011 09:08:05 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id D8CC92BB12F; Mon, 29 Aug 2011 09:08:05 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id D7A6792A55; Mon, 29 Aug 2011 09:08:05 -0400 (EDT) Date: Mon, 29 Aug 2011 09:08:05 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Tristan Gingold Subject: [Ada] Factorize code in raise-gcc.c Message-ID: <20110829130805.GA1814@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) 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 No functional change. Tested on x86_64-pc-linux-gnu, committed on trunk 2011-08-29 Tristan Gingold * raise-gcc.c (get_ip_from_context): New function. Factorize code. Index: raise-gcc.c =================================================================== --- raise-gcc.c (revision 178204) +++ raise-gcc.c (working copy) @@ -130,7 +130,7 @@ typedef struct { _Unwind_Action phase; - char * description; + const char * description; } phase_descriptor; static const phase_descriptor phase_descriptors[] @@ -511,8 +511,11 @@ } region_descriptor; -static void -db_region_for (region_descriptor *region, _Unwind_Context *uw_context) +/* Extract and adjust the IP (instruction pointer) from an exception + context. */ + +static _Unwind_Ptr +get_ip_from_context (_Unwind_Context *uw_context) { int ip_before_insn = 0; #ifdef HAVE_GETIPINFO @@ -520,12 +523,26 @@ #else _Unwind_Ptr ip = _Unwind_GetIP (uw_context); #endif + /* Subtract 1 if necessary because GetIPInfo yields a call return address + in this case, while we are interested in information for the call point. + This does not always yield the exact call instruction address but always + brings the IP back within the corresponding region. */ if (!ip_before_insn) ip--; + return ip; +} + +static void +db_region_for (region_descriptor *region, _Unwind_Context *uw_context) +{ + _Unwind_Ptr ip; + if (! (db_accepted_codes () & DB_REGIONS)) return; + ip = get_ip_from_context (uw_context); + db (DB_REGIONS, "For ip @ 0x%08x => ", ip); if (region->lsda) @@ -651,14 +668,7 @@ static void db_action_for (action_descriptor *action, _Unwind_Context *uw_context) { - int ip_before_insn = 0; -#ifdef HAVE_GETIPINFO - _Unwind_Ptr ip = _Unwind_GetIPInfo (uw_context, &ip_before_insn); -#else - _Unwind_Ptr ip = _Unwind_GetIP (uw_context); -#endif - if (!ip_before_insn) - ip--; + _Unwind_Ptr ip = get_ip_from_context (uw_context); db (DB_ACTIONS, "For ip @ 0x%08x => ", ip); @@ -706,16 +716,7 @@ region_descriptor *region, action_descriptor *action) { - int ip_before_insn = 0; -#ifdef HAVE_GETIPINFO - _Unwind_Ptr call_site = _Unwind_GetIPInfo (uw_context, &ip_before_insn); -#else - _Unwind_Ptr call_site = _Unwind_GetIP (uw_context); -#endif - /* Subtract 1 if necessary because GetIPInfo returns the actual call site - value + 1 in this case. */ - if (!ip_before_insn) - call_site--; + _Unwind_Ptr call_site = get_ip_from_context (uw_context); /* call_site is a direct index into the call-site table, with two special values : -1 for no-action and 0 for "terminate". The latter should never @@ -772,18 +773,7 @@ action_descriptor *action) { const unsigned char *p = region->call_site_table; - int ip_before_insn = 0; -#ifdef HAVE_GETIPINFO - _Unwind_Ptr ip = _Unwind_GetIPInfo (uw_context, &ip_before_insn); -#else - _Unwind_Ptr ip = _Unwind_GetIP (uw_context); -#endif - /* Subtract 1 if necessary because GetIPInfo yields a call return address - in this case, while we are interested in information for the call point. - This does not always yield the exact call instruction address but always - brings the IP back within the corresponding region. */ - if (!ip_before_insn) - ip--; + _Unwind_Ptr ip = get_ip_from_context (uw_context); /* Unless we are able to determine otherwise... */ action->kind = nothing;