Conversation

andrewleech

Companion support for micropython/micropython-lib#1022 & micropython/micropython-lib#499

Requires micropython be built with MICROPY_PY_SYS_SETTRACE eg. unix standard variant

Includes:

@andrewleechandrewleech force-pushed the pdb_support branch 2 times, most recently from 16bd204 to e027113 Compare June 19, 2022 23:51
@codecov-commenter

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.80%. Comparing base (5f058e9) to head (a7ae522).
Report is 24 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

andrewleech pushed a commit to andrewleech/micropython-lib that referenced this pull request Jun 20, 2022
andrewleech pushed a commit to andrewleech/micropython-lib that referenced this pull request Jun 20, 2022
andrewleech pushed a commit to andrewleech/micropython-lib that referenced this pull request Jun 22, 2022
Requires micropython to be compiled with MICROPY_PY_SYS_SETTRACE.
Also requires micropython/micropython#8767
andrewleech pushed a commit to andrewleech/micropython-lib that referenced this pull request Jun 22, 2022
Requires micropython to be compiled with MICROPY_PY_SYS_SETTRACE.
Also requires micropython/micropython#8767
andrewleech pushed a commit to andrewleech/micropython-lib that referenced this pull request Jun 22, 2022
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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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);
Copy link
Member

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

Copy link
Member

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;
Copy link
Member

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();
Copy link
Member

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() {
Copy link
Member

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) {
Copy link
Member

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?

@dpgeorgedpgeorge added the py-coreRelates to py/ directory in sourcelabel Jun 29, 2022
@dpgeorgedpgeorge changed the title Draft: Working towards pdb debugging support. Improve sys.settrace support to help support bdb/pdb debugging Jun 29, 2022
@dpgeorgedpgeorge changed the title Improve sys.settrace support to help support bdb/pdb debugging Improve sys.settrace to help support bdb/pdb debugging Jun 29, 2022
andrewleech pushed a commit to andrewleech/micropython-lib that referenced this pull request Aug 24, 2023
Requires micropython to be compiled with MICROPY_PY_SYS_SETTRACE.
Also requires micropython/micropython#8767
@github-actions

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64: +35176 +4.114% standard[incl +13376(data) +32(bss)]
      stm32:    +8 +0.002% PYBV10
     mimxrt:   -72 -0.019% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:   -80 -0.030% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

RetiredWizard pushed a commit to RetiredWizard/micropython that referenced this pull request Dec 30, 2023
@projectgus

This is an automated heads-up that we've just merged a Pull Request
that removes the STATIC macro from MicroPython's C API.

See #13763

A search suggests this PR might apply the STATIC macro to some C code. If it
does, then next time you rebase the PR (or merge from master) then you should
please replace all the STATIC keywords with static.

Although this is an automated message, feel free to @-reply to me directly if
you have any questions about this.

andrewleech pushed a commit to andrewleech/micropython-lib that referenced this pull request Jun 11, 2025
Requires micropython to be compiled with MICROPY_PY_SYS_SETTRACE.
Also requires micropython/micropython#8767
@andrewleechandrewleech changed the title Improve sys.settrace to help support bdb/pdb debugging Improve sys.settrace to help support debugpy / pdb debugging Jun 11, 2025
pi-anl and others added 5 commits June 11, 2025 22:09
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]>
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]>
Sign up for free to join this conversation on . Already have an account? Sign in to comment
py-coreRelates to py/ directory in source
None yet

Successfully merging this pull request may close these issues.