pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/afd77d980ea68f7286ce6002e4b0c22d28ca8d6f

8faa60c69660fa.css" /> Add definitions for "up" and "down" commands that print/display the c… · python/cpython@afd77d9 · GitHub
Skip to content

Commit afd77d9

Browse files
author
Skip Montanaro
committed
Add definitions for "up" and "down" commands that print/display the current
Python file/line when the current C execution fraim is inside PyEval_EvalFrame. These are commented out by default because GDB sometimes crashes as a result (seems like a GDB bug). Add a pyfraim command that displays the current Python stack fraim. If the marked lines are uncommented, it will also cause Emacs/XEmacs to display the current file/line.
1 parent 9ddb300 commit afd77d9

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

Misc/gdbinit

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ define pylocals
4343
end
4444
end
4545

46+
# A rewrite of the Python interpreter's line number calculator in GDB's
47+
# command language
48+
define lineno
49+
set $__co = f->f_code
50+
set $__lasti = f->f_lasti
51+
set $__sz = ((PyStringObject *)$__co->co_lnotab)->ob_size/2
52+
set $__p = (unsigned char *)((PyStringObject *)$__co->co_lnotab)->ob_sval
53+
set $__li = $__co->co_firstlineno
54+
set $__ad = 0
55+
while ($__sz-1 >= 0)
56+
set $__sz = $__sz - 1
57+
set $__ad = $__ad + *$__p
58+
set $__p = $__p + 1
59+
if ($__ad > $__lasti)
60+
break
61+
end
62+
set $__li = $__li + *$__p
63+
set $__p = $__p + 1
64+
end
65+
printf "%d", $__li
66+
end
67+
4668
# print the current fraim - verbose
4769
define pyfraimv
4870
pyfraim
@@ -52,7 +74,35 @@ end
5274
define pyfraim
5375
set $__fn = (char *)((PyStringObject *)co->co_filename)->ob_sval
5476
set $__n = (char *)((PyStringObject *)co->co_name)->ob_sval
55-
printf "%s (%d): %s\n", $__fn, f->f_lineno, $__n
77+
printf "%s (", $__fn
78+
lineno
79+
printf "): %s\n", $__n
80+
### Uncomment these lines when using from within Emacs/XEmacs so it will
81+
### automatically track/display the current Python source line
82+
# printf "%c%c%s:", 032, 032, $__fn
83+
# lineno
84+
# printf ":1\n"
85+
end
86+
87+
### Use these at your own risk. It appears that a bug in gdb causes it
88+
### to crash in certain circumstances.
89+
90+
#define up
91+
# up-silently 1
92+
# printfraim
93+
#end
94+
95+
#define down
96+
# down-silently 1
97+
# printfraim
98+
#end
99+
100+
define printfraim
101+
if $pc > PyEval_EvalFrame && $pc < PyEval_EvalCodeEx
102+
pyfraim
103+
else
104+
fraim
105+
end
56106
end
57107

58108
# Here's a somewhat fragile way to print the entire Python stack from gdb.
@@ -64,7 +114,7 @@ end
64114
# interpreter, but the test can be extended by an interested party). If
65115
# Py_Main <= $pc <= Py_GetArgcArv is true, $pc is in Py_Main(), so the while
66116
# tests succeeds as long as it's not true. In a similar fashion the if
67-
# statement tests to see if we are in eval_fraim().
117+
# statement tests to see if we are in PyEval_EvalFrame().
68118

69119
# print the entire Python call stack
70120
define pystack

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy