← index #6836PR #4265
Related · high · value 0.584
QUERY · ISSUE

sys.settrace issue (bug?)

openby wolfc01opened 2021-02-03updated 2024-09-13
needs-info

Hi,

when I have the following code

def test():
	for a in range(10):
		if a == 7:
			print("it worked")	
			print("again")	
			print("or not.")	
			
test()

then sys.settrace fires at the line containing print("or not.") even if the condition a==7 is False.

for the debugger I am writing, see https://github.com/wolfc01/micropython_debugger/blob/main/debugger.py

Probably this has to do with entering or leaving some local scope?

When I run the very same debugger and example in python 3, above effect does not occur.

Best regards
Carl.

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