From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24165 invoked by alias); 17 Jan 2006 03:46:29 -0000 Received: (qmail 24157 invoked by uid 22791); 17 Jan 2006 03:46:28 -0000 X-Spam-Check-By: sourceware.org Received: from yosemite.airs.com (HELO yosemite.airs.com) (205.217.158.180) by sourceware.org (qpsmtpd/0.31) with SMTP; Tue, 17 Jan 2006 03:46:25 +0000 Received: (qmail 7304 invoked from network); 17 Jan 2006 02:46:24 -0000 Received: from e33.co.us.ibm.com (32.97.110.151) by yosemite.airs.com with SMTP; 17 Jan 2006 02:46:24 -0000 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e33.co.us.ibm.com (8.12.11/8.12.11) with ESMTP id k0H2jsvM015554 for ; Mon, 16 Jan 2006 21:45:54 -0500 Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by d03relay04.boulder.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id k0H2m2wL101160 for ; Mon, 16 Jan 2006 19:48:02 -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 k0H2jrpY003156 for ; Mon, 16 Jan 2006 19:45:54 -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 k0H2jrst003136; Mon, 16 Jan 2006 19:45:53 -0700 From: Paul Gilliam Reply-To: pgilliam@us.ibm.com To: Mark Kettenis Subject: Re: [PATCH] add 'rs6000_in_function_epilogue_p()' (Revised) Date: Tue, 17 Jan 2006 03:46:00 -0000 User-Agent: KMail/1.6.2 Cc: gdb-patches@sourceware.org, kevinb@redhat.com References: <200511301225.56802.pgilliam@us.ibm.com> <200601121623.15363.pgilliam@us.ibm.com> <200601132105.k0DL5ZcF011764@elgar.sibelius.xs4all.nl> In-Reply-To: <200601132105.k0DL5ZcF011764@elgar.sibelius.xs4all.nl> MIME-Version: 1.0 Content-Disposition: inline Content-Type: Multipart/Mixed; boundary="Boundary-00=_qFGzDDhs5oqznk3" Message-Id: <200601161915.54240.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: 2006-01/txt/msg00206.txt.bz2 --Boundary-00=_qFGzDDhs5oqznk3 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Content-length: 1726 Mark, I have made the modifications you asked for. I would have committed the patch, but I wanted to give you a chance to see if my new variable name was ok: fr became curfrm. It's still a little criptic, but I was trying to avoid making the condition of an 'if' statement be on two lines. OK to commit? I am also concerned about this: > [ Bleah, I'd really wish people stopped sending MIME mail, especially > with that stupid quoted-printable encoding. I hate editing out all > those gratuitous equal signs. ] > > > 2006-01-11 Paul Gilliam > > > > * ppc-tdep.h: Add a define for the hard limit used when scanning an > > epilogue. > > * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilogue_p()' > > and put it into the architecture vector. > > It's probably your stupid mailer that converts tabs into spaces or > something, but please make sure the indentation of your Changelog > entry is ok. > The mailer I am using is 'kmail'. Here is what I get if I say 'kmail -v': Qt: 3.3.1 KDE: 3.2.1 KMail: 1.6.2 I viewed the source of my previous message and I have to agree: Bleah!! What mailer whould you suggest? What mailer do you use? In the Settings, I see I have a choice between "Allow 8-bit" or "MIME Compliant (Quoted Printable)". For this message I used "Allow 8-bit". I hope this does a better job. If not, I'll have to change mailers. I thought MIME was the standard though. Is that not the case? Also, the attachment on my previous message claims to be "text/x-diff". I changed this one to "text/plain". Did that make any difference for you? I really appreciate your help in getting all this stuff 'right'. -=# Paul #=- --Boundary-00=_qFGzDDhs5oqznk3 Content-Type: text/plain; charset="utf-8"; name="watch-locals.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="watch-locals.patch" Content-length: 4912 2006-01-16 Paul Gilliam * ppc-tdep.h (PPC_MAX_EPILOGUE_INSTRUCTIONS): New define. * rs6000-tdep.c (insn_changes_sp_or_jumps) (rs6000_in_function_epilogue_p): New functions. (rs6000_gdbarch_init): Set in_function_epilogue_p. Index: ppc-tdep.h =================================================================== RCS file: /cvs/src/src/gdb/ppc-tdep.h,v retrieving revision 1.48 diff -a -u -r1.48 ppc-tdep.h --- ppc-tdep.h 28 Oct 2005 18:23:32 -0000 1.48 +++ ppc-tdep.h 17 Jan 2006 02:14:16 -0000 @@ -384,4 +384,7 @@ /* Instruction size. */ #define PPC_INSN_SIZE 4 +/* Estimate for the maximum number of instrctions in a function epilogue. */ +#define PPC_MAX_EPILOGUE_INSTRUCTIONS 52 + #endif /* ppc-tdep.h */ Index: rs6000-tdep.c =================================================================== RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v retrieving revision 1.248 diff -a -u -r1.248 rs6000-tdep.c --- rs6000-tdep.c 1 Nov 2005 19:32:36 -0000 1.248 +++ rs6000-tdep.c 17 Jan 2006 02:14:21 -0000 @@ -502,6 +502,108 @@ return pc; } +static int +insn_changes_sp_or_jumps (unsigned long insn) +{ + int opcode = (insn >> 26) & 0x03f; + int sd = (insn >> 21) & 0x01f; + int a = (insn >> 16) & 0x01f; + int subcode = (insn >> 1) & 0x3ff; + + /* Changes the stack pointer. */ + + /* NOTE: There are many ways to change the value of a given register. + The ways below are those used when the register is R1, the SP, + in a funtion's epilogue. */ + + if (opcode == 31 && subcode == 444 && a == 1) + return 1; /* mr R1,Rn */ + if (opcode == 14 && sd == 1) + return 1; /* addi R1,Rn,simm */ + if (opcode == 58 && sd == 1) + return 1; /* ld R1,ds(Rn) */ + + /* Transfers control. */ + + if (opcode == 18) + return 1; /* b */ + if (opcode == 16) + return 1; /* bc */ + if (opcode == 19 && subcode == 16) + return 1; /* bclr */ + if (opcode == 19 && subcode == 528) + return 1; /* bcctr */ + + return 0; +} + +/* Return true if we are in the function's epilogue, i.e. after the + instruction that destroyed the function's stack frame. + + 1) scan forward from the point of execution: + a) If you find an instruction that modifies the stack pointer + or transfers control (except a return), execution is not in + an epilogue, return. + b) Stop scanning if you find a return instruction or reach the + end of the function or reach the hard limit for the size of + an epilogue. + 2) scan backward from the point of execution: + a) If you find an instruction that modifies the stack pointer, + execution *is* in an epilogue, return. + b) Stop scanning if you reach an instruction that transfers + control or the beginning of the function or reach the hard + limit for the size of an epilogue. */ + +static int +rs6000_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc) +{ + bfd_byte insn_buf[PPC_INSN_SIZE]; + CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end; + unsigned long insn; + struct frame_info *curfrm; + + /* Find the search limits based on function boundaries and hard limit. */ + + if (!find_pc_partial_function (pc, NULL, &func_start, &func_end)) + return 0; + + epilogue_start = pc - PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE; + if (epilogue_start < func_start) epilogue_start = func_start; + + epilogue_end = pc + PPC_MAX_EPILOGUE_INSTRUCTIONS * PPC_INSN_SIZE; + if (epilogue_end > func_end) epilogue_end = func_end; + + curfrm = get_current_frame (); + + /* Scan forward until next 'blr'. */ + + for (scan_pc = pc; scan_pc < epilogue_end; scan_pc += PPC_INSN_SIZE) + { + if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE)) + return 0; + insn = extract_signed_integer (insn_buf, PPC_INSN_SIZE); + if (insn == 0x4e800020) + break; + if (insn_changes_sp_or_jumps (insn)) + return 0; + } + + /* Scan backward until adjustment to stack pointer (R1). */ + + for (scan_pc = pc - PPC_INSN_SIZE; + scan_pc >= epilogue_start; + scan_pc -= PPC_INSN_SIZE) + { + if (!safe_frame_unwind_memory (curfrm, scan_pc, insn_buf, PPC_INSN_SIZE)) + return 0; + insn = extract_signed_integer (insn_buf, PPC_INSN_SIZE); + if (insn_changes_sp_or_jumps (insn)) + return 1; + } + + return 0; +} + /* Fill in fi->saved_regs */ @@ -3342,6 +3444,8 @@ set_gdbarch_deprecated_extract_struct_value_address (gdbarch, rs6000_extract_struct_value_address); set_gdbarch_skip_prologue (gdbarch, rs6000_skip_prologue); + set_gdbarch_in_function_epilogue_p (gdbarch, rs6000_in_function_epilogue_p); + set_gdbarch_inner_than (gdbarch, core_addr_lessthan); set_gdbarch_breakpoint_from_pc (gdbarch, rs6000_breakpoint_from_pc); --Boundary-00=_qFGzDDhs5oqznk3--