Re: breakpoint for accessing memory location

Daniel Jacobowitz
2006-10-21T15:51:32Z

On Sat, Oct 21, 2006 at 05:29:11PM +0200, Eli Zaretskii wrote:
> > Date: Sat, 21 Oct 2006 10:06:00 -0500
> > From: "Rodney M. Bates" <rodney.bates@wichita.edu>
> > CC: gdb@sourceware.org
> >
> > But while this subject is open, I would like to see more explanation on just
> > what the semantics of evaluating a watchpoint expression are. An expression
> > always is evaluated in a particular context that can affect the legality/result,
> > but in the case of a watchpoint, execution is proceeding and changing the
> > context. I have never been sure what the rules are.
> > For example, I sometimes want to watch p->f, where p is local variable that
> > I know perfectly well will soon cease to exist, but I also know *p will
> > remain. I've long since learned that watching p->f doesn't work. Instead,
> > I print the address of p->f and then watch the contents of that address.
>
> Does "watch *(<type-of-p->f> *)&p->f" work as well?

I'm pretty sure it won't. Because "p" is still in the expression, we
consider the expression dependent on the value of p, so it goes out of
scope when p does.

I use:
p &p->f
watch *$

--
Daniel Jacobowitz
CodeSourcery