Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* test availability of variables in context from user command
@ 2007-02-23 17:37 Christophe Demarey
  2007-02-23 18:16 ` Rob Quill
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Christophe Demarey @ 2007-02-23 17:37 UTC (permalink / raw)
  To: gdb

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?

Thanks,
Christophe.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: test availability of variables in context from user command
  2007-02-23 17:37 test availability of variables in context from user command Christophe Demarey
@ 2007-02-23 18:16 ` Rob Quill
  2007-02-23 19:56   ` Christophe Demarey
  2007-02-23 19:50 ` Daniel Jacobowitz
  2007-02-24  8:24 ` Michael Snyder
  2 siblings, 1 reply; 5+ messages in thread
From: Rob Quill @ 2007-02-23 18:16 UTC (permalink / raw)
  To: Christophe Demarey; +Cc: gdb

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.
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: test availability of variables in context from user command
  2007-02-23 17:37 test availability of variables in context from user command Christophe Demarey
  2007-02-23 18:16 ` Rob Quill
@ 2007-02-23 19:50 ` Daniel Jacobowitz
  2007-02-24  8:24 ` Michael Snyder
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2007-02-23 19:50 UTC (permalink / raw)
  To: Christophe Demarey; +Cc: gdb

On Fri, Feb 23, 2007 at 04:59:04PM +0100, Christophe Demarey wrote:
> Is there a way to do this with gdb?

Roughly, no, there isn't - yet.  We're discussing adding a full
scripting language, which will be more powerful than the CLI.

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: test availability of variables in context from user command
  2007-02-23 18:16 ` Rob Quill
@ 2007-02-23 19:56   ` Christophe Demarey
  0 siblings, 0 replies; 5+ messages in thread
From: Christophe Demarey @ 2007-02-23 19:56 UTC (permalink / raw)
  To: Rob Quill, drow; +Cc: gdb

Rob Quill wrote:
> 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.
It's exactly what I want to check.
> 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.
Unfortunately, this solution doesn't fit our needs because our gdb user 
commands will crash on non-patched gdb versions.
But I think it should be a good idea to have a such integrated 
functionality (a full scripting language too).

Thanks a lot for your answers.

Regards,
Christophe.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: test availability of variables in context from user command
  2007-02-23 17:37 test availability of variables in context from user command Christophe Demarey
  2007-02-23 18:16 ` Rob Quill
  2007-02-23 19:50 ` Daniel Jacobowitz
@ 2007-02-24  8:24 ` Michael Snyder
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Snyder @ 2007-02-24  8:24 UTC (permalink / raw)
  To: Christophe Demarey; +Cc: gdb

On Fri, 2007-02-23 at 16:59 +0100, 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.

Just interjecting a thought -- it would be nice if gdb had a
"which" command.  It could not only tell you whether an identifier
was in scope, but tell you WHICH scope it was in.  Could be useful,
for instance, to tell you that a local was over-shadowing a global.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-02-23 19:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-23 17:37 test availability of variables in context from user command Christophe Demarey
2007-02-23 18:16 ` Rob Quill
2007-02-23 19:56   ` Christophe Demarey
2007-02-23 19:50 ` Daniel Jacobowitz
2007-02-24  8:24 ` Michael Snyder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox