This is the mail archive of the gdb@sourceware.org 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: Checking if addess is on stack?


> From: Vladimir Prus <ghost@cs.msu.su>
> Date: Thu, 20 Apr 2006 19:31:37 +0400
> Cc: gdb@sources.redhat.com
> 
> (gdb) watch *ptr
> Hardware watchpoint 2: *ptr
> (gdb) c
> Continuing.
> Hardware watchpoint 2 deleted because the program has left the block
> in which its expression is valid.
> 
> Program exited normally.
> (gdb)
> 
> I don't watch watchpoint 2 to be deleted in this case.

You could put 2 watchpoints instead of one, as in the session attached
at the end of this message.  (Yes, I know that it triggers outside
`main', but that's what we have now.)

> I want to set breakpoint at address, and be it automatically removed when 
> leaving function, if and only if the address is on function stack.

Doing this in all cases would be a misfeature, for the reasons I tried
to explain: users normally expect us to stop the program when any one
of the variables which contribute to an expression's value are
modified.

> In current gdb, I can either:
> 1. Set watchpoint on expression, and it will be always deleted, like in above 
> case.
> 2. Set watchpoint on address, and it won't be ever deleted.

I suggested a possible enhancement to watchpoints to do better, but
someone will have to code it (assuming that people agree with my
suggestion).


D:\usr\eli\data>gdb ./dbw.exe
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or 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.
This GDB was configured as "i686-pc-mingw32"...
(gdb) b set
Breakpoint 1 at 0x401293: file dbw.c, line 3.
(gdb) r
Starting program: D:\usr\eli\data/./dbw.exe

Breakpoint 1, set (ptr=0x22ff74) at dbw.c:3
3           *ptr = 10;
(gdb) watch *ptr
Hardware watchpoint 2: *ptr
(gdb) p/x ptr
$1 = 0x22ff74
(gdb) watch *(int *)$1
Hardware watchpoint 3: *(int *) $1
(gdb) c
Continuing.
Hardware watchpoint 2: *ptr

Old value = 2
New value = 10
Hardware watchpoint 4: *(int *) $1

Old value = 2
New value = 10
set (ptr=0x22ff74) at dbw.c:4
4       }
(gdb) c
Continuing.

Watchpoint 2 deleted because the program has left the block in
which its expression is valid.
main () at dbw.c:15
15          modify(&i);
(gdb) c
Continuing.
Hardware watchpoint 4: *(int *) $1

Old value = 10
New value = 15
modify (ptr=0x22ff74) at dbw.c:9
9       }
(gdb) c
Continuing.
Hardware watchpoint 4: *(int *) $1

Old value = 15
New value = 0
0x77c39ebb in msvcrt!_cexit ()
(gdb) c
Continuing.
Hardware watchpoint 4: *(int *) $1

Old value = 0
New value = -1
0x7c81caa9 in KERNEL32!ExitProcess () from C:\WINDOWS\system32\kernel32.dll
(gdb) c
Continuing.

Program exited normally.
(gdb)


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