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: Checking if addess is on stack?

> Date: Thu, 20 Apr 2006 10:39:44 -0400
> From: Daniel Jacobowitz <>
> Everything's clearer with code!

It is, thanks.

> struct kind {
>   int i;
> };
> void func1 (void)
> {
>   struct kind kin;
>   func2 (&kin);
> }
> void func2 (struct kind *my_kin)
> {
>   struct kind *ptr = my_kin;
>   /* HERE */
> }
> We're at HERE.  I believe that what Vladimir wants is:
>   (A) a watchpoint on the value referenced by ptr->i, at the moment,
>       regardless of future changes to ptr.  I do this all the time
>       and wouldn't mind an easier way, but it's just:
>          print &ptr->i
>          watch *$31
>       (Where $31 is the right number.

But "watch ptr->i" already does that for you.  Except that it _also_
watches &ptr, and that latter address is what goes out of scope when
we leave func2.

>   (B) For that watchpoint to go out of scope when kin.i, the underlying
>       object, dies.

So perhaps we need to modify the watchpoint machinery so that when
func2 returns, we stop watching the parts of the expression that are
popped from the stack, but continue watching those which are still
valid and in scope.  Would that make sense?

>       Put this way, it's apparent that there is really no way to do
>       this.

I think it can be achieved with setting 2 watchpoints: one on
"ptr->i", the other on the address it points to.

>       -> Would that actually be neat and useful for the CLI?
> (gdb) print $31
> $32 = (int *) 0x44444444 <kin.i in frame #3>

Doesn't "info symbol $31" do this already?

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