From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9657 invoked by alias); 30 Nov 2005 19:55:14 -0000 Received: (qmail 9650 invoked by uid 22791); 30 Nov 2005 19:55:14 -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; Wed, 30 Nov 2005 19:55:10 +0000 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e32.co.us.ibm.com (8.12.11/8.12.11) with ESMTP id jAUJt8r2021145 for ; Wed, 30 Nov 2005 14:55:08 -0500 Received: from d03av04.boulder.ibm.com (d03av04.boulder.ibm.com [9.17.195.170]) by d03relay04.boulder.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id jAUJubGD074912 for ; Wed, 30 Nov 2005 12:56:37 -0700 Received: from d03av04.boulder.ibm.com (loopback [127.0.0.1]) by d03av04.boulder.ibm.com (8.12.11/8.13.3) with ESMTP id jAUJt8DX026662 for ; Wed, 30 Nov 2005 12:55:08 -0700 Received: from dyn9047022123-009047022095.beaverton.ibm.com (dyn9047022123-009047022095.beaverton.ibm.com [9.47.22.95]) by d03av04.boulder.ibm.com (8.12.11/8.12.11) with ESMTP id jAUJt8jQ026593 for ; Wed, 30 Nov 2005 12:55:08 -0700 From: Paul Gilliam Reply-To: pgilliam@us.ibm.com To: gdb-patches@sources.redhat.com Subject: [PATCH] add 'rs6000_in_function_epilogue_p()' Date: Wed, 30 Nov 2005 23:56:00 -0000 User-Agent: KMail/1.6.2 MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <200511301225.56802.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-11/txt/msg00515.txt.bz2 This patch fixes a problem when watching local variables on PowerPC. Here is a reference from the gdb mailing list: http://sourceware.org/ml/gdb/2005-11/msg00602.html I know the patch uses a depreciated function and I am open to ideas. Here is a reference from the gdb mailing list about ideas to avoid using the depreciated function: http://sourceware.org/ml/gdb/2005-11/msg00623.html I wanted to submit this patch as a starting point, but if it is acceptable, I'll commit it. 2005-11-30 Paul Gilliam * rs6000-tdep.c: Add new subroutine, 'rs6000_in_function_epilogue_p()' and put it into the architecture vector. Index: rs6000-tdep.c =================================================================== 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 1 Nov 2005 19:32:36 -0000 1.248 +++ rs6000-tdep.c 30 Nov 2005 18:59:27 -0000 @@ -502,6 +502,63 @@ rs6000_skip_prologue (CORE_ADDR pc) return pc; } +static int +insn_changes_sp(unsigned long insn) +{ + int opcode = (insn>>26) & 0x03f; + int sd = (insn>>21) & 0x01f; + int a = (insn>>16) & 0x01f; + int b = (insn>>11) & 0x01f; + int subcode = (insn>> 1) & 0x3ff; + int rc = insn & 0x001; + + 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) */ + + return 0; +} + +/* Return true if we are in the functin's epilogue, i.e. after the + instruction that destroyed the function's stack frame. */ +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_addr, func_end; + unsigned long insn; + + /* Find the search limits. */ + if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end)) + return 0; + + /* Scan forward untill next 'blr'. */ + for (scan_pc = pc; scan_pc < func_end; scan_pc += PPC_INSN_SIZE) + { + if (deprecated_read_memory_nobpt (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(insn)) + return 0; + } + + /* Scan backward untill adjustment to stack pointer (R1). */ + for (scan_pc=pc-PPC_INSN_SIZE; scan_pc>=func_addr; scan_pc-=PPC_INSN_SIZE) + { + if (deprecated_read_memory_nobpt (scan_pc, insn_buf, PPC_INSN_SIZE)) + return 0; + insn = extract_signed_integer (insn_buf, PPC_INSN_SIZE); + if (insn_changes_sp(insn)) + return 1; + } + + return 0; +} + /* Fill in fi->saved_regs */ @@ -3342,6 +3399,8 @@ rs6000_gdbarch_init (struct gdbarch_info 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);