From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10636 invoked by alias); 5 Dec 2005 18:29:13 -0000 Received: (qmail 10613 invoked by uid 22791); 5 Dec 2005 18:29:10 -0000 X-Spam-Check-By: sourceware.org Received: from e32.co.us.ibm.com (HELO e32.co.us.ibm.com) (32.97.110.150) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 05 Dec 2005 18:29:07 +0000 Received: from westrelay02.boulder.ibm.com (westrelay02.boulder.ibm.com [9.17.195.11]) by e32.co.us.ibm.com (8.12.11/8.12.11) with ESMTP id jB5IT4U7030146 for ; Mon, 5 Dec 2005 13:29:04 -0500 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by westrelay02.boulder.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id jB5ISQJ5071202 for ; Mon, 5 Dec 2005 11:28:26 -0700 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.12.11/8.13.3) with ESMTP id jB5IT3Uo005695 for ; Mon, 5 Dec 2005 11:29:04 -0700 Received: from dyn9047022123-009047022095.beaverton.ibm.com (dyn9047022123-009047022095.beaverton.ibm.com [9.47.22.95]) by d03av01.boulder.ibm.com (8.12.11/8.12.11) with ESMTP id jB5IT3Ud005677; Mon, 5 Dec 2005 11:29:03 -0700 From: Paul Gilliam Reply-To: pgilliam@us.ibm.com To: gdb-patches@sourceware.org Subject: Re: [PATCH] add 'rs6000_in_function_epilogue_p()' (Revised) Date: Tue, 06 Dec 2005 15:20:00 -0000 User-Agent: KMail/1.6.2 Cc: Kevin Buettner , gdb-patches@sources.redhat.com, Mark Kettenis , Daniel Jacobowitz , Jim Blandy References: <200511301225.56802.pgilliam@us.ibm.com> <200512021120.22263.pgilliam@us.ibm.com> <20051202133250.10d687bd@ironwood.lan> In-Reply-To: <20051202133250.10d687bd@ironwood.lan> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <200512051100.51617.pgilliam@us.ibm.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2005-12/txt/msg00105.txt.bz2 On Friday 02 December 2005 12:32, Kevin Buettner wrote: > On Fri, 2 Dec 2005 11:20:22 -0800 > Paul Gilliam wrote: >=20 > > * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilog= ue_p()' > > and put it into the architecture vector. >=20 > Your patch is okay to commit after you address Mark's concerns. >=20 > Kevin >=20 >=20 Kevin, I made the changes to address Mark's concerns. But because of the interest this has drawn, I thought I better ask again be= fore I commited the patch. It's not perfect and will not work under all conditions. But it doesn't make things worse and does help out in many if not most codi= tions. I just want to place this band-aid on the bug and address all the concerns = the 'right' way and CFI, etc. for later. SO, Can I Commit? -=3D# Paul #=3D-=20 2005-12-05 =A0Paul Gilliam =A0 =A0 =A0 =A0 =A0 * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_ep= ilogue_p()' =A0 =A0 =A0 =A0 and put it into the architecture vector. Index: rs6000-tdep.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v retrieving revision 1.248 diff -a -u -p -r1.248 rs6000-tdep.c --- rs6000-tdep.c =A0 =A0 =A0 1 Nov 2005 19:32:36 -0000 =A0 =A0 =A0 1.248 +++ rs6000-tdep.c =A0 =A0 =A0 2 Dec 2005 23:08:10 -0000 @@ -502,6 +502,74 @@ rs6000_skip_prologue (CORE_ADDR pc) =A0 =A0return pc; =A0} +static int +insn_changes_sp (unsigned long insn) +{ + =A0int opcode =A0=3D (insn>>26) & 0x03f; + =A0int sd =A0 =A0 =A0=3D (insn>>21) & 0x01f; + =A0int a =A0 =A0 =A0 =3D (insn>>16) & 0x01f; + =A0/* =A0b =A0 =A0 =A0 =3D (insn>>11) & 0x01f =A0*/ + =A0int subcode =3D (insn>> 1) & 0x3ff; + =A0/* =A0rc =A0 =A0 =A0=3D =A0insn =A0 =A0 =A0& 0x001 =A0*/ + + =A0if (opcode =3D=3D 31 && subcode =3D=3D 444 && a =3D=3D 1) + =A0 =A0return 1; =A0/* mr R1,Rn */ + =A0if (opcode =3D=3D 14 && sd =3D=3D 1) + =A0 =A0return 1; =A0/* addi R1,Rn,simm */ + =A0if (opcode =3D=3D 58 && sd =3D=3D 1) + =A0 =A0return 1; =A0/* ld R1,ds(Rn) */ + + =A0return 0; +} + +/* Return true if we are in the function's epilogue, i.e. after the + =A0 instruction that destroyed the function's stack frame. =A0*/ + +static int +rs6000_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + =A0bfd_byte insn_buf[PPC_INSN_SIZE]; + =A0CORE_ADDR scan_pc, func_addr, func_end; + =A0unsigned long insn; + =A0struct frame_info *fr; + + =A0/* Find the search limits. =A0*/ + =A0if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) + =A0 =A0return 0; + + =A0/* Get the current frame. =A0This may be cheap, since we might have + =A0 =A0 just called it in watchpoint_check, before calling + =A0 =A0 gdbarch_in_function_epilogue_p. =A0*/ + + =A0fr =3D get_current_frame (); + + =A0/* Scan forward untill next 'blr'. =A0*/ + =A0for (scan_pc =3D pc; scan_pc < func_end; scan_pc +=3D PPC_INSN_SIZE) + =A0 =A0{ + =A0 =A0 =A0if (!safe_frame_unwind_memory (fr, scan_pc, insn_buf, PPC_INSN= _SIZE)) + =A0 =A0 =A0 =A0return 0; + =A0 =A0 =A0insn =3D extract_signed_integer (insn_buf, PPC_INSN_SIZE); + =A0 =A0 =A0if (insn =3D=3D 0x4e800020) + =A0 =A0 =A0 =A0break; + =A0 =A0 =A0if (insn_changes_sp (insn)) + =A0 =A0 =A0 =A0return 0; + =A0 =A0} + + =A0/* Scan backward untill adjustment to stack pointer (R1). =A0*/ + =A0for (scan_pc =3D pc-PPC_INSN_SIZE; + =A0 =A0 =A0 scan_pc >=3D func_addr; + =A0 =A0 =A0 scan_pc -=3D PPC_INSN_SIZE) + =A0 =A0{ + =A0 =A0 =A0if (!safe_frame_unwind_memory (fr, scan_pc, insn_buf, PPC_INSN= _SIZE)) + =A0 =A0 =A0 =A0return 0; + =A0 =A0 =A0insn =3D extract_signed_integer (insn_buf, PPC_INSN_SIZE); + =A0 =A0 =A0if (insn_changes_sp (insn)) + =A0 =A0 =A0 =A0return 1; + =A0 =A0} + + =A0return 0; +} + =A0/* Fill in fi->saved_regs */ @@ -3342,6 +3409,8 @@ rs6000_gdbarch_init (struct gdbarch_info =A0 =A0set_gdbarch_deprecated_extract_struct_value_address (gdbarch, rs6000= _extract_struct_value_address); =A0 =A0set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue); + =A0set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilog= ue_p); + =A0 =A0set_gdbarch_inner_than (gdbarch, core_addr_lessthan); =A0 =A0set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10631 invoked by alias); 5 Dec 2005 18:29:12 -0000 Received: (qmail 10610 invoked by uid 22791); 5 Dec 2005 18:29:09 -0000 X-Spam-Check-By: sourceware.org Received: from e33.co.us.ibm.com (HELO e33.co.us.ibm.com) (32.97.110.151) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 05 Dec 2005 18:29:06 +0000 Received: from westrelay02.boulder.ibm.com (westrelay02.boulder.ibm.com [9.17.195.11]) by e33.co.us.ibm.com (8.12.11/8.12.11) with ESMTP id jB5IT444018908 for ; Mon, 5 Dec 2005 13:29:04 -0500 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by westrelay02.boulder.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id jB5ISQJ5075634 for ; Mon, 5 Dec 2005 11:28:26 -0700 Received: from d03av01.boulder.ibm.com (loopback [127.0.0.1]) by d03av01.boulder.ibm.com (8.12.11/8.13.3) with ESMTP id jB5IT3Um005695 for ; Mon, 5 Dec 2005 11:29:04 -0700 Received: from dyn9047022123-009047022095.beaverton.ibm.com (dyn9047022123-009047022095.beaverton.ibm.com [9.47.22.95]) by d03av01.boulder.ibm.com (8.12.11/8.12.11) with ESMTP id jB5IT3Ud005677; Mon, 5 Dec 2005 11:29:03 -0700 From: Paul Gilliam Reply-To: pgilliam@us.ibm.com To: gdb-patches@sourceware.org Subject: Re: [PATCH] add 'rs6000_in_function_epilogue_p()' (Revised) Date: Tue, 06 Dec 2005 15:15:00 -0000 User-Agent: KMail/1.6.2 Cc: Kevin Buettner , gdb-patches@sources.redhat.com, Mark Kettenis , Daniel Jacobowitz , Jim Blandy References: <200511301225.56802.pgilliam@us.ibm.com> <200512021120.22263.pgilliam@us.ibm.com> <20051202133250.10d687bd@ironwood.lan> In-Reply-To: <20051202133250.10d687bd@ironwood.lan> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-ID: <200512051100.51617.pgilliam@us.ibm.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2005-12/txt/msg00104.txt.bz2 Message-ID: <20051206151500.KbcYKaHv31shgDSQU2PCaeaYhhG1Bz-XpAA2RqhsU9o@z> On Friday 02 December 2005 12:32, Kevin Buettner wrote: > On Fri, 2 Dec 2005 11:20:22 -0800 > Paul Gilliam wrote: >=20 > > * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilog= ue_p()' > > and put it into the architecture vector. >=20 > Your patch is okay to commit after you address Mark's concerns. >=20 > Kevin >=20 >=20 Kevin, I made the changes to address Mark's concerns. But because of the interest this has drawn, I thought I better ask again be= fore I commited the patch. It's not perfect and will not work under all conditions. But it doesn't make things worse and does help out in many if not most codi= tions. I just want to place this band-aid on the bug and address all the concerns = the 'right' way and CFI, etc. for later. SO, Can I Commit? -=3D# Paul #=3D-=20 2005-12-05 =A0Paul Gilliam =A0 =A0 =A0 =A0 =A0 * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_ep= ilogue_p()' =A0 =A0 =A0 =A0 and put it into the architecture vector. Index: rs6000-tdep.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v retrieving revision 1.248 diff -a -u -p -r1.248 rs6000-tdep.c --- rs6000-tdep.c =A0 =A0 =A0 1 Nov 2005 19:32:36 -0000 =A0 =A0 =A0 1.248 +++ rs6000-tdep.c =A0 =A0 =A0 2 Dec 2005 23:08:10 -0000 @@ -502,6 +502,74 @@ rs6000_skip_prologue (CORE_ADDR pc) =A0 =A0return pc; =A0} +static int +insn_changes_sp (unsigned long insn) +{ + =A0int opcode =A0=3D (insn>>26) & 0x03f; + =A0int sd =A0 =A0 =A0=3D (insn>>21) & 0x01f; + =A0int a =A0 =A0 =A0 =3D (insn>>16) & 0x01f; + =A0/* =A0b =A0 =A0 =A0 =3D (insn>>11) & 0x01f =A0*/ + =A0int subcode =3D (insn>> 1) & 0x3ff; + =A0/* =A0rc =A0 =A0 =A0=3D =A0insn =A0 =A0 =A0& 0x001 =A0*/ + + =A0if (opcode =3D=3D 31 && subcode =3D=3D 444 && a =3D=3D 1) + =A0 =A0return 1; =A0/* mr R1,Rn */ + =A0if (opcode =3D=3D 14 && sd =3D=3D 1) + =A0 =A0return 1; =A0/* addi R1,Rn,simm */ + =A0if (opcode =3D=3D 58 && sd =3D=3D 1) + =A0 =A0return 1; =A0/* ld R1,ds(Rn) */ + + =A0return 0; +} + +/* Return true if we are in the function's epilogue, i.e. after the + =A0 instruction that destroyed the function's stack frame. =A0*/ + +static int +rs6000_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + =A0bfd_byte insn_buf[PPC_INSN_SIZE]; + =A0CORE_ADDR scan_pc, func_addr, func_end; + =A0unsigned long insn; + =A0struct frame_info *fr; + + =A0/* Find the search limits. =A0*/ + =A0if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) + =A0 =A0return 0; + + =A0/* Get the current frame. =A0This may be cheap, since we might have + =A0 =A0 just called it in watchpoint_check, before calling + =A0 =A0 gdbarch_in_function_epilogue_p. =A0*/ + + =A0fr =3D get_current_frame (); + + =A0/* Scan forward untill next 'blr'. =A0*/ + =A0for (scan_pc =3D pc; scan_pc < func_end; scan_pc +=3D PPC_INSN_SIZE) + =A0 =A0{ + =A0 =A0 =A0if (!safe_frame_unwind_memory (fr, scan_pc, insn_buf, PPC_INSN= _SIZE)) + =A0 =A0 =A0 =A0return 0; + =A0 =A0 =A0insn =3D extract_signed_integer (insn_buf, PPC_INSN_SIZE); + =A0 =A0 =A0if (insn =3D=3D 0x4e800020) + =A0 =A0 =A0 =A0break; + =A0 =A0 =A0if (insn_changes_sp (insn)) + =A0 =A0 =A0 =A0return 0; + =A0 =A0} + + =A0/* Scan backward untill adjustment to stack pointer (R1). =A0*/ + =A0for (scan_pc =3D pc-PPC_INSN_SIZE; + =A0 =A0 =A0 scan_pc >=3D func_addr; + =A0 =A0 =A0 scan_pc -=3D PPC_INSN_SIZE) + =A0 =A0{ + =A0 =A0 =A0if (!safe_frame_unwind_memory (fr, scan_pc, insn_buf, PPC_INSN= _SIZE)) + =A0 =A0 =A0 =A0return 0; + =A0 =A0 =A0insn =3D extract_signed_integer (insn_buf, PPC_INSN_SIZE); + =A0 =A0 =A0if (insn_changes_sp (insn)) + =A0 =A0 =A0 =A0return 1; + =A0 =A0} + + =A0return 0; +} + =A0/* Fill in fi->saved_regs */ @@ -3342,6 +3409,8 @@ rs6000_gdbarch_init (struct gdbarch_info =A0 =A0set_gdbarch_deprecated_extract_struct_value_address (gdbarch, rs6000= _extract_struct_value_address); =A0 =A0set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue); + =A0set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilog= ue_p); + =A0 =A0set_gdbarch_inner_than (gdbarch, core_addr_lessthan); =A0 =A0set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc);