This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: test availability of variables in context from user command
- From: "Rob Quill" <rob dot quill at gmail dot com>
- To: "Christophe Demarey" <Christophe dot Demarey at inria dot fr>
- Cc: gdb at sourceware dot org
- Date: Fri, 23 Feb 2007 17:12:29 +0000
- Subject: Re: test availability of variables in context from user command
- 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=
- References: <45DF0F48.60507@inria.fr>
On 23/02/07, Christophe Demarey <Christophe.Demarey@inria.fr> 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.