public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Re: [PATCH] Fix that different function breakpoints are set at same pc address (PR gdb/12703)
@ 2011-06-27 11:26 Terry Guo
  2011-06-29  1:26 ` Terry Guo
  0 siblings, 1 reply; 15+ messages in thread
From: Terry Guo @ 2011-06-27 11:26 UTC (permalink / raw)
  To: gdb-patches

Hi Yao and Pedro,

Thanks for your helpful comments. I did learnt a lot from them. After some
further investigation, I agree with Yao's patch and think it is better than
mine. Yao's patch also fixed another function break point issue which I will
show later. I performed "make check" for Yao's patch on QEMU and no
regression found. I am reworking the patch according to the comments.

I agree with the root cause is the function thumb_instruction_changes_pc
fails to catch the b.n instruction. And this is caused by check [1] as
pointed by Yao. Here is the disassembly code of function bar:

00008146 <bar>:
    8146:       b510            push    {r4, lr}
    8148:       2200            movs    r2, #0
    814a:       4905            ldr     r1, [pc, #20]   ; (8160 <bar+0x1a>)
    814c:       4c05            ldr     r4, [pc, #20]   ; (8164 <bar+0x1e>)
    814e:       4806            ldr     r0, [pc, #24]   ; (8168 <bar+0x22>)
    8150:       e002            b.n     8158 <bar+0x12>
    8152:       5813            ldr     r3, [r2, r0]
    8154:       5053            str     r3, [r2, r1]
    8156:       3204            adds    r2, #4
    8158:       1853            adds    r3, r2, r1
    815a:       42a3            cmp     r3, r4
    815c:       d3f9            bcc.n   8152 <bar+0xc>
    815e:       bd10            pop     {r4, pc}

With or without my previous patch, the command "b bar" will set break point
at location 0x8158. With Yao's patch, the break point will be set at
location 0x8150 because the thumb_instruction_changes_pc catches the b.n
instruction. That's also why I think Yao's patch is better.

Best regards,
Terry



^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] Fix that different function breakpoints are set at same pc address  (PR gdb/12703)
@ 2011-06-24  2:31 Terry Guo
  2011-06-24  3:55 ` Yao Qi
  0 siblings, 1 reply; 15+ messages in thread
From: Terry Guo @ 2011-06-24  2:31 UTC (permalink / raw)
  To: gdb-patches

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  <terry.guo@arm.com>

        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  <terry.guo@arm.com>

        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 = 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;
 
   /* 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
 	= skip_prologue_using_sal (gdbarch, func_addr);
@@ -1439,6 +1439,9 @@ arm_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR
pc)
   if (limit_pc == 0)
     limit_pc = pc + 64;          /* Magic.  */
 
+  /* Don't scan beyond the end of the current function.  */
+  if (limit_pc > end_pc)
+    limit_pc = end_pc;
 
   /* 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 <http://www.gnu.org/licenses/>.
*/
+
+
+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 = &_etext;
+    for(pulDest = &_data; pulDest < &_edata; )
+    {
+        *pulDest++ = *pulSrc++;
+    }
+}
+
+
+int main()
+{
+  bar();
+  foo();  
+}
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 <http://www.gnu.org/licenses/>.
+
+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);       
+        if { $bp_pos > $bp_location_boundary } {
+            fail "The location of function breakpoint exceeds the body of
the function.\n"
+          } else {          
+            pass "PASS";
+          }
+     }
+}
-- 
1.7.1




^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2011-07-13  8:26 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-27 11:26 [PATCH] Fix that different function breakpoints are set at same pc address (PR gdb/12703) Terry Guo
2011-06-29  1:26 ` Terry Guo
2011-06-29  5:36   ` Yao Qi
2011-06-29  7:00     ` Terry Guo
2011-06-29  8:00       ` Yao Qi
2011-06-29  8:49         ` Terry Guo
     [not found]         ` <45520D6299C11E4588128526465332BB0D0C8B1246@SAROVARA.Asiapac.Arm.com>
2011-06-29 10:00           ` Yao Qi
2011-06-29 10:17             ` Terry Guo
2011-07-01  8:59             ` Richard Earnshaw
2011-07-01  9:47               ` Pedro Alves
2011-07-13 13:21                 ` Terry Guo
  -- strict thread matches above, loose matches on Subject: below --
2011-06-24  2:31 Terry Guo
2011-06-24  3:55 ` Yao Qi
2011-06-24  8:59   ` Pedro Alves
2011-06-24 10:39     ` Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).