bloombloombloom / Bloom

A debug interface for AVR-based embedded systems development on GNU/Linux.
https://bloom.oscillate.io/
Other
64 stars 3 forks source link

Explore potential fix for CLion prematurely killing Bloom's process #53

Closed navnavnav closed 1 year ago

navnavnav commented 1 year ago

There is a known issue with CLion managing Bloom's process; At the end of a debug session, CLion issues a SIGKILL to Bloom's process, forcing it to shutdown immediately, with no opportunity to safely release the connected hardware (debug tool and target). This issue sometimes results in subsequent startup failures, as the hardware is left in an unknown state.

This issue was reported to CLion's developers some time ago: https://youtrack.jetbrains.com/issue/CPP-28843

There may be a way to fix this within Bloom;

Key points (some of which are assumptions):

With the above points in mind, we could force the TargetController to suspend upon receiving the detach command packet from the GDB client. Suspending the TargetController will mean disconnecting from the debug tool and target. Once the TargetController has been suspended, we will send an OK response back to the GDB client, allowing it to disconnect. This means that, by the time CLion sends the SIGKILL to Bloom, we will have already released the hardware.

I'm not sure if this will work. The purpose of this ticket is to confirm it and explore its feasibility. Even if it does work, it's a nasty hack which I hope we'll be able to remove at some point later on, once the issue in CLion is addressed.

If it does work, I'd like to get it into v0.11.0, which is due for release soon.

navnavnav commented 1 year ago

This appears to work quite well. By suspending the TargetController upon receiving the detach command packet, CLion will now wait for Bloom to release the hardware, before it sends the SIGKILL.

We only do this if we're running under CLion, and we warn the user about it at startup:

https://github.com/bloombloombloom/Bloom/blob/01651be95bed36ce55f5b8b2c7d55c2224bcade2/src/DebugServer/Gdb/GdbRspDebugServer.cpp#L128-L132

Not the nicest solution, but it will have to do for now.

These changes are in develop and will be shipped with v0.11.0, which I'm hoping to publish late this weekend or early next week. Probably on Sunday/Monday.