-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Improve sys.settrace to help support bdb/pdb debugging #8767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
16bd204
to
e027113
Compare
Codecov Report
@@ Coverage Diff @@
## master #8767 +/- ##
=======================================
Coverage 98.31% 98.31%
=======================================
Files 156 156
Lines 20326 20326
=======================================
Hits 19983 19983
Misses 343 343
Continue to review full report at Codecov.
|
Requires micropython to be compiled with MICROPY_PY_SYS_SETTRACE. Also requires micropython/micropython#8767
Requires micropython to be compiled with MICROPY_PY_SYS_SETTRACE. Also requires micropython/micropython#8767
Requires micropython to be compiled with MICROPY_PY_SYS_SETTRACE. Also requires micropython/micropython#8767
MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_gettrace_obj, mp_sys_gettrace); | ||
|
||
// _getframe(): Return current frame object. | ||
STATIC mp_obj_t mp_sys_getframe(size_t n_args, const mp_obj_t *args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please call it mp_sys__getframe
if (attr == MP_QSTR___code__) { | ||
mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in); | ||
mp_obj_code_t *code = MP_OBJ_TO_PTR(mp_obj_new_code(self->context, self->rc)); | ||
if (code != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can code be null?
switch (attr) { | ||
case MP_QSTR_f_back: | ||
dest[0] = mp_const_none; | ||
if (o->code_state->prev_state) { | ||
if (!o->code_state->prev_state->frame) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you find a case where this could be NULL? maybe it needs a test...
dest[0] = o->trace_obj; | ||
break; | ||
case MP_QSTR_f_locals: | ||
dest[0] = MP_OBJ_FROM_PTR(o->code->dict_locals); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed? locals in uPy doesn't work well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just return an empty dict instead?
@@ -274,6 +292,7 @@ mp_obj_t mp_obj_new_frame(const mp_code_state_t *code_state) { | |||
o->lineno = mp_prof_bytecode_lineno(rc, o->lasti); | |||
o->trace_opcodes = false; | |||
o->callback = MP_OBJ_NULL; | |||
o->trace_obj = MP_OBJ_NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe call it f_trace
@@ -60,7 +61,9 @@ mp_obj_t mp_obj_new_frame(const mp_code_state_t *code_state); | |||
|
|||
// This is the implementation for the sys.settrace | |||
mp_obj_t mp_prof_settrace(mp_obj_t callback); | |||
mp_obj_t mp_prof_gettrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please put void
in arg list
@@ -313,6 +332,33 @@ mp_obj_t mp_prof_settrace(mp_obj_t callback) { | |||
return mp_const_none; | |||
} | |||
|
|||
mp_obj_t mp_prof_gettrace() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void
in arg list
return prof_trace_cb; | ||
} | ||
|
||
mp_obj_t mp_prof_get_frame(int depth) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we change int
to size_t
to indicate it can't be negative?
Only if MICROPY_PY_SYS_SETTRACE is enabled. This is used to provide introspection of attributes such as function name or source file & line. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Used in bdb.py debugging support.
Used in pdb.py debugging support.
Requires micropython to be compiled with MICROPY_PY_SYS_SETTRACE. Also requires micropython/micropython#8767
f3c6bf2
to
c32fec4
Compare
Code size report:
|
Re-enable binascii.crc32()
This is an automated heads-up that we've just merged a Pull Request See #13763 A search suggests this PR might apply the STATIC macro to some C code. If it Although this is an automated message, feel free to @-reply to me directly if |
Companion support for micropython/micropython-lib#499
Requires micropython be built with
MICROPY_PY_SYS_SETTRACE
eg. unix dev variantIncludes:
sys/settrace: Add sys._getframe() function.
Refer to https://docs.python.org/3/library/sys.html#sys._getframe
sys/settrace: Add frame.f_trace object support.
f_trace
holds a python obj on the frame, used inbdb
to track active trace function for call stack.