[debugger] Kill the gdb server on debug adapter process exit

This commit is contained in:
Miro Spönemann 2020-01-22 16:52:05 +01:00
parent 8a78e09c6d
commit fb50244a29
4 changed files with 11 additions and 73 deletions

View File

@ -68,7 +68,7 @@ export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendAp
await this.editorManager.open(sketchFileURI);
await this.manager.start(current);
} else {
this.messageService.error('Please open a valid INO file.')
this.messageService.error('Please open a sketch file to start debugging.')
}
} else {
await this.manager.start(current);

View File

@ -1,55 +0,0 @@
import { DebugSessionManager } from "@theia/debug/lib/browser/debug-session-manager";
import { DebugSessionOptions } from "@theia/debug/lib/browser/debug-session-options";
import { DebugSession } from "@theia/debug/lib/browser/debug-session";
export class ArduinoDebugSessionManager extends DebugSessionManager {
static readonly COOL_DOWN_TIME = 5000;
protected arduinoSession?: Promise<DebugSession | undefined>;
protected lastSessionStopTime?: DOMHighResTimeStamp;
start(options: DebugSessionOptions) {
if (options.configuration.type === 'arduino') {
if (this.arduinoSession) {
this.messageService.info('A debug session is already running. You must stop the running session before starting a new one.')
return Promise.resolve(undefined);
}
const superStart = super.start.bind(this);
const promise = (async resolve => {
if (this.lastSessionStopTime) {
const now = performance.now();
if (now - this.lastSessionStopTime < ArduinoDebugSessionManager.COOL_DOWN_TIME) {
const waitTime = ArduinoDebugSessionManager.COOL_DOWN_TIME - Math.max(now - this.lastSessionStopTime, 0);
if (waitTime > 2000) {
const userWaitTime = Math.round(waitTime / 100) / 10;
this.messageService.info(`The previous debug session is cooling down. Waiting ${userWaitTime} seconds before starting a new session...`)
}
await new Promise(resolve => setTimeout(resolve, waitTime));
}
}
return superStart(options);
})();
this.arduinoSession = promise;
promise.then(session => {
if (!session)
this.arduinoSession = undefined;
});
return promise;
}
return super.start(options);
}
destroy(sessionId?: string): void {
if (this.arduinoSession) {
this.arduinoSession.then(session => {
if (session && sessionId === session.id) {
this.arduinoSession = undefined;
this.lastSessionStopTime = performance.now();
}
})
}
super.destroy(sessionId);
}
}

View File

@ -1,17 +1,14 @@
import { ContainerModule } from 'inversify';
import { VariableContribution } from '@theia/variable-resolver/lib/browser';
import { ArduinoVariableResolver } from './arduino-variable-resolver';
import { DebugSessionManager } from '@theia/debug/lib/browser/debug-session-manager';
import { DebugFrontendApplicationContribution } from '@theia/debug/lib/browser/debug-frontend-application-contribution';
import { DebugConfigurationManager } from '@theia/debug/lib/browser/debug-configuration-manager';
import { ArduinoDebugConfigurationManager } from './arduino-debug-configuration-manager';
import { ArduinoDebugFrontendApplicationContribution } from './arduino-debug-frontend-application-contribution';
import { ArduinoDebugSessionManager } from './arduino-debug-session-manager';
export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(ArduinoVariableResolver).toSelf().inSingletonScope();
bind(VariableContribution).toService(ArduinoVariableResolver);
rebind(DebugSessionManager).to(ArduinoDebugSessionManager).inSingletonScope();
rebind(DebugConfigurationManager).to(ArduinoDebugConfigurationManager).inSingletonScope();
rebind(DebugFrontendApplicationContribution).to(ArduinoDebugFrontendApplicationContribution);
});

View File

@ -258,6 +258,11 @@ export class CmsisDebugSession extends GDBDebugSession {
this.progressEvent(0, 'Starting Debugger');
this.sendEvent(new OutputEvent(`Starting debugger: ${JSON.stringify(args)}`));
await this.gdbServer.spawn(args);
process.on('exit', () => {
if (this.gdbServer.isRunning) {
this.gdbServer.kill();
}
});
await this.spawn(args);
this.checkServerErrors(gdbServerErrors);
@ -425,20 +430,11 @@ export class CmsisDebugSession extends GDBDebugSession {
}
}
// Stop gdb client and server - we give GDB five seconds to exit orderly before we kill the GDB server
if (this.gdbServer.isRunning) {
const killPromise = new Promise(resolve => {
setTimeout(() => {
this.gdbServer.kill();
resolve();
}, 5000);
});
try {
await this.gdb.sendGDBExit();
} catch (e) {
// Need to catch here in case the connection has already been closed
}
await killPromise;
// Stop gdb client
try {
await this.gdb.sendGDBExit();
} catch (e) {
// Need to catch here in case the connection has already been closed
}
}