micropython / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
19.5k stars 7.8k forks source link

Strange crash in `mp_obj_str_get_str`, need guidance to debug this myself #12860

Closed aguaviva closed 1 year ago

aguaviva commented 1 year ago

I'd be nice to know how more experienced people would approach debugging this issue.

The code is quite simple:

    while True:
        year, month, day, hour, mins, secs, weekday, yearday = time.localtime()
        t = f"{hour+1:02}:{mins:02}:{secs:02}"

        # (!!) offending line
        tft.text(font_gg, t, 0, 0, ili9342c.BLACK, ili9342c.WHITE, 1) 

More specifically it crashes in this line of the C module's tft code:

https://github.com/aguaviva/ili9342c_mpy/blob/2486326d893f59d283057feeac00e5eff79f6266/src/ili9342c.c#L796

Which calls mp_obj_str_get_str:

https://github.com/micropython/micropython/blob/06a7bf967c58644a0d341764994bdcc9253b4527/py/objstr.c#L2372

Here is the stack trace:

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x401186fb  PS      : 0x00060e30  A0      : 0x80105db1  A1      : 0x3ffd6c30  
A2      : 0x3f80a9e0  A3      : 0x00000001  A4      : 0x00000000  A5      : 0x3ffd6cab  
A6      : 0x00000000  A7      : 0x3ffd6c30  A8      : 0x00000000  A9      : 0xffffffff  
A10     : 0x3f80a9e0  A11     : 0x00000004  A12     : 0x00000077  A13     : 0x00000000  
A14     : 0x3ffc3998  A15     : 0x000c2189  SAR     : 0x00000020  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x0000000b  LBEG    : 0x40096bb0  LEND    : 0x40096bc3  LCOUNT  : 0x00000000  

0x401186f8: mp_obj_str_get_str at /home/raul/repos/v_1_21/micropython/py/objstr.c:2372 (discriminator 2)
0x40105dae: ili9342c_ILI9342C_text at ili9342c.c:?
0x401159da: fun_builtin_var_call at /home/raul/repos/v_1_21/micropython/py/objfun.c:119
0x4011bbb5: mp_call_function_n_kw at /home/raul/repos/v_1_21/micropython/py/runtime.c:712
0x4011bc8d: mp_call_method_n_kw at /home/raul/repos/v_1_21/micropython/py/runtime.c:728
0x40086455: mp_execute_bytecode at /home/raul/repos/v_1_21/micropython/py/vm.c:1042
0x40115a64: fun_bc_call at /home/raul/repos/v_1_21/micropython/py/objfun.c:273
0x4011bbb5: mp_call_function_n_kw at /home/raul/repos/v_1_21/micropython/py/runtime.c:712
0x400863ad: mp_execute_bytecode at /home/raul/repos/v_1_21/micropython/py/vm.c:957
0x40115a64: fun_bc_call at /home/raul/repos/v_1_21/micropython/py/objfun.c:273
0x4011bbb5: mp_call_function_n_kw at /home/raul/repos/v_1_21/micropython/py/runtime.c:712
0x4011bbca: mp_call_function_0 at /home/raul/repos/v_1_21/micropython/py/runtime.c:686
0x4014690b: parse_compile_execute at /home/raul/repos/v_1_21/micropython/shared/runtime/pyexec.c:123
0x40146b3a: do_reader_stdin at /home/raul/repos/v_1_21/micropython/shared/runtime/pyexec.c:280
 (inlined by) pyexec_raw_repl at /home/raul/repos/v_1_21/micropython/shared/runtime/pyexec.c:513
0x4012ce5a: mp_task at /home/raul/repos/v_1_21/micropython/ports/esp32/main.c:138

How would you go about debugging this?

jimmo commented 1 year ago

More specifically it crashes in this line of the C module's tft code:

https://github.com/aguaviva/ili9342c_mpy/blob/2486326d893f59d283057feeac00e5eff79f6266/src/ili9342c.c#L796

It's surprising that it's calling mp_obj_str_get_str given that args[2] is zero (i.e. an int, so it should have taken the other branch).

To debug this, I would either:

aguaviva commented 1 year ago

I think arg[2] should be a string and not an integer, if I am not mistaken the arguments go like this: