mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-08 03:46:33 +00:00
[debugger] Kill the gdb server on debug adapter process exit
This commit is contained in:
parent
8a78e09c6d
commit
fb50244a29
@ -68,7 +68,7 @@ export class ArduinoDebugFrontendApplicationContribution extends DebugFrontendAp
|
|||||||
await this.editorManager.open(sketchFileURI);
|
await this.editorManager.open(sketchFileURI);
|
||||||
await this.manager.start(current);
|
await this.manager.start(current);
|
||||||
} else {
|
} else {
|
||||||
this.messageService.error('Please open a valid INO file.')
|
this.messageService.error('Please open a sketch file to start debugging.')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.manager.start(current);
|
await this.manager.start(current);
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,17 +1,14 @@
|
|||||||
import { ContainerModule } from 'inversify';
|
import { ContainerModule } from 'inversify';
|
||||||
import { VariableContribution } from '@theia/variable-resolver/lib/browser';
|
import { VariableContribution } from '@theia/variable-resolver/lib/browser';
|
||||||
import { ArduinoVariableResolver } from './arduino-variable-resolver';
|
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 { DebugFrontendApplicationContribution } from '@theia/debug/lib/browser/debug-frontend-application-contribution';
|
||||||
import { DebugConfigurationManager } from '@theia/debug/lib/browser/debug-configuration-manager';
|
import { DebugConfigurationManager } from '@theia/debug/lib/browser/debug-configuration-manager';
|
||||||
import { ArduinoDebugConfigurationManager } from './arduino-debug-configuration-manager';
|
import { ArduinoDebugConfigurationManager } from './arduino-debug-configuration-manager';
|
||||||
import { ArduinoDebugFrontendApplicationContribution } from './arduino-debug-frontend-application-contribution';
|
import { ArduinoDebugFrontendApplicationContribution } from './arduino-debug-frontend-application-contribution';
|
||||||
import { ArduinoDebugSessionManager } from './arduino-debug-session-manager';
|
|
||||||
|
|
||||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||||
bind(ArduinoVariableResolver).toSelf().inSingletonScope();
|
bind(ArduinoVariableResolver).toSelf().inSingletonScope();
|
||||||
bind(VariableContribution).toService(ArduinoVariableResolver);
|
bind(VariableContribution).toService(ArduinoVariableResolver);
|
||||||
rebind(DebugSessionManager).to(ArduinoDebugSessionManager).inSingletonScope();
|
|
||||||
rebind(DebugConfigurationManager).to(ArduinoDebugConfigurationManager).inSingletonScope();
|
rebind(DebugConfigurationManager).to(ArduinoDebugConfigurationManager).inSingletonScope();
|
||||||
rebind(DebugFrontendApplicationContribution).to(ArduinoDebugFrontendApplicationContribution);
|
rebind(DebugFrontendApplicationContribution).to(ArduinoDebugFrontendApplicationContribution);
|
||||||
});
|
});
|
||||||
|
@ -258,6 +258,11 @@ export class CmsisDebugSession extends GDBDebugSession {
|
|||||||
this.progressEvent(0, 'Starting Debugger');
|
this.progressEvent(0, 'Starting Debugger');
|
||||||
this.sendEvent(new OutputEvent(`Starting debugger: ${JSON.stringify(args)}`));
|
this.sendEvent(new OutputEvent(`Starting debugger: ${JSON.stringify(args)}`));
|
||||||
await this.gdbServer.spawn(args);
|
await this.gdbServer.spawn(args);
|
||||||
|
process.on('exit', () => {
|
||||||
|
if (this.gdbServer.isRunning) {
|
||||||
|
this.gdbServer.kill();
|
||||||
|
}
|
||||||
|
});
|
||||||
await this.spawn(args);
|
await this.spawn(args);
|
||||||
this.checkServerErrors(gdbServerErrors);
|
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
|
// Stop gdb client
|
||||||
if (this.gdbServer.isRunning) {
|
try {
|
||||||
const killPromise = new Promise(resolve => {
|
await this.gdb.sendGDBExit();
|
||||||
setTimeout(() => {
|
} catch (e) {
|
||||||
this.gdbServer.kill();
|
// Need to catch here in case the connection has already been closed
|
||||||
resolve();
|
|
||||||
}, 5000);
|
|
||||||
});
|
|
||||||
try {
|
|
||||||
await this.gdb.sendGDBExit();
|
|
||||||
} catch (e) {
|
|
||||||
// Need to catch here in case the connection has already been closed
|
|
||||||
}
|
|
||||||
await killPromise;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user