This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[PATCH] Compare contents when evaluating an array watchpoint
- From: Klee Dienes <klee at apple dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Sun, 6 Oct 2002 05:16:39 -0400
- Subject: [PATCH] Compare contents when evaluating an array watchpoint
The following patch allows one to set watchpoints on arrays, and have
the watchpoint triggered if any element in the array changes. Without
the patch, the C value_equal semantics causes the address of the array
to be checked for change, not the contents --- resulting in a
watchpoint that can never be hit.
This is particularly useful if one wants to do commands like watch
{char[80]} 0xfff0000, or similar, in order to watch an arbitrary region
of memory.
2002-08-06 Klee Dienes <kdienes@bluegill.localnet>
* breakpoint.c (watchpoint_equal): New function. Like
value_equal, but arrays only count as "equal" if they have the
same contents.
(watchpoint_check): Update to use watchpoint_equal.
diff -u -r1.1.1.21 -r1.47
--- breakpoint.c 2002/09/26 20:56:41 1.1.1.21
+++ breakpoint.c 2002/10/06 09:07:23 1.47
@@ -2359,6 +2448,34 @@
return bs;
}
+/* Like value_equal, but two arrays are only considered equal if their
+ contents are equal. */
+
+static int
+watchpoint_equal (struct value *arg1, struct value *arg2)
+{
+ register int len;
+ register char *p1, *p2;
+
+ if ((TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY)
+ && (TYPE_CODE (VALUE_TYPE (arg2)) == TYPE_CODE_ARRAY))
+ {
+ int len = TYPE_LENGTH (VALUE_TYPE (arg1));
+ if (TYPE_LENGTH (VALUE_TYPE (arg1)) != TYPE_LENGTH (VALUE_TYPE
(arg2)))
+ return 0;
+ p1 = VALUE_CONTENTS (arg1);
+ p2 = VALUE_CONTENTS (arg2);
+ while (--len >= 0)
+ {
+ if (*p1++ != *p2++)
+ break;
+ }
+ return len < 0;
+ }
+
+ return value_equal (arg1, arg2);
+}
+
/* Possible return values for watchpoint_check (this can't be an enum
because of check_errors). */
/* The watchpoint has been deleted. */
@@ -2417,7 +2535,7 @@
struct value *mark = value_mark ();
struct value *new_val = evaluate_expression
(bs->breakpoint_at->exp);
- if (!value_equal (b->val, new_val))
+ if (!watchpoint_equal (b->val, new_val))
{
release_value (new_val);