Skip to content

Commit c5e32c6

Browse files
committed
vm: Add rudimentary bytecode execution tracing capability.
1 parent 4c6b375 commit c5e32c6

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

py/bc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ typedef struct _mp_exc_stack {
1313
mp_vm_return_kind_t mp_execute_byte_code(const byte *code, const mp_obj_t *args, uint n_args, const mp_obj_t *args2, uint n_args2, mp_obj_t *ret);
1414
mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **ip_in_out, mp_obj_t *fastn, mp_obj_t **sp_in_out, mp_exc_stack_t *exc_stack, mp_exc_stack_t **exc_sp_in_out, volatile mp_obj_t inject_exc);
1515
void mp_byte_code_print(const byte *code, int len);
16+
void mp_byte_code_print2(const byte *code, int len);
1617

1718
// Helper macros to access pointer with least significant bit holding a flag
1819
#define MP_TAGPTR_PTR(x) ((void*)((machine_uint_t)(x) & ~((machine_uint_t)1)))

py/showbc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
ip += sizeof(machine_uint_t); \
2929
} while (0)
3030

31+
void mp_byte_code_print2(const byte *ip, int len);
32+
3133
void mp_byte_code_print(const byte *ip, int len) {
3234
const byte *ip_start = ip;
3335

@@ -71,7 +73,11 @@ void mp_byte_code_print(const byte *ip, int len) {
7173
printf(" bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line);
7274
}
7375
}
76+
mp_byte_code_print2(ip, len - 0);
77+
}
7478

79+
void mp_byte_code_print2(const byte *ip, int len) {
80+
const byte *ip_start = ip;
7581
machine_uint_t unum;
7682
qstr qstr;
7783
while (ip - ip_start < len) {

py/vm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#include "objgenerator.h"
1515

1616
#define DETECT_VM_STACK_OVERFLOW (0)
17+
#if 0
18+
#define TRACE(ip) mp_byte_code_print2(ip, 1);
19+
#else
20+
#define TRACE(ip)
21+
#endif
1722

1823
// Value stack grows up (this makes it incompatible with native C stack, but
1924
// makes sure that arguments to functions are in natural order arg1..argN
@@ -168,6 +173,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
168173
#if MICROPY_USE_COMPUTED_GOTO
169174
#include "vmentrytable.h"
170175
#define DISPATCH() do { \
176+
TRACE(ip); \
171177
save_ip = ip; \
172178
op = *ip++; \
173179
goto *entry_table[op]; \
@@ -223,6 +229,7 @@ mp_vm_return_kind_t mp_execute_byte_code_2(const byte *code_info, const byte **i
223229
#if MICROPY_USE_COMPUTED_GOTO
224230
DISPATCH();
225231
#else
232+
TRACE(ip);
226233
save_ip = ip;
227234
op = *ip++;
228235

0 commit comments

Comments
 (0)