From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4173 invoked by alias); 20 Apr 2006 14:39:54 -0000 Received: (qmail 4162 invoked by uid 22791); 20 Apr 2006 14:39:52 -0000 X-Spam-Check-By: sourceware.org Received: from nevyn.them.org (HELO nevyn.them.org) (66.93.172.17) by sourceware.org (qpsmtpd/0.31.1) with ESMTP; Thu, 20 Apr 2006 14:39:46 +0000 Received: from drow by nevyn.them.org with local (Exim 4.54) id 1FWaJs-0003m4-PI for gdb@sourceware.org; Thu, 20 Apr 2006 10:39:44 -0400 Date: Thu, 20 Apr 2006 15:32:00 -0000 From: Daniel Jacobowitz To: gdb@sourceware.org Subject: Re: Checking if addess is on stack? Message-ID: <20060420143944.GA14255@nevyn.them.org> Mail-Followup-To: gdb@sourceware.org References: <200604201426.59360.ghost@cs.msu.su> <200604201548.36899.ghost@cs.msu.su> <20060420124903.GA11015@nevyn.them.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.8i X-IsSubscribed: yes 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/msg00274.txt.bz2 On Thu, Apr 20, 2006 at 05:27:51PM +0300, Eli Zaretskii wrote: > > Date: Thu, 20 Apr 2006 08:49:04 -0400 > > From: Daniel Jacobowitz > > > > What he wants is not to stop the watchpoint when ptr goes out of scope, > > but when ptr->i goes out of scope - if ptr points to a stack allocated > > variable, in this function or another one. > > Sorry, I'm probably too dumb and so am still in the woods--could you > provide an example of such a situation? > > Specifically, where is ptr allocated--is it itself on the stack or > somewhere else? Everything's clearer with code! Let's try this. 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. DON'T try "watch *$"! It will re-evaluate the expression when you next stop and get a different value for $ !) (B) For that watchpoint to go out of scope when kin.i, the underlying object, dies. Put this way, it's apparent that there is really no way to do this. We could approximate it; we could figure out that it belonged to a frame, but not its scope within that frame. Well, I suppose we could... we could calculate the addresses of all locals of that frame within the current block and work out inside which one it was. -> Would that actually be neat and useful for the CLI? (gdb) print $31 $32 = (int *) 0x44444444 -- Daniel Jacobowitz CodeSourcery