From: Vladimir Prus <ghost@cs.msu.su>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb@sources.redhat.com
Subject: Re: Checking if addess is on stack?
Date: Thu, 20 Apr 2006 16:29:00 -0000 [thread overview]
Message-ID: <200604201931.38519.ghost@cs.msu.su> (raw)
In-Reply-To: <u8xq0wi8g.fsf@gnu.org>
On Thursday 20 April 2006 16:21, Eli Zaretskii wrote:
> > 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.
>
> I think setting a watchpoint on `ptr->i' will do what you want here:
> it will watch _any_ accesses to that address, because GDB actually
> computes the address and places a watchpoint there. So no matter how
> was the address accessed, the watchpoint will trigger.
>
> Do you have any specific examples where this logic does not work? If
> so, please show those examples.
void set(int* ptr)
{
*ptr = 10;
}
void modify(int* ptr)
{
*ptr = 15;
}
int main()
{
int i;
set(&i);
modify(&i);
return 0;
}
I get this debug session with gdb 6.4:
(gdb) b set
Breakpoint 1 at 0x8048397: file main.cpp, line 4.
(gdb) r
Starting program: /tmp/mi/a.out
Breakpoint 1, set (ptr=0xbf967374) at main.cpp:4
4 *ptr = 10;
(gdb) n
5 }
(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.
> > 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.
>
> Well, I thought the trick with tb does the equivalent of what you
> wanted. It automatically inserts the watchpoint when the scope is
> entered, while its deletion is handled by GDB itself. Next time the
> function is entered, GDB will insert the watchpoint again. Isn't that
> what you want, as far as the variable-out-of-scope issue is
> considered? (Whether to watch the address or the expression is a
> different matter, as mentioned above.)
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.
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.
- Volodya
next prev parent reply other threads:[~2006-04-20 15:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-20 10:27 Vladimir Prus
2006-04-20 11:42 ` Eli Zaretskii
2006-04-20 11:48 ` Vladimir Prus
2006-04-20 12:21 ` Eli Zaretskii
2006-04-20 12:49 ` Vladimir Prus
2006-04-20 14:27 ` Eli Zaretskii
2006-04-20 14:39 ` Daniel Jacobowitz
2006-04-20 15:24 ` Eli Zaretskii
2006-04-20 15:32 ` Daniel Jacobowitz
2006-04-20 18:41 ` Eli Zaretskii
2006-04-20 19:12 ` Daniel Jacobowitz
2006-04-21 11:45 ` Eli Zaretskii
2006-04-22 8:06 ` Daniel Jacobowitz
2006-04-20 16:29 ` Vladimir Prus [this message]
2006-04-20 19:03 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200604201931.38519.ghost@cs.msu.su \
--to=ghost@cs.msu.su \
--cc=eliz@gnu.org \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox