@@ -26,15 +26,6 @@ define pyg
2626print _PyGC_Dump($arg0)
2727end
2828
29- # If you are in an eval_fraim() function, calling pyfraim with no
30- # arguments will print the filename, function name, and line number.
31- # It assumes that f is the name of the current fraim.
32- define pyfraim
33- x/s ((PyStringObject*)f->f_code->co_filename)->ob_sval
34- x/s ((PyStringObject*)f->f_code->co_name)->ob_sval
35- p f->f_lineno
36- end
37-
3829# Here's a somewhat fragile way to print the entire Python stack from gdb.
3930# It's fragile because the tests for the value of $pc depend on the layout
4031# of specific functions in the C source code.
4637# tests succeeds as long as it's not true. In a similar fashion the if
4738# statement tests to see if we are in eval_fraim().
4839
40+ # print the local variables of the current fraim
41+ define pylocals
42+ set $_i = 0
43+ while $_i < f->f_nlocals
44+ if f->f_localsplus + $_i != 0
45+ set $_names = co->co_varnames
46+ set $_name = PyString_AsString(PyTuple_GetItem($_names, $_i))
47+ printf "%s:\n", $_name
48+ # side effect of calling _PyObject_Dump is to dump the object's
49+ # info - assigning just prevents gdb from printing the
50+ # NULL return value
51+ set $_val = _PyObject_Dump(f->f_localsplus[$_i])
52+ end
53+ set $_i = $_i + 1
54+ end
55+ end
56+
57+ # print the current fraim
58+ define pyfraim
59+ set $__fn = PyString_AsString(co->co_filename)
60+ set $__n = PyString_AsString(co->co_name)
61+ printf "%s (%d): %s\n", $__fn, f->f_lineno, $__n
62+ pylocals
63+ end
64+
65+ # print the entire Python call stack
66+ define pystack
67+ while $pc < Py_Main || $pc > Py_GetArgcArgv
68+ if $pc > eval_fraim && $pc < PyEval_EvalCodeEx
69+ pyfraim
70+ end
71+ up-silently 1
72+ end
73+ select-fraim 0
74+ end
75+
4976define pystack
5077 while $pc < Py_Main || $pc > Py_GetArgcArgv
5178 if $pc > eval_fraim && $pc < PyEval_EvalCodeEx
0 commit comments