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);
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;
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);
goto exception_unwind;
}
/* Resume normal execution */
+#ifdef LLTRACE
+ if (lltrace) {
+ lltrace_resume_frame(frame);
+ }
+#endif
DISPATCH();
}
}
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
#ifdef Py_DEBUG
#define DPRINTF(level, ...) \
- if (lltrace >= (level)) { fprintf(stderr, __VA_ARGS__); }
+ if (lltrace >= (level)) { printf(__VA_ARGS__); }
#else
#define DPRINTF(level, ...)
#endif