aboutsummaryrefslogtreecommitdiff
path: root/py/emitglue.c
diff options
context:
space:
mode:
authorMilan Rossa <rossa.milan@gmail.com>2019-08-14 16:09:36 +0200
committerDamien George <damien.p.george@gmail.com>2019-08-30 16:44:12 +1000
commit310b3d1b81d561e19d719acd89ee47b759e3795c (patch)
tree18beb2d50b30dd525fc57efd43a7e705e777fade /py/emitglue.c
parentc96aedad4691d864c073890a7a20abc7ebd2de27 (diff)
py: Integrate sys.settrace feature into the VM and runtime.
This commit adds support for sys.settrace, allowing to install Python handlers to trace execution of Python code. The interface follows CPython as closely as possible. The feature is disabled by default and can be enabled via MICROPY_PY_SYS_SETTRACE.
Diffstat (limited to 'py/emitglue.c')
-rw-r--r--py/emitglue.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/py/emitglue.c b/py/emitglue.c
index 483a47025..d30a1e674 100644
--- a/py/emitglue.c
+++ b/py/emitglue.c
@@ -34,6 +34,7 @@
#include "py/emitglue.h"
#include "py/runtime0.h"
#include "py/bc.h"
+#include "py/profile.h"
#if MICROPY_DEBUG_VERBOSE // print debugging info
#define DEBUG_PRINT (1)
@@ -52,6 +53,9 @@ mp_uint_t mp_verbose_flag = 0;
mp_raw_code_t *mp_emit_glue_new_raw_code(void) {
mp_raw_code_t *rc = m_new0(mp_raw_code_t, 1);
rc->kind = MP_CODE_RESERVED;
+ #if MICROPY_PY_SYS_SETTRACE
+ rc->line_of_definition = 0;
+ #endif
return rc;
}
@@ -75,6 +79,11 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code,
rc->n_raw_code = n_raw_code;
#endif
+ #if MICROPY_PY_SYS_SETTRACE
+ mp_bytecode_prelude_t *prelude = &rc->prelude;
+ mp_prof_extract_prelude(code, prelude);
+ #endif
+
#ifdef DEBUG_PRINT
#if !MICROPY_DEBUG_PRINTERS
const size_t len = 0;
@@ -172,6 +181,12 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar
if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) {
((mp_obj_base_t*)MP_OBJ_TO_PTR(fun))->type = &mp_type_gen_wrap;
}
+
+ #if MICROPY_PY_SYS_SETTRACE
+ mp_obj_fun_bc_t *self_fun = (mp_obj_fun_bc_t *)MP_OBJ_TO_PTR(fun);
+ self_fun->rc = rc;
+ #endif
+
break;
}