-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Improve sys.settrace to help support debugpy / 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 ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8767 +/- ##
==========================================
- Coverage 98.54% 97.80% -0.74%
==========================================
Files 169 169
Lines 21943 21924 -19
==========================================
- Hits 21623 21443 -180
- Misses 320 481 +161 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
py/modsys.c
Outdated
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
py/objfun.c
Outdated
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?
py/profile.c
Outdated
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...
py/profile.c
Outdated
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?
py/profile.c
Outdated
@@ -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
py/profile.h
Outdated
@@ -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
py/profile.c
Outdated
@@ -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
py/profile.c
Outdated
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?
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 |
Requires micropython to be compiled with MICROPY_PY_SYS_SETTRACE. Also requires micropython/micropython#8767
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 <[email protected]>
Signed-off-by: Andrew Leech <[email protected]>
Refer to https://docs.python.org/3/library/sys.html#sys._getframe Signed-off-by: Andrew Leech <[email protected]>
Refer to https://docs.python.org/3/library/sys.html#sys.gettrace Signed-off-by: Andrew Leech <[email protected]>
Updates micropython-lib submodule to include the new debugpy implementation that enables VS Code debugging support for MicroPython applications. The debugpy port provides: - Debug Adapter Protocol (DAP) compatibility with VS Code - Line breakpoints, stepping, and variable inspection - Integration with MicroPython's sys.settrace functionality - Network-based debugging via TCP socket connection This enables developers to debug MicroPython code using the familiar VS Code debugging interface, improving the development experience. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Companion support for micropython/micropython-lib#1022 & micropython/micropython-lib#499
Requires micropython be built with
MICROPY_PY_SYS_SETTRACE
eg. unix standard 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.