This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why no hwatch command in gdb ?


Hi, Jan,

On 3/10/11, Jan Kratochvil <jan.kratochvil@redhat.com> wrote:
> GNU gdb (GDB) 7.2.50.20110310-cvs
> This GDB was configured as "x86_64-unknown-linux-gnu".
> (gdb) watch gdb_stdout
> Hardware watchpoint 2: gdb_stdout
> (gdb) watch gdb_stderr
> Hardware watchpoint 3: gdb_stderr
> (gdb) watch gdb_stdlog
> Hardware watchpoint 4: gdb_stdlog
> (gdb) watch gdb_stdin
> Hardware watchpoint 5: gdb_stdin
> (gdb) watch gdb_stdtargin
> Hardware watchpoint 6: gdb_stdtargin
> (gdb) continue
> Continuing.
> Warning:
> Could not insert hardware watchpoint 5.
> Could not insert hardware breakpoints:
> You may have requested too many hardware breakpoints/watchpoints.
> (gdb)

Well, I am confused with the gdb hardware watchpoint support in x86
arch.

I tested it in a ARM board. Now the kernel can support up to 1
hardware watchpoint and 6 hardware breakpoints.

(gdb) hbreak main
No hardware breakpoint support in the target.
(gdb) b main
Breakpoint 2 at 0x8364: file /tmp/helloworld.c, line 7.
(gdb) run
Starting program: /tmp/helloworld

Breakpoint 2, main () at /tmp/helloworld.c:7
7         i=1;
(gdb) watch i
Hardware watchpoint 3: i
(gdb) watch i
Watchpoint 4: i
(gdb) hbreak 8
Hardware assisted breakpoint 5 at 0x8370: file /tmp/helloworld.c, line 8.
(gdb) hbreak 9
Hardware assisted breakpoint 6 at 0x837c: file /tmp/helloworld.c, line 9.
(gdb) hbreak 10
Hardware assisted breakpoint 7 at 0x8388: file /tmp/helloworld.c, line 10.
(gdb) hbreak 11
Hardware assisted breakpoint 8 at 0x8394: file /tmp/helloworld.c, line 11.
(gdb) hbreak 12
Hardware assisted breakpoint 9 at 0x83a0: file /tmp/helloworld.c, line 12.
(gdb) hbreak 13
Hardware assisted breakpoint 10 at 0x83ac: file /tmp/helloworld.c, line 13.
(gdb) hbreak 14
Hardware breakpoints used exceeds limit.
(gdb) hbreak 15
Hardware breakpoints used exceeds limit.

Firstly, before the program run, we can not set the hardware
breakpoint. For gdb use ptrace to get the debug register information,
and thread id is needed.

hardware watchpoint can only be set to 1, and hardware breakpoint can
be set to 6. If more than 6, gdb will complain with "Hardware
breakpoints used exceeds limit."

So I think it works fine in the arm arch.

But in x86, I took a look at my CentOS 5.5 7.0.1-23.el5.
We can set the hardware breakpoint before program runs, it's not the
standard gdb function. There is a patch named
gdb-bz541866-rwatch-before-run.patch, in the patch,
target_can_use_hardware_watchpoint is forced to be 1.

--- /dev/null
+++ b/gdb/config/ia64/nm-linux.h
@@ -0,0 +1,28 @@
+/* Native support for GNU/Linux ia64.
+
+   Copyright 2010 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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/>.  */
+
+#ifndef NM_LINUX_H
+#define NM_LINUX_H
+
+#include "config/nm-linux.h"
+
+/* Red Hat backward compatibility with gdb-6.8.  */
+#define target_can_use_hardware_watchpoint(type, cnt, ot) 1
+
+#endif /* NM_LINUX_H */
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1257,8 +1257,10 @@ extern char *normal_pid_to_str (ptid_t ptid);
    bp_hardware_breakpoint.  CNT is the number of such watchpoints used so far
    (including this one?).  OTHERTYPE is who knows what...  */

+#ifndef target_can_use_hardware_watchpoint
 #define target_can_use_hardware_watchpoint(TYPE,CNT,OTHERTYPE) \
  (*current_target.to_can_use_hw_breakpoint) (TYPE, CNT, OTHERTYPE);
+#endif

So the problem is because of the previous patch of this distribution
?????

Regards,
  robert


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]