]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add pystack definition to Misc/gdbinit with some explanation of its behavior
authorSkip Montanaro <skip@pobox.com>
Mon, 1 Mar 2004 15:44:05 +0000 (15:44 +0000)
committerSkip Montanaro <skip@pobox.com>
Mon, 1 Mar 2004 15:44:05 +0000 (15:44 +0000)
and add flag comments to ceval.c and main.c alerting people to the coupling
between pystack and the layout of those files.

Misc/gdbinit
Modules/main.c
Python/ceval.c

index 05f6a9151c59313e3cd30ce8653f0edc0008ebe1..4790adae54cfc78f82d4e1f084ade0d5a1cf94f9 100644 (file)
@@ -34,3 +34,26 @@ x/s ((PyStringObject*)f->f_code->co_filename)->ob_sval
 x/s ((PyStringObject*)f->f_code->co_name)->ob_sval
 p f->f_lineno
 end
+
+# Here's a somewhat fragile way to print the entire Python stack from gdb.
+# It's fragile because the tests for the value of $pc depend on the layout
+# of specific functions in the C source code.
+
+# Explanation of while and if tests: We want to pop up the stack until we
+# land in Py_Main (this is probably an incorrect assumption in an embedded
+# interpreter, but the test can be extended by an interested party).  If
+# Py_Main <= $pc <= Py_GetArgcArv is true $pc is in Py_Main(), so the while
+# tests succeeds as long as it's not true.  In a similar fashion the if
+# statement tests to see if we are in eval_frame().
+
+define pystack
+    while $pc < Py_Main || $pc > Py_GetArgcArgv
+        if $pc > eval_frame && $pc < PyEval_EvalCodeEx
+            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
+        up-silently 1
+    end
+    select-frame 0
+end
index 68a82c7be372f499870ae32a995633700ec35f2b..fc5773c07fbbb58c717f8ed1116ea643f354b0ce 100644 (file)
@@ -452,6 +452,9 @@ Py_Main(int argc, char **argv)
        return sts;
 }
 
+/* this is gonna seem *real weird*, but if you put some other code between
+   Py_Main() and Py_GetArgcArgv() you will need to adjust the test in the
+   while statement in Misc/gdbinit:ppystack */
 
 /* Make the *original* argc/argv available to other modules.
    This is rare, but it is needed by the secureware extension. */
index c6fb0bf7e5498aad12e462769710d579a960295a..337184464f1334157acec97537de3707434716ae 100644 (file)
@@ -2445,6 +2445,10 @@ fast_yield:
        return retval;
 }
 
+/* this is gonna seem *real weird*, but if you put some other code between
+   eval_frame() and PyEval_EvalCodeEx() you will need to adjust the test in
+   the if statement in Misc/gdbinit:ppystack */
+
 PyObject *
 PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
           PyObject **args, int argcount, PyObject **kws, int kwcount,