This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: test availability of variables in context from user command


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.



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]