8000 py/objtype: mp_obj_class_lookup: Improve debug logging. · guidebee/micropython@4556bd2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4556bd2

Browse files
committed
py/objtype: mp_obj_class_lookup: Improve debug logging.
Now traces more explicitly thru the lookup process.
1 parent 35be9e8 commit 4556bd2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

py/objtype.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,15 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_
113113
assert(lookup->dest[0] == MP_OBJ_NULL);
114114
assert(lookup->dest[1] == MP_OBJ_NULL);
115115
for (;;) {
116+
DEBUG_printf("mp_obj_class_lookup: Looking up %s in %s\n", qstr_str(lookup->attr), qstr_str(type->name));
116117
// Optimize special method lookup for native types
117118
// This avoids extra method_name => slot lookup. On the other hand,
118119
// this should not be applied to class types, as will result in extra
119120
// lookup either.
120121
if (lookup->meth_offset != 0 && mp_obj_is_native_type(type)) {
121122
if (*(void**)((char*)type + lookup->meth_offset) != NULL) {
122-
DEBUG_printf("mp_obj_class_lookup: matched special meth slot for %s\n", qstr_str(lookup->attr));
123+
DEBUG_printf("mp_obj_class_lookup: Matched special meth slot (off=%d) for %s\n",
124+
lookup->meth_offset, qstr_str(lookup->attr));
123125
lookup->dest[0] = MP_OBJ_SENTINEL;
124126
return;
125127
}
@@ -150,7 +152,8 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_
150152
#if DEBUG_PRINT
151153
printf("mp_obj_class_lookup: Returning: ");
152154
mp_obj_print(lookup->dest[0], PRINT_REPR); printf(" ");
153-
mp_obj_print(lookup->dest[1], PRINT_REPR); printf("\n");
155+
// Don't try to repr() lookup->dest[1], as we can be called recursively
156+
printf("<%s @%p>\n", mp_obj_get_type_str(lookup->dest[1]), lookup->dest[1]);
154157
#endif
155158
return;
156159
}
@@ -169,6 +172,7 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_
169172
// attribute not found, keep searching base classes
170173

171174
if (type->parent == NULL) {
175+
DEBUG_printf("mp_obj_class_lookup: No more parents\n");
172176
return;
173177
} else if (((mp_obj_base_t*)type->parent)->type == &mp_type_tuple) {
174178
const mp_obj_tuple_t *parent_tuple = type->parent;

0 commit comments

Comments
 (0)
0