← index #6799PR #4265
Related · high · value 1.035
QUERY · ISSUE

Add means for accessing locals when MicroPython is built with sys.settrace

openby aivarannamaaopened 2021-01-26updated 2024-09-13
enhancement

sys.settrace is a great step towards having a usable MicroPython debugger, but as long as it's not possible to query local variables, people can't replace their print-debugging with a debugger based on sys.settrace.

My proposal is to somehow expose locals when sys.settrace is enabled. It doesn't need to be a Dict[str, Any]. If the exact rules are published for mapping local names to positions in an array, the debugger can still present a conventional view to the user. It's alright if some locals (eg. created by constant expressions) don't end up in this array at all, as long as the rules are clear.

If something like this gets done, then I'd do my best to create a beginner-friendly MicroPython debugger for Thonny IDE.

CANDIDATE · PULL REQUEST

Profiling: sys.settrace implementation.

closedby malinahopened 2018-10-24updated 2019-08-30

This is a working concept of profiling API related to issue #3864.

Please review this pull-request and comment especially on the overall integration into the Micropython.

So far the main concern of the profiler is runtime instruction tracing used to create detailed code coverage reports. To achieve this the analogue of sys.settrace was implemented and puts Micropython closer to feature a debugger #3009.

Building and Running

So far only the Unix port is concerned.

Enable profiling in ports/unix/mpconfigport.h like so:

#define MICROPY_PY_SYS_SETTRACE (1)

MICROPY_PERSISTENT_CODE_SAVE is required by the MICROPY_PY_SYS_TRACE.

Python API

sys.settrace(tracefunc)

As defined in original Python3 documentation sys.settrace(tracefunc). The Frame object and Code objects are only partially implemented.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied