Skip to content

Commit 6ab4a24

Browse files
committed
Use tagged refs and dump more info in lltrace
1 parent 473914c commit 6ab4a24

File tree

5 files changed

+45
-27
lines changed

5 files changed

+45
-27
lines changed

Python/bytecodes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ dummy_func(
244244

245245
inst(LOAD_FAST_DEFERRED, (-- value)) {
246246
assert(!PyStackRef_IsNull(GETLOCAL(oparg)));
247-
value = PyStackRef_DUP(GETLOCAL(oparg));
247+
value = GETLOCAL(oparg);
248+
value.bits |= Py_TAG_REFCNT;
248249
}
249250

250251
inst(LOAD_FAST_AND_CLEAR, (-- value)) {

Python/ceval.c

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -136,39 +136,53 @@
136136

137137

138138
#ifdef LLTRACE
139+
static void print_item(_PyStackRef ref)
140+
{
141+
if (PyStackRef_IsNull(ref)) {
142+
printf("<NULL>");
143+
return;
144+
}
145+
PyObject *obj = PyStackRef_AsPyObjectBorrow(ref);
146+
if (obj == NULL) {
147+
printf("<nil>");
148+
return;
149+
}
150+
if (
151+
obj == Py_None
152+
|| PyBool_Check(obj)
153+
|| PyLong_CheckExact(obj)
154+
|| PyFloat_CheckExact(obj)
155+
|| PyUnicode_CheckExact(obj)
156+
) {
157+
if (PyObject_Print(obj, stdout, 0) == 0) {
158+
return;
159+
}
160+
PyErr_Clear();
161+
}
162+
// Don't call __repr__(), it might recurse into the interpreter.
163+
printf("<%s at %p>", Py_TYPE(obj)->tp_name, (void *)(ref.bits));
164+
}
165+
139166
static void
140167
dump_stack(_PyInterpreterFrame *frame, _PyStackRef *stack_pointer)
141168
{
169+
_PyStackRef *locals_base = _PyFrame_GetLocalsArray(frame);
142170
_PyStackRef *stack_base = _PyFrame_Stackbase(frame);
143171
PyObject *exc = PyErr_GetRaisedException();
172+
printf(" locals=[");
173+
for (_PyStackRef *ptr = locals_base; ptr < stack_base; ptr++) {
174+
if (ptr != locals_base) {
175+
printf(", ");
176+
}
177+
print_item(*ptr);
178+
}
179+
printf("]\n");
144180
printf(" stack=[");
145181
for (_PyStackRef *ptr = stack_base; ptr < stack_pointer; ptr++) {
146182
if (ptr != stack_base) {
147183
printf(", ");
148184
}
149-
if (PyStackRef_IsNull(*ptr)) {
150-
printf("<NULL>");
151-
continue;
152-
}
153-
PyObject *obj = PyStackRef_AsPyObjectBorrow(*ptr);
154-
if (obj == NULL) {
155-
printf("<nil>");
156-
continue;
157-
}
158-
if (
159-
obj == Py_None
160-
|| PyBool_Check(obj)
161-
|| PyLong_CheckExact(obj)
162-
|| PyFloat_CheckExact(obj)
163-
|| PyUnicode_CheckExact(obj)
164-
) {
165-
if (PyObject_Print(obj, stdout, 0) == 0) {
166-
continue;
167-
}
168-
PyErr_Clear();
169-
}
170-
// Don't call __repr__(), it might recurse into the interpreter.
171-
printf("<%s at %p>", Py_TYPE(obj)->tp_name, (void *)(ptr->bits));
185+
print_item(*ptr);
172186
}
173187
printf("]\n");
174188
fflush(stdout);
@@ -253,6 +267,7 @@ maybe_lltrace_resume_frame(_PyInterpreterFrame *frame, _PyInterpreterFrame *skip
253267
lltrace = *python_lltrace - '0'; // TODO: Parse an int and all that
254268
}
255269
}
270+
lltrace = 5;
256271
if (lltrace >= 5) {
257272
lltrace_resume_frame(frame);
258273
}

Python/executor_cases.c.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/frame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
6868
assert(!_PyFrame_IsIncomplete(frame));
6969
assert(f->f_back == NULL);
7070
_PyInterpreterFrame *prev = _PyFrame_GetFirstComplete(frame->previous);
71-
frame->previous = NULL;
71+
frame->previous = NULLBINARY_OP_ADD_UNICODE;
7272
if (prev) {
7373
assert(prev->owner != FRAME_OWNED_BY_CSTACK);
7474
/* Link PyFrameObjects.f_back and remove link through _PyInterpreterFrame.previous */

Python/generated_cases.c.h

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)