Bug 9681 - gdb-weekly-6.8.50.20081216 lets you set watchpoints on nonexistent struct members
Summary: gdb-weekly-6.8.50.20081216 lets you set watchpoints on nonexistent struct mem...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: breakpoints (show other bugs)
Version: unknown
: P2 normal
Target Milestone: 7.0
Assignee: Pedro Alves
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-23 22:26 UTC by Peter Maydell
Modified: 2009-01-01 22:04 UTC (History)
1 user (show)

See Also:
Host: i486-linux-gnu
Target: i486-linux-gnu
Build: i486-linux-gnu
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Maydell 2008-12-23 22:26:46 UTC
Seen with gdb-weekly-6.8.50.20081216.tar.bz2 on Linux/ix86 native.

This snapshot of gdb will happily allow you to put watchpoints on structure
members which don't exist:
  (gdb) watch myfoo.nosuchmember
  Watchpoint 2: myfoo.nosuchmember

Trying the same thing with ubuntu's gdb (which advertises itself as "GNU gdb
6.8-debian") gives:
  (gdb) watch myfoo.nosuchmember
  There is no member named nosuchmember.

So I guess this is a regression. It seems to be watchpoint-specific; for
instance "print myfoo.nosuch" correctly gives an error.

The transcript below gives a more complete test example.

pm215@canth:~/gdb-srcs$ cat t.c
struct foo {
  int x;
  int y;
};
struct foo myfoo;
int main(void) {
  myfoo.x = 1;
  return 0;
}
pm215@canth:~/gdb-srcs$ gcc -g -Wall -o t t.c
pm215@canth:~/gdb-srcs$ build/gdb/gdb t
GNU gdb (GDB) 6.8.50.20081216
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
(gdb) break main
Breakpoint 1 at 0x80483a2: file t.c, line 7.
(gdb) run
Starting program: /home/pm215/gdb-srcs/t

Breakpoint 1, main () at t.c:7
7         myfoo.x = 1;
(gdb) watch myfoo.nosuchmember
Watchpoint 2: myfoo.nosuchmember
(gdb) c
Continuing.

Program exited normally.
Current language:  auto; currently asm
Comment 1 Pedro Alves 2008-12-30 00:26:19 UTC
I tracked it down to around 2008-03-03.  This seems related/suspicious:

2008-03-03  Daniel Jacobowitz  <dan@codesourcery.com>

	* breakpoint.c (fetch_watchpoint_value): New function.
	(update_watchpoint): Set and clear val_valid.  Use
	fetch_watchpoint_value.  Handle unreadable values on the
	value chain.  Correct check for user-requested array watchpoints.
	(breakpoint_init_inferior): Clear val_valid.
	(watchpoint_value_print): New function.
	(print_it_typical): Use it.  Do not free or clear old_val.  Print
	watchpoints even if old_val == NULL.
	(watchpoint_check): Use fetch_watchpoint_value.  Check for values
	becoming readable or unreadable.
	(watch_command_1): Use fetch_watchpoint_value.  Set val_valid.
	(do_enable_watchpoint): Likewise.
	* breakpoint.h (struct breakpoint): Update comment for val.  Add
	val_valid.
	* NEWS: Mention watchpoints on inaccessible memory.
Comment 2 Pedro Alves 2008-12-31 17:55:27 UTC
Testing a patch.
Comment 3 Sourceware Commits 2009-01-01 22:02:17 UTC
Subject: Bug 9681

CVSROOT:	/cvs/src
Module name:	src
Changes by:	palves@sourceware.org	2009-01-01 22:02:03

Modified files:
	gdb            : ChangeLog breakpoint.c corefile.c exceptions.h 
	gdb/testsuite  : ChangeLog 
	gdb/testsuite/gdb.base: watchpoint.exp 

Log message:
	2009-01-01  Pedro Alves  <pedro@codesourcery.com>
	
	PR breakpoints/9681:
	* exceptions.h (enum errors): New error type, MEMORY_ERROR.
	* corefile.c (memory_error): Rewrite to throw a MEMORY_ERROR.
	* breakpoint.c (fetch_watchpoint_value): Ignore MEMORY_ERRORs, but
	retrow all other exceptions.
	
	2009-01-01  Pedro Alves  <pedro@codesourcery.com>
	
	PR breakpoints/9681:
	* gdb.base/watchpoint.exp: Add regression test.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.10057&r2=1.10058
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/breakpoint.c.diff?cvsroot=src&r1=1.368&r2=1.369
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/corefile.c.diff?cvsroot=src&r1=1.47&r2=1.48
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/exceptions.h.diff?cvsroot=src&r1=1.22&r2=1.23
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1783&r2=1.1784
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.base/watchpoint.exp.diff?cvsroot=src&r1=1.19&r2=1.20

Comment 4 Pedro Alves 2009-01-01 22:04:31 UTC
Fix checked in.  The next snapshot should have this fixed.  Thanks!