From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24248 invoked by alias); 16 Oct 2013 14:16:21 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 24235 invoked by uid 89); 16 Oct 2013 14:16:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 16 Oct 2013 14:16:19 +0000 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r9GEGFRi021518 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 16 Oct 2013 14:16:17 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r9GEGEOR010936 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 16 Oct 2013 14:16:15 GMT Received: from abhmt113.oracle.com (abhmt113.oracle.com [141.146.116.65]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r9GEGEqt018772 for ; Wed, 16 Oct 2013 14:16:14 GMT Received: from termi.oracle.com (/10.175.50.250) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 16 Oct 2013 07:16:13 -0700 From: jose.marchesi@oracle.com (Jose E. Marchesi) To: gdb-patches@sourceware.org Subject: [PATCH] add gdbarch_in_function_epilogue_p hook for sparc64 Date: Wed, 16 Oct 2013 14:16:00 -0000 Message-ID: <87mwm9b8pr.fsf@oracle.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00485.txt.bz2 Hi. watchpoint_update and watchpoint_cond avoid checking for watchpoints when we are located at a function epilogue in the current frame. This is done in order to avoid using corrupted local registers and unwinding a corrupted/destroyed stack. The code determining whether we are in a function epilogue is provided by the backends via the gdbarch_in_function_epilogue_p hook. The patch below adds such a hook for sparc. Note that despite sparc_in_function_epilogue_p must work on both sparc32 and sparc64 the patch only installs the hook on sparc64 targets. This is because I can't test it in sparc32. This patch makes all the tests on watch-cond.exp to pass on sparc64-unknown-linux-gnu. 2013-10-16 Jose E. Marchesi * sparc-tdep.c (sparc_in_function_epilogue_p): New function. (X_RETTURN): New macro. * sparc-tdep.h: sparc_in_function_epilogue_p prototype. * sparc64-tdep.c (sparc64_init_abi): Hook sparc_in_function_epilogue_p. Index: sparc-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/sparc-tdep.c,v retrieving revision 1.233 diff -u -r1.233 sparc-tdep.c --- sparc-tdep.c 24 Jun 2013 22:18:32 -0000 1.233 +++ sparc-tdep.c 16 Oct 2013 14:00:49 -0000 @@ -88,6 +88,8 @@ #define X_DISP19(i) ((((i) & 0x7ffff) ^ 0x40000) - 0x40000) #define X_DISP10(i) ((((((i) >> 11) && 0x300) | (((i) >> 5) & 0xff)) ^ 0x200) - 0x200) #define X_SIMM13(i) ((((i) & 0x1fff) ^ 0x1000) - 0x1000) +/* Macros to identify some instructions. */ +#define X_RETTURN(i) ((X_OP (i) == 0x2) && (X_OP3 (i) == 0x39)) /* Fetch the instruction at PC. Instructions are always big-endian even if the processor operates in little-endian mode. */ @@ -421,6 +434,29 @@ regcache_raw_write (regcache, regnum + 1, buf + 4); } +/* Return true if we are in a function's epilogue, i.e. after an + instruction that destroyed a function's stack frame. */ + +int +sparc_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + /* This function must return true if we are one instruction after an + instruction that destroyed the stack frame of the current + function. The SPARC instructions used to restore the callers + stack frame are RESTORE and RETURN/RETT. + + Of these RETURN/RETT is a branch instruction and thus we return + true if we are in its delay slot. + + RESTORE is almost always found in the delay slot of a branch + instruction that transfer control to the caller, such as JMPL. + Thus the next instruction is in the caller frame and we don't + need to do anything about it. */ + + unsigned int insn = sparc_fetch_instruction (pc - 4); + return X_RETTURN (insn); +} + static CORE_ADDR sparc32_frame_align (struct gdbarch *gdbarch, CORE_ADDR address) Index: sparc-tdep.h =================================================================== RCS file: /cvs/src/src/gdb/sparc-tdep.h,v retrieving revision 1.33 diff -u -r1.33 sparc-tdep.h --- sparc-tdep.h 1 Jan 2013 06:32:51 -0000 1.33 +++ sparc-tdep.h 16 Oct 2013 14:00:49 -0000 @@ -193,6 +193,9 @@ extern struct sparc_frame_cache * sparc32_frame_cache (struct frame_info *this_frame, void **this_cache); +extern int +sparc_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc); + extern int sparc_software_single_step (struct frame_info *frame); Index: sparc64-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/sparc64-tdep.c,v retrieving revision 1.62 diff -u -r1.62 sparc64-tdep.c --- sparc64-tdep.c 1 Jan 2013 06:32:51 -0000 1.62 +++ sparc64-tdep.c 16 Oct 2013 14:00:49 -0000 @@ -1197,6 +1198,9 @@ set_gdbarch_skip_prologue (gdbarch, sparc64_skip_prologue); + /* Detect whether PC is in function epilogue. */ + set_gdbarch_in_function_epilogue_p (gdbarch, sparc_in_function_epilogue_p); + /* Hook in the DWARF CFI frame unwinder. */ dwarf2_frame_set_init_reg (gdbarch, sparc64_dwarf2_frame_init_reg); /* FIXME: kettenis/20050423: Don't enable the unwinder until the