Re: hbreak.exp: Test hardware breakpoints

Daniel Jacobowitz
2008-03-01T04:40:05Z

On Wed, Feb 27, 2008 at 03:11:38PM +0000, Maciej W. Rozycki wrote:
> Daniel, have you got any further with this patch you proposed? I can see
> it has not been included in the tree.

I have checked in the updated version, which is attached.

> Here is my gdb.base/hbreak.exp test case again, updated according to your
> suggestion so that hardware breakpoints are only inserted once the target
> has been placed into the execution mode. It passes on i386-linux natively
> and with the mipsisa32-sde-elf target using the
> mips-sim-sde32/-EB/-march=mips32r2 and mips-sim-sde32/-EL/-march=mips32r2
> boards. It reports the cases correctly as unsupported on mips-linux
> natively and with the mipsisa32-sde-elf target using the
> mips-sim-sde32/-EB/-march=mips32r2 and mips-sim-sde32/-EL/-march=mips32r2
> boards.

It fails using gdbserver. The first failure looks like this:

(gdb) continue
Continuing.
Warning:
Cannot insert hardware breakpoint 10.
Could not insert hardware breakpoints:
You may have requested too many hardware breakpoints/watchpoints.

(gdb) FAIL: gdb.base/hbreak.exp: run until function breakpoint

"target remote" has hardware breakpoint support, but this particular
remote target does not. Unfortunately we do not detect the error
and I am not sure how to make it do so. There is a
gdb,no_hardware_watchpoints setting in the testsuite already; maybe we
can just skip this test if it is set?

The problem with autodetection is that we don't have any way to probe
for those packets at the moment. We don't get an error until we go to
insert one. We could try inserting one early, when it is requested,
maybe?

--
Daniel Jacobowitz
CodeSourcery

2007-02-29 Daniel Jacobowitz <dan@codesourcery.com>

* Makefile.in (i386-nat.o): Update.
* amd64-linux-nat.c (_initialize_amd64_linux_nat): Call
i386_use_watchpoints.
* i386-linux-nat.c (_initialize_i386_linux_nat): Call
i386_use_watchpoints.
* i386-nat.c (i386_stopped_data_address): Take two arguments.
(i386_stopped_by_watchpoint): Update call.
(i386_can_use_hw_breakpoint, i386_use_watchpoints): New.
* config/i386/nm-i386.h: Conditionalize definitions on
! I386_WATCHPOINTS_IN_TARGET_VECTOR.
(i386_use_watchpoints): Declare.
(i386_stopped_data_address): Update.
* config/i386/nm-linux.h (I386_WATCHPOINTS_IN_TARGET_VECTOR): Define.
* config/i386/nm-linux64.h (I386_WATCHPOINTS_IN_TARGET_VECTOR): Define.

Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.985
diff -u -p -r1.985 Makefile.in
--- Makefile.in 27 Feb 2008 01:06:20 -0000 1.985
+++ Makefile.in 1 Mar 2008 03:58:33 -0000
@@ -2229,7 +2229,8 @@ i386-linux-tdep.o: i386-linux-tdep.c $(d
$(value_h) $(regcache_h) $(inferior_h) $(osabi_h) $(reggroups_h) \
$(dwarf2_frame_h) $(gdb_string_h) $(i386_tdep_h) \
$(i386_linux_tdep_h) $(glibc_tdep_h) $(solib_svr4_h) $(symtab_h)
-i386-nat.o: i386-nat.c $(defs_h) $(breakpoint_h) $(command_h) $(gdbcmd_h)
+i386-nat.o: i386-nat.c $(defs_h) $(breakpoint_h) $(command_h) $(gdbcmd_h) \
+ $(target_h)
i386nbsd-nat.o: i386nbsd-nat.c $(defs_h) $(gdbcore_h) $(regcache_h) \
$(target_h) $(i386_tdep_h) $(i386bsd_nat_h) $(nbsd_nat_h) \
$(bsd_kvm_h)
Index: amd64-linux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/amd64-linux-nat.c,v
retrieving revision 1.20
diff -u -p -r1.20 amd64-linux-nat.c
--- amd64-linux-nat.c 16 Jan 2008 04:52:52 -0000 1.20
+++ amd64-linux-nat.c 1 Mar 2008 03:58:33 -0000
@@ -421,6 +421,8 @@ _initialize_amd64_linux_nat (void)
/* Fill in the generic GNU/Linux methods. */
t = linux_target ();

+ i386_use_watchpoints (t);
+
/* Override the GNU/Linux inferior startup hook. */
super_post_startup_inferior = t->to_post_startup_inferior;
t->to_post_startup_inferior = amd64_linux_child_post_startup_inferior;
Index: i386-linux-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-linux-nat.c,v
retrieving revision 1.85
diff -u -p -r1.85 i386-linux-nat.c
--- i386-linux-nat.c 1 Jan 2008 22:53:10 -0000 1.85
+++ i386-linux-nat.c 1 Mar 2008 03:58:33 -0000
@@ -820,6 +820,8 @@ _initialize_i386_linux_nat (void)
/* Fill in the generic GNU/Linux methods. */
t = linux_target ();

+ i386_use_watchpoints (t);
+
/* Override the default ptrace resume method. */
t->to_resume = i386_linux_resume;

Index: i386-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/i386-nat.c,v
retrieving revision 1.17
diff -u -p -r1.17 i386-nat.c
--- i386-nat.c 1 Jan 2008 22:53:11 -0000 1.17
+++ i386-nat.c 1 Mar 2008 03:58:33 -0000
@@ -21,6 +21,7 @@
#include "breakpoint.h"
#include "command.h"
#include "gdbcmd.h"
+#include "target.h"

/* Support for hardware watchpoints and breakpoints using the i386
debug registers.
@@ -563,7 +564,7 @@ i386_region_ok_for_watchpoint (CORE_ADDR
Otherwise, return zero. */

int
-i386_stopped_data_address (CORE_ADDR *addr_p)
+i386_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
{
CORE_ADDR addr = 0;
int i;
@@ -599,7 +600,7 @@ int
i386_stopped_by_watchpoint (void)
{
CORE_ADDR addr = 0;
- return i386_stopped_data_address (&addr);
+ return i386_stopped_data_address (&current_target, &addr);
}

/* Return non-zero if the inferior has some break/watchpoint that
@@ -654,6 +655,47 @@ i386_remove_hw_breakpoint (struct bp_tar
return retval;
}

+/* Returns the number of hardware watchpoints of type TYPE that we can
+ set. Value is positive if we can set CNT watchpoints, zero if
+ setting watchpoints of type TYPE is not supported, and negative if
+ CNT is more than the maximum number of watchpoints of type TYPE
+ that we can support. TYPE is one of bp_hardware_watchpoint,
+ bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
+ CNT is the number of such watchpoints used so far (including this
+ one). OTHERTYPE is non-zero if other types of watchpoints are
+ currently enabled.
+
+ We always return 1 here because we don't have enough information
+ about possible overlap of addresses that they want to watch. As an
+ extreme example, consider the case where all the watchpoints watch
+ the same address and the same region length: then we can handle a
+ virtually unlimited number of watchpoints, due to debug register
+ sharing implemented via reference counts in i386-nat.c. */
+
+static int
+i386_can_use_hw_breakpoint (int type, int cnt, int othertype)
+{
+ return 1;
+}
+
+void
+i386_use_watchpoints (struct target_ops *t)
+{
+ /* After a watchpoint trap, the PC points to the instruction after the
+ one that caused the trap. Therefore we don't need to step over it.
+ But we do need to reset the status register to avoid another trap. */
+ t->to_have_continuable_watchpoint = 1;
+
+ t->to_can_use_hw_breakpoint = i386_can_use_hw_breakpoint;
+ t->to_region_ok_for_hw_watchpoint = i386_region_ok_for_watchpoint;
+ t->to_stopped_by_watchpoint = i386_stopped_by_watchpoint;
+ t->to_stopped_data_address = i386_stopped_data_address;
+ t->to_insert_watchpoint = i386_insert_watchpoint;
+ t->to_remove_watchpoint = i386_remove_watchpoint;
+ t->to_insert_hw_breakpoint = i386_insert_hw_breakpoint;
+ t->to_remove_hw_breakpoint = i386_remove_hw_breakpoint;
+}
+
#endif /* I386_USE_GENERIC_WATCHPOINTS */
\f

Index: config/i386/nm-i386.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/nm-i386.h,v
retrieving revision 1.12
diff -u -p -r1.12 nm-i386.h
--- config/i386/nm-i386.h 1 Jan 2008 22:53:14 -0000 1.12
+++ config/i386/nm-i386.h 1 Mar 2008 03:58:33 -0000
@@ -24,6 +24,11 @@
/* Targets should define this to use the generic x86 watchpoint support. */
#ifdef I386_USE_GENERIC_WATCHPOINTS

+/* Add watchpoint methods to the provided target_ops. Targets which call
+ this should also define I386_WATCHPOINTS_IN_TARGET_VECTOR. */
+struct target_ops;
+void i386_use_watchpoints (struct target_ops *);
+
/* Clear the reference counts and forget everything we knew about DRi. */
extern void i386_cleanup_dregs (void);

@@ -48,7 +53,7 @@ extern int i386_stopped_by_hwbp (void);
/* If the inferior has some break/watchpoint that triggered, set
the address associated with that break/watchpoint and return
true. Otherwise, return false. */
-extern int i386_stopped_data_address (CORE_ADDR *);
+extern int i386_stopped_data_address (struct target_ops *, CORE_ADDR *);

/* Insert a hardware-assisted breakpoint at BP_TGT->placed_address.
Return 0 on success, EBUSY on failure. */
@@ -59,6 +64,10 @@ extern int i386_insert_hw_breakpoint (st
Return 0 on success, -1 on failure. */
extern int i386_remove_hw_breakpoint (struct bp_target_info *bp_tgt);

+extern int i386_stopped_by_watchpoint (void);
+
+#ifndef I386_WATCHPOINTS_IN_TARGET_VECTOR
+
/* Returns the number of hardware watchpoints of type TYPE that we can
set. Value is positive if we can set CNT watchpoints, zero if
setting watchpoints of type TYPE is not supported, and negative if
@@ -90,11 +99,10 @@ extern int i386_remove_hw_breakpoint (s

#define HAVE_CONTINUABLE_WATCHPOINT 1

-extern int i386_stopped_by_watchpoint (void);
-
#define STOPPED_BY_WATCHPOINT(W) (i386_stopped_by_watchpoint () != 0)

-#define target_stopped_data_address(target, x) i386_stopped_data_address(x)
+#define target_stopped_data_address(target, x) \
+ i386_stopped_data_address(target, x)

/* Use these macros for watchpoint insertion/removal. */

@@ -110,6 +118,8 @@ extern int i386_stopped_by_watchpoint (v
#define target_remove_hw_breakpoint(bp_tgt) \
i386_remove_hw_breakpoint (bp_tgt)

+#endif /* I386_WATCHPOINTS_IN_TARGET_VECTOR */
+
#endif /* I386_USE_GENERIC_WATCHPOINTS */

#endif /* NM_I386_H */
Index: config/i386/nm-linux.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/nm-linux.h,v
retrieving revision 1.27
diff -u -p -r1.27 nm-linux.h
--- config/i386/nm-linux.h 1 Jan 2008 22:53:14 -0000 1.27
+++ config/i386/nm-linux.h 1 Mar 2008 03:58:33 -0000
@@ -23,6 +23,7 @@

/* GNU/Linux supports the i386 hardware debugging registers. */
#define I386_USE_GENERIC_WATCHPOINTS
+#define I386_WATCHPOINTS_IN_TARGET_VECTOR

#include "i386/nm-i386.h"
#include "config/nm-linux.h"
Index: config/i386/nm-linux64.h
===================================================================
RCS file: /cvs/src/src/gdb/config/i386/nm-linux64.h,v
retrieving revision 1.7
diff -u -p -r1.7 nm-linux64.h
--- config/i386/nm-linux64.h 1 Jan 2008 22:53:14 -0000 1.7
+++ config/i386/nm-linux64.h 1 Mar 2008 03:58:33 -0000
@@ -25,6 +25,7 @@

/* GNU/Linux supports the i386 hardware debugging registers. */
#define I386_USE_GENERIC_WATCHPOINTS
+#define I386_WATCHPOINTS_IN_TARGET_VECTOR

#include "i386/nm-i386.h"
#include "config/nm-linux.h"