From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15468 invoked by alias); 24 Jun 2011 02:31:10 -0000 Received: (qmail 15456 invoked by uid 22791); 24 Jun 2011 02:31:09 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from service87.mimecast.com (HELO service87.mimecast.com) (94.185.240.25) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Fri, 24 Jun 2011 02:30:55 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Fri, 24 Jun 2011 03:30:52 +0100 Received: from Terrysh02 ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.0); Fri, 24 Jun 2011 03:30:50 +0100 From: "Terry Guo" To: References: In-Reply-To: Subject: [PATCH] Fix that different function breakpoints are set at same pc address (PR gdb/12703) Date: Fri, 24 Jun 2011 02:31:00 -0000 Message-ID: <000001cc3216$b96ba290$2c42e7b0$@guo@arm.com> MIME-Version: 1.0 X-MC-Unique: 111062403305200401 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable 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 X-SW-Source: 2011-06/txt/msg00363.txt.bz2 Hello, This patch addresses the bug in gdb/12703 which sets two different function breakpoints at same pc address. In this patch I enhanced the way to analyze the ARM thumb prologue to prevent the function breakpoint from being set outside the function body. Patch has been tested against arm-none-eabi with no regressions. OK for commit? Thanks, Terry gdb/ChangLog: 2011-06-16 Terry Guo PR gdb/12703 * arm-tdep.c (arm_skip_prologue): Don't scan beyond the end of the current function. gdb/testsuite/ChangLog: 2011-06-16 Terry Guo PR gdb/12703 * gdb.base/break-function.c: New testcase. * gdb.base/break-function.exp: New script. diff --git gdb/arm-tdep.c gdb/arm-tdep.c index 2dd8c9e..c188576 100644 --- gdb/arm-tdep.c +++ gdb/arm-tdep.c @@ -1372,13 +1372,13 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) enum bfd_endian byte_order_for_code =3D gdbarch_byte_order_for_code (gdbarch); unsigned long inst; CORE_ADDR skip_pc; - CORE_ADDR func_addr, limit_pc; + CORE_ADDR func_addr, limit_pc, end_pc; struct symtab_and_line sal; =20 /* See if we can determine the end of the prologue via the symbol table. If so, then return either PC, or the PC after the prologue, whichever is greater. */ - if (find_pc_partial_function (pc, NULL, &func_addr, NULL)) + if (find_pc_partial_function (pc, NULL, &func_addr, &end_pc)) { CORE_ADDR post_prologue_pc =3D skip_prologue_using_sal (gdbarch, func_addr); @@ -1439,6 +1439,9 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) if (limit_pc =3D=3D 0) limit_pc =3D pc + 64; /* Magic. */ =20 + /* Don't scan beyond the end of the current function. */ + if (limit_pc > end_pc) + limit_pc =3D end_pc; =20 /* Check if this is Thumb code. */ if (arm_pc_is_thumb (gdbarch, pc)) diff --git gdb/testsuite/gdb.base/break-function.c gdb/testsuite/gdb.base/break-function.c new file mode 100644 index 0000000..e24cf91 --- /dev/null +++ gdb/testsuite/gdb.base/break-function.c @@ -0,0 +1,47 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 1992, 1993, 1994, 1995, 1999, 2002, 2003, 2007, 2008, 2009, 2010, + 2011 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +unsigned long _etext; +unsigned long _data; +unsigned long _edata; + +void foo(void) +{ + while(1) + { + } +} /* End of function foo */ + +void bar(void) +{ + unsigned long *pulSrc, *pulDest; + + pulSrc =3D &_etext; + for(pulDest =3D &_data; pulDest < &_edata; ) + { + *pulDest++ =3D *pulSrc++; + } +} + + +int main() +{ + bar(); + foo();=20=20 +} diff --git gdb/testsuite/gdb.base/break-function.exp gdb/testsuite/gdb.base/break-function.exp new file mode 100644 index 0000000..a42ba79 --- /dev/null +++ gdb/testsuite/gdb.base/break-function.exp @@ -0,0 +1,35 @@ +# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, +# 2000, 2002, 2003, 2007, 2008, 2009, 2010, 2011 +# Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +set srcfile break-function.c + +if { [prepare_for_testing break-function.exp "break-function" {break-function.c}] } { + return -1 +} + +set bp_location_boundary [gdb_get_line_number "End of function foo"] + +gdb_test_multiple "b foo" "Set breakpoint for function foo" { + -re "Breakpoint 1 at.*file.*, line (\[0-9\]+).*" { + set bp_pos $expect_out(1,string);=20=20=20=20=20=20=20 + if { $bp_pos > $bp_location_boundary } { + fail "The location of function breakpoint exceeds the body of the function.\n" + } else {=20=20=20=20=20=20=20=20=20=20 + pass "PASS"; + } + } +} --=20 1.7.1