From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [patch] Warn on constant value watchpoints
Date: Sun, 08 Jun 2008 15:53:00 -0000 [thread overview]
Message-ID: <20080608155302.GA25486@host0.dyn.jankratochvil.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 201 bytes --]
Hi,
idea came from a discussion with the Firefox maintainer Martin Stransky who had
disfunctional watchpoint on the address of a variable:
(gdb) watch 0x4343548
Watchpoint 1: 70530376
Regards,
Jan
[-- Attachment #2: gdb-constant-watchpoint.patch --]
[-- Type: text/plain, Size: 3291 bytes --]
2008-06-08 Jan Kratochvil <jan.kratochvil@redhat.com>
* breakpoint.c (watch_command_1): New variable VAL_RESULT. Fill in
VAL_RESULT by the existing FETCH_WATCHPOINT_VALUE call. Ask user for
constant list VAL_RESULT.
2008-06-08 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.texinfo (Set Watchpoints): Document constant value watchpoints.
2008-06-08 Jan Kratochvil <jan.kratochvil@redhat.com>
* gdb.base/watchpoint.exp: New test for constant value watchpoints.
--- gdb/breakpoint.c 6 Jun 2008 20:58:08 -0000 1.324
+++ gdb/breakpoint.c 8 Jun 2008 15:18:38 -0000
@@ -5818,7 +5818,7 @@ watch_command_1 (char *arg, int accessfl
struct symtab_and_line sal;
struct expression *exp;
struct block *exp_valid_block;
- struct value *val, *mark;
+ struct value *val, *mark, *val_result;
struct frame_info *frame;
struct frame_info *prev_frame = NULL;
char *exp_start = NULL;
@@ -5903,10 +5903,23 @@ watch_command_1 (char *arg, int accessfl
exp_end = arg;
exp_valid_block = innermost_block;
mark = value_mark ();
- fetch_watchpoint_value (exp, &val, NULL, NULL);
+ fetch_watchpoint_value (exp, &val, &val_result, NULL);
if (val != NULL)
release_value (val);
+ if (from_tty)
+ {
+ struct value *v;
+
+ /* VAL may be unset for unreachable final values. */
+ for (v = val_result; v; v = value_next (v))
+ if (VALUE_LVAL (v) == lval_memory || VALUE_LVAL (v) == lval_register)
+ break;
+ if (v == NULL && !query
+ (_("Do you insist on this watchpoint with a constant value? ")))
+ error (_("Watchpoint with a constant value was cancelled."));
+ }
+
tok = arg;
while (*tok == ' ' || *tok == '\t')
tok++;
--- gdb/doc/gdb.texinfo 6 Jun 2008 20:58:08 -0000 1.503
+++ gdb/doc/gdb.texinfo 8 Jun 2008 15:19:53 -0000
@@ -3375,6 +3426,18 @@ This command prints a list of watchpoint
it is the same as @code{info break} (@pxref{Set Breaks}).
@end table
+If you watch for a change in a numerically entered address you need to
+dereference it as the address itself is just a constant number which will never
+change:
+
+@smallexample
+(@value{GDBP}) watch 0x600850
+Do you insist on this watchpoint with a constant value? (y or n) n
+Watchpoint with a constant value was cancelled.
+(@value{GDBP}) watch *(int *) 0x600850
+Watchpoint 1: *(int *) 6293584
+@end smallexample
+
@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
watchpoints execute very quickly, and the debugger reports a change in
value at the exact instruction where the change occurs. If @value{GDBN}
--- gdb/testsuite/gdb.base/watchpoint.exp 15 Apr 2008 14:33:54 -0000 1.18
+++ gdb/testsuite/gdb.base/watchpoint.exp 8 Jun 2008 15:19:55 -0000
@@ -679,6 +679,18 @@ set prev_timeout $timeout
set timeout 600
verbose "Timeout now 600 sec.\n"
+# Test constant-value watchpoints.
+gdb_test "watch 123" "Watchpoint with a constant value was cancelled." \
+ "constant watchpoint" \
+ "Do you insist on this watchpoint with a constant value\\? \\(y or n\\) " \
+ "n"
+# For unsupported constant-value watchpoints catching we need to reset the
+# breakpoints counter.
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load $binfile
+
if [initialize] then {
test_simple_watchpoint
next reply other threads:[~2008-06-08 15:53 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-08 15:53 Jan Kratochvil [this message]
2008-06-08 18:05 ` Eli Zaretskii
2008-06-08 18:09 ` Daniel Jacobowitz
2008-06-08 18:50 ` Eli Zaretskii
2008-06-08 19:28 ` Jan Kratochvil
2008-06-09 6:14 ` Jan Kratochvil
2008-06-26 15:01 ` Daniel Jacobowitz
2008-06-26 19:40 ` Eli Zaretskii
2008-07-10 9:00 ` Jan Kratochvil
2008-07-10 9:02 ` Jan Kratochvil
2008-07-10 9:06 ` Jan Kratochvil
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080608155302.GA25486@host0.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox