Skip to content
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

Improve sys.settrace to help support bdb/pdb debugging #8767

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

andrewleech
Copy link
Sponsor Contributor

@andrewleech andrewleech commented Jun 16, 2022

Companion support for micropython/micropython-lib#499

Requires micropython be built with MICROPY_PY_SYS_SETTRACE eg. unix dev variant

Includes:

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

codecov-commenter commented Jun 20, 2022

Codecov Report

Merging #8767 (e027113) into master (d7919ea) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #8767   +/-   ##
=======================================
  Coverage   98.31%   98.31%           
=======================================
  Files         156      156           
  Lines       20326    20326           
=======================================
  Hits        19983    19983           
  Misses        343      343           
Impacted Files Coverage Δ
py/modsys.c 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d7919ea...e027113. Read the comment docs.

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
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

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?

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...

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?

@@ -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

@@ -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

@@ -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

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?

@dpgeorge dpgeorge changed the title Draft: Working towards pdb debugging support. Improve sys.settrace support to help support bdb/pdb debugging Jun 29, 2022
@dpgeorge dpgeorge 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
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.
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
Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64: +26848 +3.362% standard[incl +9056(data) +24(bss)]
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants