tools/mpy-tool.py: Fix freezing of non-bytecode funcs with settrace.

Only bytecode functions can be profiled at this stage.  Native functions
(eg inline assembler) may not even have a valid prelude.

Fixes issue #5075.
This commit is contained in:
Damien George 2019-09-06 23:55:15 +10:00
parent bd2e46e0a5
commit c69f58e6b9
1 changed files with 17 additions and 16 deletions

View File

@ -412,22 +412,23 @@ class RawCode(object):
print(' .fun_data_len = %u,' % len(self.bytecode))
print(' .n_obj = %u,' % len(self.objs))
print(' .n_raw_code = %u,' % len(self.raw_codes))
print(' #if MICROPY_PY_SYS_SETTRACE')
print(' .prelude = {')
print(' .n_state = %u,' % self.prelude[0])
print(' .n_exc_stack = %u,' % self.prelude[1])
print(' .scope_flags = %u,' % self.prelude[2])
print(' .n_pos_args = %u,' % self.prelude[3])
print(' .n_kwonly_args = %u,' % self.prelude[4])
print(' .n_def_pos_args = %u,' % self.prelude[5])
print(' .qstr_block_name = %s,' % self.simple_name.qstr_id)
print(' .qstr_source_file = %s,' % self.source_file.qstr_id)
print(' .line_info = fun_data_%s + %u,' % (self.escaped_name, 0)) # TODO
print(' .locals = fun_data_%s + %u,' % (self.escaped_name, 0)) # TODO
print(' .opcodes = fun_data_%s + %u,' % (self.escaped_name, self.ip))
print(' },')
print(' .line_of_definition = %u,' % 0) # TODO
print(' #endif')
if self.code_kind == MP_CODE_BYTECODE:
print(' #if MICROPY_PY_SYS_SETTRACE')
print(' .prelude = {')
print(' .n_state = %u,' % self.prelude[0])
print(' .n_exc_stack = %u,' % self.prelude[1])
print(' .scope_flags = %u,' % self.prelude[2])
print(' .n_pos_args = %u,' % self.prelude[3])
print(' .n_kwonly_args = %u,' % self.prelude[4])
print(' .n_def_pos_args = %u,' % self.prelude[5])
print(' .qstr_block_name = %s,' % self.simple_name.qstr_id)
print(' .qstr_source_file = %s,' % self.source_file.qstr_id)
print(' .line_info = fun_data_%s + %u,' % (self.escaped_name, 0)) # TODO
print(' .locals = fun_data_%s + %u,' % (self.escaped_name, 0)) # TODO
print(' .opcodes = fun_data_%s + %u,' % (self.escaped_name, self.ip))
print(' },')
print(' .line_of_definition = %u,' % 0) # TODO
print(' #endif')
print(' #if MICROPY_EMIT_MACHINE_CODE')
print(' .prelude_offset = %u,' % self.prelude_offset)
print(' .n_qstr = %u,' % len(qstr_links))