summaryrefslogtreecommitdiffstats
path: root/Misc
diff options
context:
space:
mode:
authorSkip Montanaro <skip@pobox.com>2005-01-08 21:56:43 (GMT)
committerSkip Montanaro <skip@pobox.com>2005-01-08 21:56:43 (GMT)
commitafd77d980ea68f7286ce6002e4b0c22d28ca8d6f (patch)
tree5e4cabd07e62fa4c4206e86e0a5a0173cd93b711 /Misc
parent9ddb3005986dae244935c670cdd58cc08b09f752 (diff)
downloadcpython-afd77d980ea68f7286ce6002e4b0c22d28ca8d6f.zip
cpython-afd77d980ea68f7286ce6002e4b0c22d28ca8d6f.tar.gz
cpython-afd77d980ea68f7286ce6002e4b0c22d28ca8d6f.tar.bz2
Add definitions for "up" and "down" commands that print/display the current
Python file/line when the current C execution frame is inside PyEval_EvalFrame. These are commented out by default because GDB sometimes crashes as a result (seems like a GDB bug). Add a pyframe command that displays the current Python stack frame. If the marked lines are uncommented, it will also cause Emacs/XEmacs to display the current file/line.
Diffstat (limited to 'Misc')
-rw-r--r--Misc/gdbinit54
1 files changed, 52 insertions, 2 deletions
diff --git a/Misc/gdbinit b/Misc/gdbinit
index 51370e2..42998c9 100644
--- a/Misc/gdbinit
+++ b/Misc/gdbinit
@@ -43,6 +43,28 @@ define pylocals
end
end
+# A rewrite of the Python interpreter's line number calculator in GDB's
+# command language
+define lineno
+ set $__co = f->f_code
+ set $__lasti = f->f_lasti
+ set $__sz = ((PyStringObject *)$__co->co_lnotab)->ob_size/2
+ set $__p = (unsigned char *)((PyStringObject *)$__co->co_lnotab)->ob_sval
+ set $__li = $__co->co_firstlineno
+ set $__ad = 0
+ while ($__sz-1 >= 0)
+ set $__sz = $__sz - 1
+ set $__ad = $__ad + *$__p
+ set $__p = $__p + 1
+ if ($__ad > $__lasti)
+ break
+ end
+ set $__li = $__li + *$__p
+ set $__p = $__p + 1
+ end
+ printf "%d", $__li
+end
+
# print the current frame - verbose
define pyframev
pyframe
@@ -52,7 +74,35 @@ end
define pyframe
set $__fn = (char *)((PyStringObject *)co->co_filename)->ob_sval
set $__n = (char *)((PyStringObject *)co->co_name)->ob_sval
- printf "%s (%d): %s\n", $__fn, f->f_lineno, $__n
+ printf "%s (", $__fn
+ lineno
+ printf "): %s\n", $__n
+### Uncomment these lines when using from within Emacs/XEmacs so it will
+### automatically track/display the current Python source line
+# printf "%c%c%s:", 032, 032, $__fn
+# lineno
+# printf ":1\n"
+end
+
+### Use these at your own risk. It appears that a bug in gdb causes it
+### to crash in certain circumstances.
+
+#define up
+# up-silently 1
+# printframe
+#end
+
+#define down
+# down-silently 1
+# printframe
+#end
+
+define printframe
+ if $pc > PyEval_EvalFrame && $pc < PyEval_EvalCodeEx
+ pyframe
+ else
+ frame
+ end
end
# Here's a somewhat fragile way to print the entire Python stack from gdb.
@@ -64,7 +114,7 @@ end
# 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().
+# statement tests to see if we are in PyEval_EvalFrame().
# print the entire Python call stack
define pystack