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

_______________________________________________
Bug-gdb mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-gdb

Reply via email to