From: "Rob Quill" <rob.quill@gmail.com>
To: "Christophe Demarey" <Christophe.Demarey@inria.fr>
Cc: gdb@sourceware.org
Subject: Re: test availability of variables in context from user command
Date: Fri, 23 Feb 2007 18:16:00 -0000 [thread overview]
Message-ID: <baf6008d0702230912w10f053e1s260da745ee27dc9a@mail.gmail.com> (raw)
In-Reply-To: <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.
>
next prev parent reply other threads:[~2007-02-23 17:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-23 17:37 Christophe Demarey
2007-02-23 18:16 ` Rob Quill [this message]
2007-02-23 19:56 ` Christophe Demarey
2007-02-23 19:50 ` Daniel Jacobowitz
2007-02-24 8:24 ` Michael Snyder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=baf6008d0702230912w10f053e1s260da745ee27dc9a@mail.gmail.com \
--to=rob.quill@gmail.com \
--cc=Christophe.Demarey@inria.fr \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox