[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#660: GDB gets address of structure member wrong in memory breakpoint

Sven Rudolph writes in email to me:
> > Package: gdb
> > Version: 4.12
> >
> > As you can see below, when setting a memory breakpoint on a structure
> > member GDB uses the address of the start of the structure by mistake.
> > Applying *& to the member (to take its address and then dereference
> > it) gives correct results.
> (typescript deleted)
> You used commands that don't even exist in the current version of gdb,
> so i cannot reproduce this problem. I'm not a gdb expert, so please
> try to reproduce this problem on a current gdb (or close the bug) .

These commands have equivalents in gdb 4.14-1.  However, the
equivalents don't appear to work for me at all.  See the transcript

Please can we keep this bug open until (a) the memory watchpoints,
which are a useful feature, work and (b) we see that the original bug
is fixed.


-chiark:~/junk> cat t.c
struct foo { int a,b; };

void fong(struct foo *p, int x) { p->b=x; }

int main(int argc, char **argv) {
  struct foo f;
  f.a= 2;
  f.b= 3;
-chiark:~/junk> gcc -g t.c
-chiark:~/junk> gdb a.out
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.14 (i486-debian-linux), Copyright 1995 Free Software Foundation, Inc...
(gdb) break main
Breakpoint 1 at 0x1093: file t.c, line 7.
(gdb) run
Starting program: /u/ian/junk/a.out

Breakpoint 1, main (argc=1, argv=0xbffff858) at t.c:7
7         f.a= 2;
(gdb) step
8         f.b= 3;
(gdb) step
9         fong(&f,4);
(gdb) print f
$1 = {a = 2, b = 3}
(gdb) watch f.b
Hardware watchpoint 2: f.b
(gdb) watch f.a
Hardware watchpoint 3: f.a
(gdb) watch *&f.b
Hardware watchpoint 4: *&f.b
(gdb) info watchpoints
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x00001093 in main at t.c:7
        breakpoint already hit 1 time
2   hw watchpoint  keep y   f.b
3   hw watchpoint  keep y   f.a
4   hw watchpoint  keep y   *&f.b
(gdb) cont
warning: Hardware watchpoint 3: Could not insert watchpoint

warning: Hardware watchpoint 4: Could not insert watchpoint

ptrace: Unknown error -1.
Cannot insert breakpoints.
The same program may be running in another process.
(gdb) quit
The program is running.  Quit anyway (and kill it)? (y or n) y

Reply to: