mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
- New function sys.call_tracing() allows pdb to debug code
recursively. - pdb has a new command, "debug", which lets you step through arbitrary code from the debugger's (pdb) prompt.
This commit is contained in:
parent
12dd7b12c6
commit
a12fe4e81f
5 changed files with 78 additions and 0 deletions
|
@ -3024,6 +3024,24 @@ call_trace(Py_tracefunc func, PyObject *obj, PyFrameObject *frame,
|
|||
return result;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_PyEval_CallTracing(PyObject *func, PyObject *args)
|
||||
{
|
||||
PyFrameObject *frame = PyEval_GetFrame();
|
||||
PyThreadState *tstate = frame->f_tstate;
|
||||
int save_tracing = tstate->tracing;
|
||||
int save_use_tracing = tstate->use_tracing;
|
||||
PyObject *result;
|
||||
|
||||
tstate->tracing = 0;
|
||||
tstate->use_tracing = ((tstate->c_tracefunc != NULL)
|
||||
|| (tstate->c_profilefunc != NULL));
|
||||
result = PyObject_Call(func, args, NULL);
|
||||
tstate->tracing = save_tracing;
|
||||
tstate->use_tracing = save_use_tracing;
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
|
||||
PyFrameObject *frame, int *instr_lb, int *instr_ub)
|
||||
|
|
|
@ -17,6 +17,7 @@ Data members:
|
|||
#include "Python.h"
|
||||
#include "compile.h"
|
||||
#include "frameobject.h"
|
||||
#include "eval.h"
|
||||
|
||||
#include "osdefs.h"
|
||||
|
||||
|
@ -609,6 +610,23 @@ sys_getframe(PyObject *self, PyObject *args)
|
|||
return (PyObject*)f;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(call_tracing_doc,
|
||||
"call_tracing(func, args) -> object\n\
|
||||
\n\
|
||||
Call func(*args), while tracing is enabled. The tracing state is\n\
|
||||
saved, and restored afterwards. This is intended to be called from\n\
|
||||
a debugger from a checkpoint, to recursively debug some other code."
|
||||
);
|
||||
|
||||
static PyObject *
|
||||
sys_call_tracing(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *func, *funcargs;
|
||||
if (!PyArg_ParseTuple(args, "OO:call_tracing", &func, &funcargs))
|
||||
return NULL;
|
||||
return _PyEval_CallTracing(func, funcargs);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(callstats_doc,
|
||||
"callstats() -> tuple of integers\n\
|
||||
\n\
|
||||
|
@ -700,6 +718,7 @@ static PyMethodDef sys_methods[] = {
|
|||
{"setrecursionlimit", sys_setrecursionlimit, METH_VARARGS,
|
||||
setrecursionlimit_doc},
|
||||
{"settrace", sys_settrace, METH_O, settrace_doc},
|
||||
{"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue