From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5214 invoked by alias); 20 Apr 2006 15:32:07 -0000 Received: (qmail 5205 invoked by uid 22791); 20 Apr 2006 15:32:06 -0000 X-Spam-Check-By: sourceware.org Received: from zigzag.lvk.cs.msu.su (HELO zigzag.lvk.cs.msu.su) (158.250.17.23) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 20 Apr 2006 15:32:02 +0000 Received: from Debian-exim by zigzag.lvk.cs.msu.su with spam-scanned (Exim 4.50) id 1FWb8M-0003Qf-2H for gdb@sources.redhat.com; Thu, 20 Apr 2006 19:31:59 +0400 Received: from zigzag.lvk.cs.msu.su ([158.250.17.23]) by zigzag.lvk.cs.msu.su with esmtp (Exim 4.50) id 1FWb8A-0003Nw-3F; Thu, 20 Apr 2006 19:31:42 +0400 From: Vladimir Prus To: Eli Zaretskii Subject: Re: Checking if addess is on stack? Date: Thu, 20 Apr 2006 16:29:00 -0000 User-Agent: KMail/1.7.2 Cc: gdb@sources.redhat.com References: <200604201548.36899.ghost@cs.msu.su> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200604201931.38519.ghost@cs.msu.su> Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2006-04/txt/msg00276.txt.bz2 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