aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python
diff options
context:
space:
mode:
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c34
-rw-r--r--Python/executor.c2
-rw-r--r--Python/optimizer.c2
3 files changed, 30 insertions, 8 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 30f722e45e4..1dc4fd80224 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -109,11 +109,24 @@ dump_stack(_PyInterpreterFrame *frame, PyObject **stack_pointer)
if (ptr != stack_base) {
printf(", ");
}
- if (PyObject_Print(*ptr, stdout, 0) != 0) {
+ if (*ptr == NULL) {
+ printf("<nil>");
+ continue;
+ }
+ if (
+ *ptr == Py_None
+ || PyBool_Check(*ptr)
+ || PyLong_CheckExact(*ptr)
+ || PyFloat_CheckExact(*ptr)
+ || PyUnicode_CheckExact(*ptr)
+ ) {
+ if (PyObject_Print(*ptr, stdout, 0) == 0) {
+ continue;
+ }
PyErr_Clear();
- printf("<%s object at %p>",
- Py_TYPE(*ptr)->tp_name, (void *)(*ptr));
}
+ // Don't call __repr__(), it might recurse into the interpreter.
+ printf("<%s at %p>", Py_TYPE(*ptr)->tp_name, (void *)(*ptr));
}
printf("]\n");
fflush(stdout);
@@ -128,9 +141,6 @@ lltrace_instruction(_PyInterpreterFrame *frame,
if (frame->owner == FRAME_OWNED_BY_CSTACK) {
return;
}
- /* This dump_stack() operation is risky, since the repr() of some
- objects enters the interpreter recursively. It is also slow.
- So you might want to comment it out. */
dump_stack(frame, stack_pointer);
int oparg = next_instr->op.arg;
int opcode = next_instr->op.code;
@@ -729,6 +739,13 @@ resume_frame:
goto exit_unwind;
}
lltrace = r;
+ if (!lltrace) {
+ // When tracing executed uops, also trace bytecode
+ char *uop_debug = Py_GETENV("PYTHONUOPSDEBUG");
+ if (uop_debug != NULL && *uop_debug >= '0') {
+ lltrace = (*uop_debug - '0') >= 4; // TODO: Parse an int and all that
+ }
+ }
}
if (lltrace) {
lltrace_resume_frame(frame);
@@ -896,6 +913,11 @@ exception_unwind:
goto exception_unwind;
}
/* Resume normal execution */
+#ifdef LLTRACE
+ if (lltrace) {
+ lltrace_resume_frame(frame);
+ }
+#endif
DISPATCH();
}
}
diff --git a/Python/executor.c b/Python/executor.c
index 57525df202d..4a18618c0c6 100644
--- a/Python/executor.c
+++ b/Python/executor.c
@@ -41,7 +41,7 @@ _PyUopExecute(_PyExecutorObject *executor, _PyInterpreterFrame *frame, PyObject
lltrace = *uop_debug - '0'; // TODO: Parse an int and all that
}
#define DPRINTF(level, ...) \
- if (lltrace >= (level)) { fprintf(stderr, __VA_ARGS__); }
+ if (lltrace >= (level)) { printf(__VA_ARGS__); }
#else
#define DPRINTF(level, ...)
#endif
diff --git a/Python/optimizer.c b/Python/optimizer.c
index d2ed8dfcd2c..6c730aa14b9 100644
--- a/Python/optimizer.c
+++ b/Python/optimizer.c
@@ -391,7 +391,7 @@ translate_bytecode_to_trace(
#ifdef Py_DEBUG
#define DPRINTF(level, ...) \
- if (lltrace >= (level)) { fprintf(stderr, __VA_ARGS__); }
+ if (lltrace >= (level)) { printf(__VA_ARGS__); }
#else
#define DPRINTF(level, ...)
#endif