[Python-checkins] python/dist/src/Misc gdbinit,1.8,1.9

montanaro at users.sourceforge.net montanaro at users.sourceforge.net
Sat Jan 8 22:57:00 CET 2005


Update of /cvsroot/python/python/dist/src/Misc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21826

Modified Files:
	gdbinit 
Log Message:
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.



Index: gdbinit
===================================================================
RCS file: /cvsroot/python/python/dist/src/Misc/gdbinit,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- gdbinit	17 Nov 2004 16:04:15 -0000	1.8
+++ gdbinit	8 Jan 2005 21:56:43 -0000	1.9
@@ -43,6 +43,28 @@
     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 @@
 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 @@
 # 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



More information about the Python-checkins mailing list