Add `terminateDebuggee` capability
If my guess is right we can set it and code for it, even with keeping the old version compatibility. If this is true (old versions will just have the "stop" as plain terminate, new versions will have the additional option to "Disconnect" (in this case we'd get terminateDebuggee; false in the disconnect request and would issue a -target-detach).
After some tests: for a attach configuration we'll get Disconnect + Disconnect and Suspend, as soon as we support both (but not if only one of those is added):
response.body.supportTerminateDebuggee = true;
response.body.supportSuspendDebuggee = true;
but I see no option to actually do "Disconnect and Suspend" in a portable way.
What possibly works on Linux is to send SIGSTOP, then detach - but only there. Tried with a mingw32 process and mingw32 process outside of this extension - sending SIGSTOP killed the process.
Retesting with a launch configuration resulted in the same two buttons.
If this is not done then we have the existing two buttons: detach for attach, stop for launch.
It looks to me that we therefore should (at least currently) not support this (I haven't checked if updating a dependency would change anything, but I guess it wouldn't).
Should we close this issue?
Should I commit the following changes nonetheless?
--- a/src/gdb.ts
+++ b/src/gdb.ts
@@ -49,6 +49,22 @@ class GDBDebugSession extends MI2DebugSession {
response.body.supportsEvaluateForHovers = true;
response.body.supportsSetVariable = true;
response.body.supportsStepBack = true;
+
+ // CHECKME - things to possibly implement:
+
+ // seems to be only working together (at least in vscode),
+ // but looks to be not applicable to a system process
+ // see https://github.com/WebFreak001/code-debug/issues/357
+ //response.body.supportTerminateDebuggee = true;
+ //response.body.supportSuspendDebuggee = true;
+
+ // This should have the benefit of faster restart. Do we care?
+ // If supported we'll receive a RestartRequest, if not the DAP will receive a stop,
+ // then will be restarted itself (so we go through the complete initialization).
+ // For "launch" RestartRequest should send a stop with terminate,
+ // for "attach" it should either be a detach + attach or send pause and request GDB info to be
+ // reloaded (is "show directories" + "directories" enough?)
+ //response.body.supportsRestartRequest = true;
this.sendResponse(response);
}
diff --git a/src/mibase.ts b/src/mibase.ts
index 5cf2abf..7dc938c 100644
--- a/src/mibase.ts
+++ b/src/mibase.ts
@@ -170,11 +170,16 @@ export class MI2DebugSession extends DebugSession {
this.quitEvent();
}
protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void {
- if (this.attached)
- this.miDebugger.detach();
- else
- this.miDebugger.stop();
+ if (args.terminateDebuggee == undefined)
+ if (this.attached)
+ args.terminateDebuggee = false;
+ else
+ args.terminateDebuggee = true;
+ if (args.terminateDebuggee)
+ this.miDebugger.stop();
+ else
+ this.miDebugger.detach();
this.commandServer.close();
this.commandServer = undefined;
this.sendResponse(response);