TOPLLab / WARDuino

📟 A dynamic WebAssembly VM for embedded systems
https://topllab.github.io/WARDuino/
Mozilla Public License 2.0
73 stars 7 forks source link

Plugin linenumbers don't update #182

Closed carllocos closed 1 year ago

carllocos commented 1 year ago

As noticed during our last meeting, the latest commits on the main branch cause the plugin to break. I did some investigation and could not properly identify the root cause but I think it is related to pausing the thread.

If you start the plugin in emulated mode but pass the --paused argument to the spawning process method. You will notice that the plugin completely blocks and if you omit the --paused argument the plugin can correctly interact with the emulator and thus also correctly start. Unfortunately, when I tried to investigate whether that was the reason why the plugin failed on the MCU, the bug suddenly disappeared :upside_down_face:

The weird part is however that when debugging on a paused emulator, the emulator was clearly irresponsive since the plugin did not receive any answer back for the interrupts being sent. However, when I was still facing the bug on the MCU, the plugin did clearly still get answers back from the MCU, but the issue that I noticed then was related to source mapping: the corresponding line number could not be calculated for the dumped pc_ptr address calculated in this method: https://github.com/TOPLLab/WARDuino-VSCode/blob/727aa258c62a8261fd3c4c08a33941686c256ffe/src/DebugSession/DebugSession.ts#L324

The fact that the source mapping was invalid most likely indicates that the pc_ptr was pointing to an invalid location, which seems weird since normally the pc_ptr should point to the start of the main function since this happens automatically when invoking the run_module method for the first time. I'm not sure of this but maybe because of the paused thread the pc_ptr was simply never changed to the right location :/.

Unfortunately, as I said, I no longer experience that bug and can therefore no longer continue my investigation. @tolauwae So maybe if you do experience the bug, you could try to disable the following line of code and see whether it solves the problem https://github.com/TOPLLab/WARDuino/blob/d050e5bf0b3b83cbaedd83d7ff821af1e0960db2/src/Interpreter/instructions.cpp#L1539

tolauwae commented 1 year ago

I still experience the bug.

  1. commenting out 1539 does not fix the problem. (I also commented out the next line otherwise it doesn't compile)
  2. I am not sure the bug is related to the sleeping of the interpreter thread during pause, since we do receive dumps in the plugin. Also I tried this with the device, not the emulator.

There is something very wrong with the debugger. Strange behaviour I notice:

  1. I only step yet a function is updated
  2. interrupt received is printed twice, and result is send twice

Output log in VS Code:

hardware: 
hardware: 
nextRequest
Plugin: Step
hardware: received interrupt 4
hardware: received interrupt 4
hardware: Interrupt: 4
hardware: Interrupt: 4
hardware: STEP!
Plugin: Refreshing
hardware: STEP!
Plugin: Refreshing
hardware: received interrupt 12
hardware: received interrupt 12
hardware: Interrupt: 12
hardware: Interrupt: 12
hardware: {"pc":"0x3ffbdc88","start":["0x3ffbdb70"],"breakpoints":[],"functions":[{"fidx":"0x4","from":"0x3ffbdc5e","to":"0x3ffbdc69"},{"fidx":"0x5","from":"0x3ffbdc6c","to":"0x3ffbdc85"},{"fidx":"0x6","from":"0x3ffbdc88","to":"0x3ffbdc8e"},{"fidx":"0x7","from":"0x3ffbdc91","to":"0x3ffbdc97"},{"fidx":"0x8","from":"0x3ffbdc9a","to":"0x3ffbdc9e"},{"fidx":"0x9","from":"0x3ffbdca1","to":"0x3ffbdca9"}],"callstack":[{"type":0,"fidx":"0x5","sp":-1,"fp":-1,"start":"0x3ffbdc6c","ra":"0x3ffbdc57","callsite":"0x3ffbdc55"},{"type":0,"fidx":"0x6","sp":-1,"fp":0,"start":"0x3ffbdc88","ra":"0x3ffbdc72","callsite":"0x3ffbdc70"}], "locals": {"count":0,"locals":[]}, "events": []}
(0) []
warning setting locals for new function with index: 6
118
hardware: {"pc":"0x3ffbdc88","start":["0x3ffbdb70"],"breakpoints":[],"functions":[{"fidx":"0x4","from":"0x3ffbdc5e","to":"0x3ffbdc69"},{"fidx":"0x5","from":"0x3ffbdc6c","to":"0x3ffbdc85"},{"fidx":"0x6","from":"0x3ffbdc88","to":"0x3ffbdc8e"},{"fidx":"0x7","from":"0x3ffbdc91","to":"0x3ffbdc97"},{"fidx":"0x8","from":"0x3ffbdc9a","to":"0x3ffbdc9e"},{"fidx":"0x9","from":"0x3ffbdca1","to":"0x3ffbdca9"}],"callstack":[{"type":0,"fidx":"0x5","sp":-1,"fp":-1,"start":"0x3ffbdc6c","ra":"0x3ffbdc57","callsite":"0x3ffbdc55"},{"type":0,"fidx":"0x6","sp":-1,"fp":0,"start":"0x3ffbdc88","ra":"0x3ffbdc72","callsite":"0x3ffbdc70"}], "locals": {"count":0,"locals":[]}, "events": []}
(0) []
118
hardware: 
hardware: 
hardware: received interrupt 12
hardware: received interrupt 12
hardware: Interrupt: 12
hardware: Interrupt: 12
hardware: {"pc":"0x3ffbdc88","start":["0x3ffbdb70"],"breakpoints":[],"functions":[{"fidx":"0x4","from":"0x3ffbdc5e","to":"0x3ffbdc69"},{"fidx":"0x5","from":"0x3ffbdc6c","to":"0x3ffbdc85"},{"fidx":"0x6","from":"0x3ffbdc88","to":"0x3ffbdc8e"},{"fidx":"0x7","from":"0x3ffbdc91","to":"0x3ffbdc97"},{"fidx":"0x8","from":"0x3ffbdc9a","to":"0x3ffbdc9e"},{"fidx":"0x9","from":"0x3ffbdca1","to":"0x3ffbdca9"}],"callstack":[{"type":0,"fidx":"0x5","sp":-1,"fp":-1,"start":"0x3ffbdc6c","ra":"0x3ffbdc57","callsite":"0x3ffbdc55"},{"type":0,"fidx":"0x6","sp":-1,"fp":0,"start":"0x3ffbdc88","ra":"0x3ffbdc72","callsite":"0x3ffbdc70"}], "locals": {"count":0,"locals":[]}, "events": []}
(0) []
118
hardware: {"pc":"0x3ffbdc88","start":["0x3ffbdb70"],"breakpoints":[],"functions":[{"fidx":"0x4","from":"0x3ffbdc5e","to":"0x3ffbdc69"},{"fidx":"0x5","from":"0x3ffbdc6c","to":"0x3ffbdc85"},{"fidx":"0x6","from":"0x3ffbdc88","to":"0x3ffbdc8e"},{"fidx":"0x7","from":"0x3ffbdc91","to":"0x3ffbdc97"},{"fidx":"0x8","from":"0x3ffbdc9a","to":"0x3ffbdc9e"},{"fidx":"0x9","from":"0x3ffbdca1","to":"0x3ffbdca9"}],"callstack":[{"type":0,"fidx":"0x5","sp":-1,"fp":-1,"start":"0x3ffbdc6c","ra":"0x3ffbdc57","callsite":"0x3ffbdc55"},{"type":0,"fidx":"0x6","sp":-1,"fp":0,"start":"0x3ffbdc88","ra":"0x3ffbdc72","callsite":"0x3ffbdc70"}], "locals": {"count":0,"locals":[]}, "events": []}
(0) []
118
carllocos commented 1 year ago

the reason why the interrupt result is printed twice is because the plugin sends the interrupt two times. This is something that I already fixed in the newer version of the plugin.

tolauwae commented 1 year ago

And any idea why we get warning setting locals for new function with index: 6 in the output? @carllocos

tolauwae commented 1 year ago

The above warning was printed because the fidx in the dump did not exist. The problem was that the wrong program was uploaded. This is a bug introduced by the templating in 0.3.0.

This problem has been fixed. But this bug persists, so this was unrelated.

I have also confirmed that the sleeping during pause is not the problem as I said before. The bug does not manifest on 875a01b4a51a567fad2e17ee9df41a2e64de3d8e.

tolauwae commented 1 year ago

Nevermind it has been fixed with the wrong program upload fix. It makes sense as well. Wrong program uploaded so none of the addresses correspond with the lines in the VS Code.