When a gdb-remote plugin process doesn't respond to an interrupt, it returns from
SendContinuePacketAndWaitForResponse with eStateInvalid. The AsyncThread
code responds to this return by setting the state to eStateExited. But it doesn't
immediately exit the ProcessGDBRemote::AsyncThread's packet fetch loop.
This looks like just an oversight in the AsyncThread function. It's important not to
go back to wait for another packet. If it arrives while you are tearing down the
process, the internal-state-thread might try to handle it when the process in not
in a good state.
We weren't going to do anything useful with the extra packet anyway, we've already
declared the process exited. So rather than put more checks into all the shutdown paths
to make sure this extra packet doesn't cause problems, just don't fetch it.
The main part of the patch is setting "done = true" when we get the eStateInvalid.
I also added a check at the beginning of the while(done) loop to prevent another error
from getting us to fetch packets for an exited process.
I also added a test case to ensure that if an Interrupt fails, we call the process
exited. I can't test exactly the error I'm fixing, there's no good way to know
that the stop reply for the failed interrupt wasn't fetched. But at least this
asserts that the overall behavior is correct.
You could put this up into the while condition?