bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to test if variable is defined from user-defined command?


From: Skip Montanaro
Subject: How to test if variable is defined from user-defined command?
Date: 25 Aug 2001 10:07:28 -0700

I define a command in .gdbinit to display a Python stack trace:

define ppystack
    set $__fr = 0
    select-frame $__fr
    while $pc < Py_Main || $pc > Py_GetArgcArgv
        if $pc > eval_code2 && $pc < set_exc_info || $pc > eval_code2r && $pc < 
ceval_end
            set $__fn = PyString_AsString(co->co_filename)
            set $__n = PyString_AsString(co->co_name)
            printf "%s (%d): %s\n",  $__fn, f->f_lineno, $__n
        end
        set $__fr = $__fr + 1
        select-frame $__fr
    end
    select-frame 0
end

This works fine unless the stack is a bit bolluxed up, in which case, even
though my test of the range of $pc succeeds, gdb might tell me there is no
variable named "co" in the local scope, bombing out of the stack print at
that point.  Is there a way to test if a variable exists in the local scope
before accessing it?  I'm thinking of something like

    if defined("co")
        do stuff with co->...
    end

but couldn't find anything in the gdb info file.

Thanks,

Skip Montanaro



reply via email to

[Prev in Thread] Current Thread [Next in Thread]