This is the mail archive of the
mailing list for the GDB project.
Re: Checking if addess is on stack?
On Thursday 20 April 2006 15:42, Eli Zaretskii wrote:
> > From: Vladimir Prus <email@example.com>
> > Date: Thu, 20 Apr 2006 14:26:58 +0400
> > Cc: firstname.lastname@example.org
> > I'm not sure that's exactly what I need. This way, watchpoint will be
> > automatically inserted when I enter 'do_that', but as soon as I leave
> > 'do_that', gdb will remove wathchpoint because 'ptr' has gone out of
> > scope. This will prevent me from catching accesses to ptr->i made outside
> > of the function where 'ptr' is valid. Am I missing something?
> Perhaps _I_ am missing something. Isn't `ptr' a variable that is
> local to the function `do_that'? I thought it was; if so, then it
> couldn't possibly be accessed after `do_that' returns, because all
> locals are popped off the stack when `do_that' returns. These locals
> will get entirely new values when `do_that' is entered the next time.
> (If you want to catch accesses to the address where `ptr' _was_ on the
> stack, then you really need to set the wathchpoint on an absolute
Precisely, I want to catch accesses to a specific address, and I want that to
be the only (or at least default) behaviour in KDevelop. That is, if user
types in any expression, KDevelop will compute the address of that expression
and set watchpoint on address.
The rationale is that in the case I've given:
void do_that(My_class* ptr)
ptr->i = .....;
user most likely wants to catch all future accesses to variable 'i', and does
not care if those accesses go via 'ptr' in 'do_that', or via some other
pointer variable in some other function.
> But watching addresses on the stack beyond the stack top is
> a very unusual thing to do, so I don't think this is what your users
> would need.)
Exactly, so I want to detect the case where address in on the stack, and in
that case disable the watchpoint when function exists. But there's no easy
way to detect if address is on stack, and that's the problem.