From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28675 invoked by alias); 12 Apr 2006 16:36:07 -0000 Received: (qmail 28666 invoked by uid 22791); 12 Apr 2006 16:36:06 -0000 X-Spam-Check-By: sourceware.org Received: from mail-out3.apple.com (HELO mail-out3.apple.com) (17.254.13.22) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 12 Apr 2006 16:36:04 +0000 Received: from relay6.apple.com (relay6.apple.com [17.128.113.36]) by mail-out3.apple.com (8.12.11/8.12.11) with ESMTP id k3CGZgAe026688; Wed, 12 Apr 2006 09:35:42 -0700 (PDT) Received: from [17.201.22.240] (unknown [17.201.22.240]) by relay6.apple.com (Apple SCV relay) with ESMTP id C17E4171; Wed, 12 Apr 2006 09:35:42 -0700 (PDT) In-Reply-To: References: Mime-Version: 1.0 (Apple Message framework v749.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <1A00C3C1-BDF5-489E-A36A-A1E5C20E102A@apple.com> Cc: gdb@sources.redhat.com Content-Transfer-Encoding: 7bit From: Jim Ingham Subject: Re: -var-update and address changes Date: Wed, 12 Apr 2006 18:25:00 -0000 To: Vladimir Prus X-Mailer: Apple Mail (2.749.3) 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/msg00146.txt.bz2 On Apr 12, 2006, at 5:04 AM, Vladimir Prus wrote: > > Hi, > I'm running into what looks like a bug in -var-update. Basically, I > create a > varobj with "&variable", then I enter a function that has a > variable with > the same name, and -var-update does not report anything. > > Here's the code, and the gdb session. > > int foo() > { > int i = 10; > ++i; > return i; > } > > int main() > { > int i = 10; > i = foo(); > return i; > } > > And here's the session > > -break-insert a.cpp:12 > ^done,.... > (gdb) > -break-insert a.cpp:5 > ^done,.... > (gdb) > -exec-run > ^running > (gdb) > *stopped,reason="breakpoint-hit",..... > (gdb) > -var-create TEST * &i > ^done,name="TEST",numchild="1",type="int *" > (gdb) > -exec-continue > ^running > (gdb) > *stopped,reason="breakpoint-hit",....... > (gdb) > -var-update * > ^done,changelist=[] > (gdb) > > The value of "&i" changes, but -var-update does not report this. > This can be > explained by the fact that varobjs are "bound" to the stack frame > where > they were created, but that "binding" is not mentioned in > documentation. > > The problem I'm trying to solve is this: > 1. In some frame, I create varobj for 'i'. > 2. After continue, I see that there's local variable 'i', and I > want to find > out if previously-created varobj can be used to show this local > 'i', or if > I should create new 'i'. > > - I can't use frame ids because gdb only prints code address, > and two > different stack frames can have the same code address. > - I can't use -var-update, because it does not seem to report > anything > - I can't use -var-update on variable addresses, because of the > above > report > > So, the only solution is to remove all varobjs, and create them > afresh, > which is contrary to the very purpose of varobjs. > > Can somebody suggest the right fix? So far, I think that the simplest > approach is to make gdb print stack address of current frame, like > is done > on the Apple branch: > > 553^done,stack=[frame= > {level="0",addr="0x00003db0",fp="0xbffff2c0",...... > > That way, frontend can deal with the issue of frame stacks > themself, and > -var-update will be only used when single-stepping inside a given > frame. > Will patches to implement this be welcome? That's what I would suggest. It seemed the simplest way to handle this when we were first thinking about it. > > And I still don't know what to do about variable shadowing inside a > single > function. I added another option to -stack-list-locals to print all the blocks in a given function. Using this plus the option to have -stack-list- locals return variable object, you will get all the shadowed variables in the function as varobj's when you enter the function. Then the varobj system will tell you which of these are in and out of scope at any given PC. We also tell what the valid block is, but Xcode doesn't use this info at present. This all works in our branch if you want to see one example of how to do it. Jim