Skip to content

Commit

Permalink
py/vm: For tracing use mp_printf, and print state when thread enabled.
Browse files Browse the repository at this point in the history
mp_printf should be used to print the prefix because it's also used in
mp_bytecode_print2 (otherwise, depending on the system, different output
streams may be used).

Also print the current thread state when threading is enabled to easily see
which thread executes what opcode.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Mar 17, 2021
1 parent 6e5aea0 commit 42cf77f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion py/vm.c
Expand Up @@ -39,7 +39,12 @@
// *FORMAT-OFF*

#if 0
#define TRACE(ip) printf("sp=%d ", (int)(sp - &code_state->state[0] + 1)); mp_bytecode_print2(&mp_plat_print, ip, 1, code_state->fun_bc->const_table);
#if MICROPY_PY_THREAD
#define TRACE_PREFIX mp_printf(&mp_plat_print, "ts=%p sp=%d ", mp_thread_get_state(), (int)(sp - &code_state->state[0] + 1))
#else
#define TRACE_PREFIX mp_printf(&mp_plat_print, "sp=%d ", (int)(sp - &code_state->state[0] + 1))
#endif
#define TRACE(ip) TRACE_PREFIX; mp_bytecode_print2(&mp_plat_print, ip, 1, code_state->fun_bc->const_table);
#else
#define TRACE(ip)
#endif
Expand Down

0 comments on commit 42cf77f

Please sign in to comment.