Skip to content

Commit

Permalink
py: Fix compiling with debug enabled and make more use of DEBUG_printf.
Browse files Browse the repository at this point in the history
DEBUG_printf and MICROPY_DEBUG_PRINTER is now used instead of normal
printf, and a fault is fixed in mp_obj_class_lookup with debugging enabled;
see issue micropython#3999.  Debugging can now be enabled on all ports including when
nan-boxing is used.
  • Loading branch information
dpgeorge committed Aug 2, 2018
1 parent da2d2b6 commit b630dfc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
3 changes: 3 additions & 0 deletions py/emitglue.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code,
#endif

#ifdef DEBUG_PRINT
#if !MICROPY_DEBUG_PRINTERS
const size_t len = 0;
#endif
DEBUG_printf("assign byte code: code=%p len=" UINT_FMT " flags=%x\n", code, len, (uint)scope_flags);
#endif
#if MICROPY_DEBUG_PRINTERS
Expand Down
3 changes: 2 additions & 1 deletion py/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ void gc_dump_alloc_table(void) {
GC_EXIT();
}

#if DEBUG_PRINT
#if 0
// For testing the GC functions
void gc_test(void) {
mp_uint_t len = 500;
mp_uint_t *heap = malloc(len);
Expand Down
8 changes: 4 additions & 4 deletions py/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,13 @@ void mp_set_clear(mp_set_t *set) {
#if defined(DEBUG_PRINT) && DEBUG_PRINT
void mp_map_dump(mp_map_t *map) {
for (size_t i = 0; i < map->alloc; i++) {
if (map->table[i].key != NULL) {
if (map->table[i].key != MP_OBJ_NULL) {
mp_obj_print(map->table[i].key, PRINT_REPR);
} else {
printf("(nil)");
DEBUG_printf("(nil)");
}
printf(": %p\n", map->table[i].value);
DEBUG_printf(": %p\n", map->table[i].value);
}
printf("---\n");
DEBUG_printf("---\n");
}
#endif
2 changes: 1 addition & 1 deletion py/objfun.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
dump_args(args, n_args);
DEBUG_printf("Input kw args: ");
dump_args(args + n_args, n_kw * 2);

mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in);
DEBUG_printf("Func n_def_args: %d\n", self->n_def_args);

size_t n_state, state_size;
DECODE_CODESTATE_SIZE(self->bytecode, n_state, state_size);
Expand Down
11 changes: 7 additions & 4 deletions py/objtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_
mp_convert_member_lookup(obj_obj, type, elem->value, lookup->dest);
}
#if DEBUG_PRINT
printf("mp_obj_class_lookup: Returning: ");
mp_obj_print(lookup->dest[0], PRINT_REPR); printf(" ");
// Don't try to repr() lookup->dest[1], as we can be called recursively
printf("<%s @%p>\n", mp_obj_get_type_str(lookup->dest[1]), lookup->dest[1]);
DEBUG_printf("mp_obj_class_lookup: Returning: ");
mp_obj_print_helper(MICROPY_DEBUG_PRINTER, lookup->dest[0], PRINT_REPR);
if (lookup->dest[1] != MP_OBJ_NULL) {
// Don't try to repr() lookup->dest[1], as we can be called recursively
DEBUG_printf(" <%s @%p>", mp_obj_get_type_str(lookup->dest[1]), MP_OBJ_TO_PTR(lookup->dest[1]));
}
DEBUG_printf("\n");
#endif
return;
}
Expand Down

0 comments on commit b630dfc

Please sign in to comment.