summaryrefslogtreecommitdiff
path: root/Misc/gdbinit
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2004-03-01 15:44:05 +0000
committerSkip Montanaro <skip@pobox.com>2004-03-01 15:44:05 +0000
commit905460b2da211039da91a5a257c09b91679a132a (patch)
treed5b8144b3789cff68439c1e128dc335795b82393 /Misc/gdbinit
parentcf71f0d6bb74e5725398a655632986b0ca0cd2fa (diff)
downloadcpython-905460b2da211039da91a5a257c09b91679a132a.tar.gz
Add pystack definition to Misc/gdbinit with some explanation of its behavior
and add flag comments to ceval.c and main.c alerting people to the coupling between pystack and the layout of those files.
Diffstat (limited to 'Misc/gdbinit')
-rw-r--r--Misc/gdbinit23
1 files changed, 23 insertions, 0 deletions
diff --git a/Misc/gdbinit b/Misc/gdbinit
index 05f6a9151c..4790adae54 100644
--- a/Misc/gdbinit
+++ b/Misc/gdbinit
@@ -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