From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2283 invoked by alias); 23 Feb 2007 17:12:48 -0000 Received: (qmail 2258 invoked by uid 22791); 23 Feb 2007 17:12:48 -0000 X-Spam-Check-By: sourceware.org Received: from wr-out-0506.google.com (HELO wr-out-0506.google.com) (64.233.184.227) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 23 Feb 2007 17:12:31 +0000 Received: by wr-out-0506.google.com with SMTP id 55so893489wri for ; Fri, 23 Feb 2007 09:12:29 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=P0c9V28GLyUz+ixiq41QinOKVZJB571iNkG5Sr/3dgNMnie8hXHiHV46ptexBMdIstvsuxAF/KvMNLYtWfSnRXbEsPeL/VARvNWR7TEWvERCUYcc6rDwo6lJB2aG3bb92fGeiALatcbANyG5T3iy/iiISPm9NVYgDi83lydMhsU= Received: by 10.114.111.1 with SMTP id j1mr1071100wac.1172250749329; Fri, 23 Feb 2007 09:12:29 -0800 (PST) Received: by 10.114.95.11 with HTTP; Fri, 23 Feb 2007 09:12:29 -0800 (PST) Message-ID: Date: Fri, 23 Feb 2007 18:16:00 -0000 From: "Rob Quill" To: "Christophe Demarey" Subject: Re: test availability of variables in context from user command Cc: gdb@sourceware.org In-Reply-To: <45DF0F48.60507@inria.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <45DF0F48.60507@inria.fr> 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: 2007-02/txt/msg00249.txt.bz2 On 23/02/07, Christophe Demarey wrote: > Hello, > > I want to check the availability of a variable (var1 for instance) in > the context from an user command but I don't find any way to do this. > Here is a (dummy) example of what I want to do : > > void func1(void) > { > int var2 = 2; > ... > } > > int main(int argc, char **argv) > { > int var1 = 1; > > ... > func1(); > } > > My gdb command: > define myfunc > if defined(var1) > $res = $var1 > else > $res = $var2 > end > ... > end > > If I break into main, res should be equals to 1, else res should be > equals to 2. > > Is there a way to do this with gdb? I modifed GDB to make in possible to cehck whether variables are in scope. I'm not sure if that's what you want, but you can do things like: print $in_scope(var1); or in a command file: if($in_scope(var1) == 1) i.e. do something if var1 is in scope. At the moment it only covers certain cases as I haven't had time to finish it off, but it wouldn't be hard to do. I modified it against 6.6, but hopefully I can forge a patch out of it, if you want it. I've never made a patch before, but I'm sure I'll figure it out. Rob > > Thanks, > Christophe. >