Skip to content

Commit a4ac5b9

Browse files
committed
showbc: Make sure it's possible to trace MAKE_FUNCTION arg to actual bytecode.
1 parent dd0dee3 commit a4ac5b9

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

py/bc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef struct _mp_code_state {
5151

5252
mp_vm_return_kind_t mp_execute_bytecode(const byte *code, const mp_obj_t *args, uint n_args, const mp_obj_t *args2, uint n_args2, mp_obj_t *ret);
5353
mp_vm_return_kind_t mp_execute_bytecode2(mp_code_state *code_state, volatile mp_obj_t inject_exc);
54-
void mp_bytecode_print(const byte *code, int len);
54+
void mp_bytecode_print(const void *descr, const byte *code, int len);
5555
void mp_bytecode_print2(const byte *code, int len);
5656

5757
// Helper macros to access pointer with least significant bit holding a flag

py/emitglue.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, byte *code, uint len, uint
8181
#endif
8282
#if MICROPY_DEBUG_PRINTERS
8383
if (mp_verbose_flag > 0) {
84-
mp_bytecode_print(code, len);
84+
mp_bytecode_print(rc, code, len);
8585
}
8686
#endif
8787
}

py/showbc.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
void mp_bytecode_print2(const byte *ip, int len);
5858

59-
void mp_bytecode_print(const byte *ip, int len) {
59+
void mp_bytecode_print(const void *descr, const byte *ip, int len) {
6060
const byte *ip_start = ip;
6161

6262
// get code info size
@@ -66,7 +66,8 @@ void mp_bytecode_print(const byte *ip, int len) {
6666

6767
qstr source_file = code_info[4] | (code_info[5] << 8) | (code_info[6] << 16) | (code_info[7] << 24);
6868
qstr block_name = code_info[8] | (code_info[9] << 8) | (code_info[10] << 16) | (code_info[11] << 24);
69-
printf("File %s, code block '%s' (%d bytes)\n", qstr_str(source_file), qstr_str(block_name), len);
69+
printf("File %s, code block '%s' (descriptor: %p, bytecode @%p %d bytes)\n",
70+
qstr_str(source_file), qstr_str(block_name), descr, code_info, len);
7071

7172
// bytecode prelude: state size and exception stack size; 16 bit uints
7273
{
@@ -434,25 +435,25 @@ void mp_bytecode_print2(const byte *ip, int len) {
434435

435436
case MP_BC_MAKE_FUNCTION:
436437
DECODE_PTR;
437-
printf("MAKE_FUNCTION " UINT_FMT, unum);
438+
printf("MAKE_FUNCTION %p", (void*)unum);
438439
break;
439440

440441
case MP_BC_MAKE_FUNCTION_DEFARGS:
441442
DECODE_PTR;
442-
printf("MAKE_FUNCTION_DEFARGS " UINT_FMT, unum);
443+
printf("MAKE_FUNCTION_DEFARGS %p", (void*)unum);
443444
break;
444445

445446
case MP_BC_MAKE_CLOSURE: {
446447
DECODE_PTR;
447448
machine_uint_t n_closed_over = *ip++;
448-
printf("MAKE_CLOSURE " UINT_FMT " " UINT_FMT, unum, n_closed_over);
449+
printf("MAKE_CLOSURE %p " UINT_FMT, (void*)unum, n_closed_over);
449450
break;
450451
}
451452

452453
case MP_BC_MAKE_CLOSURE_DEFARGS: {
453454
DECODE_PTR;
454455
machine_uint_t n_closed_over = *ip++;
455-
printf("MAKE_CLOSURE_DEFARGS " UINT_FMT " " UINT_FMT, unum, n_closed_over);
456+
printf("MAKE_CLOSURE_DEFARGS %p " UINT_FMT, (void*)unum, n_closed_over);
456457
break;
457458
}
458459

0 commit comments

Comments
 (0)