From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20237 invoked by alias); 28 Nov 2006 11:47:06 -0000 Received: (qmail 20221 invoked by uid 22791); 28 Nov 2006 11:47:04 -0000 X-Spam-Check-By: sourceware.org Received: from wx-out-0506.google.com (HELO wx-out-0506.google.com) (66.249.82.239) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 28 Nov 2006 11:46:57 +0000 Received: by wx-out-0506.google.com with SMTP id h26so2055710wxd for ; Tue, 28 Nov 2006 03:46:56 -0800 (PST) Received: by 10.70.131.19 with SMTP id e19mr1505391wxd.1164714415835; Tue, 28 Nov 2006 03:46:55 -0800 (PST) Received: by 10.70.12.7 with HTTP; Tue, 28 Nov 2006 03:46:55 -0800 (PST) Message-ID: Date: Tue, 28 Nov 2006 11:47:00 -0000 From: "Rob Quill" To: "Jim Blandy" Subject: Re: Checking variable scope Cc: gdb@sourceware.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-IsSubscribed: yes Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2006-11/txt/msg00195.txt.bz2 On 27/11/06, Jim Blandy wrote: > > "Rob Quill" writes: > > I am stepping through the program, so I suppose I'd be looking to see > > if the variable is in scope at the location of the PC. > > > > How would I call lookup_symbol, given that information? I had a brief > > look, but I wasn't sure what parameters to pass to the function, or > > how to get the right values. > > You can pass NULL for 'symtab' and 'is_a_field_of_this', and > VAR_DOMAIN for domain. block is the scoping block containing the PC. > I don't know where you're calling things from, so I can't really tell > you how to get the current PC. > The aim would be to add a command to gdb, in_scope (or similar) which can be used from a GDB script to check if a variable is in scope without throwing an error if is isn't. As currently if I do "print a" and a is not in scope then I get an error and the script stops, which is fine. But even better would be if I were able to check if a was in scope and only print (or do other things with it) if it was. Does that help explain where I would be calling things from? As I understand it, current when you do "print a" it tries to parse a, as it is possible to print expressions etc, and when is parsing in, in exp_c.y, it throws errors if the variable is not in scope. So currently my code sets a global variable check_scope, and in exp_c.y, if check_scope is 1, then an internal variable is set if the variable is not in scope, and an _error() is thrown, with an empty string, and when running a script and an error is encountered, if the error message is the empty string then the error is ignored. Obviously this is not a particularly neat way of doing it, and I'm sure there is a better way, so any help is appreciated. Thanks Rob