This is the mail archive of the 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: [PATCH] Compare contents when evaluating an array watchpoint


Looking through this thread, the technical issues appear to have been resolved. You should probably ping the maintainers.

--- Begin Message --- 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
+++ 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;
+ {
+ int len = TYPE_LENGTH (VALUE_TYPE (arg1));
+ 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);

--- End Message ---

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