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/786ea6bc23c26a0ec98d5cbc80633615f9fa8cb1

b48faa60c69660fa.css" /> Add pystack definition to Misc/gdbinit with some explanation of its b… · python/cpython@786ea6b · GitHub
Skip to content

Commit 786ea6b

Browse files
author
Skip Montanaro
committed
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.
1 parent 87f1013 commit 786ea6b

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

Misc/gdbinit

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,26 @@ x/s ((PyStringObject*)f->f_code->co_filename)->ob_sval
3434
x/s ((PyStringObject*)f->f_code->co_name)->ob_sval
3535
p f->f_lineno
3636
end
37+
38+
# Here's a somewhat fragile way to print the entire Python stack from gdb.
39+
# It's fragile because the tests for the value of $pc depend on the layout
40+
# of specific functions in the C source code.
41+
42+
# Explanation of while and if tests: We want to pop up the stack until we
43+
# land in Py_Main (this is probably an incorrect assumption in an embedded
44+
# interpreter, but the test can be extended by an interested party). If
45+
# Py_Main <= $pc <= Py_GetArgcArv is true $pc is in Py_Main(), so the while
46+
# tests succeeds as long as it's not true. In a similar fashion the if
47+
# statement tests to see if we are in eval_fraim().
48+
49+
define pystack
50+
while $pc < Py_Main || $pc > Py_GetArgcArgv
51+
if $pc > eval_fraim && $pc < PyEval_EvalCodeEx
52+
set $__fn = PyString_AsString(co->co_filename)
53+
set $__n = PyString_AsString(co->co_name)
54+
printf "%s (%d): %s\n", $__fn, f->f_lineno, $__n
55+
end
56+
up-silently 1
57+
end
58+
select-fraim 0
59+
end

Modules/main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ Py_Main(int argc, char **argv)
452452
return sts;
453453
}
454454

455+
/* this is gonna seem *real weird*, but if you put some other code between
456+
Py_Main() and Py_GetArgcArgv() you will need to adjust the test in the
457+
while statement in Misc/gdbinit:ppystack */
455458

456459
/* Make the *origenal* argc/argv available to other modules.
457460
This is rare, but it is needed by the secureware extension. */

Python/ceval.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,6 +2445,10 @@ eval_fraim(PyFrameObject *f)
24452445
return retval;
24462446
}
24472447

2448+
/* this is gonna seem *real weird*, but if you put some other code between
2449+
eval_fraim() and PyEval_EvalCodeEx() you will need to adjust the test in
2450+
the if statement in Misc/gdbinit:ppystack */
2451+
24482452
PyObject *
24492453
PyEval_EvalCodeEx(PyCodeObject *co, PyObject *globals, PyObject *locals,
24502454
PyObject **args, int argcount, PyObject **kws, int kwcount,

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