This is an optional request, but supporting it makes the experience better when
re-launching a big binary that takes significant time to parse: instead of
tearing down and re-create the whole session we just need to kill the current
process and launch a new one.
Some non-obvious comments that might help review this change:
- After killing the process, we get an "exited" event for it. Because the process no longer exists some interesting things can occur that manifest as flaky failures if not dealt with:
- EventIsProcessEvent relies on SBEvent::GetBroadcasterClass, which can crash if the broadcaster is no longer there: the event only holds a weak_ptr to its broadcaster, and GetBroadcasterClass uses it without checking.
Other EventIs* functions look at the flavor of the EventData, so I have modified EventIsProcessEvent to do that. - We keep the PID of the old process so we can detect its "exited" event and not terminate the whole session. But sometimes the SBProcess we get from the event won't have a PID, for some reason.
- EventIsProcessEvent relies on SBEvent::GetBroadcasterClass, which can crash if the broadcaster is no longer there: the event only holds a weak_ptr to its broadcaster, and GetBroadcasterClass uses it without checking.
- I have factored out the code to launch a process out to a new LaunchProcess function, so it can be used from both request_launch and request_restart.
- The restart_runInTerminal test has the same problem with debug builds as the original runInTerminal test: when attaching to the launcher instance of lldb-vscode it takes a long time to parse its debug info. I have used the same workaround to disable that particular test for debug builds.
+1