Workaround for Windows: We cannot use SIGINT to interrupt gdb, so kill the process on disconnect

This commit is contained in:
Miro Spönemann 2020-02-26 16:12:02 +01:00
parent a6cef7c605
commit b055bd9e41
3 changed files with 28 additions and 8 deletions

View File

@ -4,7 +4,7 @@ import { GDBBackend } from 'cdt-gdb-adapter/dist/GDBBackend';
import * as mi from 'cdt-gdb-adapter/dist/mi';
import { ArduinoGDBBackend } from './arduino-gdb-backend';
import { ArduinoVariableHandler } from './arduino-variable-handler';
import { Scope } from 'vscode-debugadapter';
import { Scope, OutputEvent } from 'vscode-debugadapter';
export interface ArduinoLaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
arduinoCli?: string;
@ -51,9 +51,25 @@ export class ArduinoDebugSession extends GDBDebugSession {
}
}
protected pauseRequest(response: DebugProtocol.PauseResponse, args: DebugProtocol.PauseArguments): Promise<void> {
if (process.platform === 'win32') {
const message = 'Pause is not supported on Windows. Please stop the debug session and set a breakpoint instead.';
this.sendEvent(new OutputEvent(message));
this.sendErrorResponse(response, 1, message);
return Promise.resolve();
}
return super.pauseRequest(response, args);
}
protected async disconnectRequest(response: DebugProtocol.DisconnectResponse): Promise<void> {
try {
if (this.isRunning) {
if (process.platform === 'win32') {
// We cannot pause on Windows
this.arduinoBackend.kill();
this.sendResponse(response);
return;
}
// Need to pause first
const waitPromise = new Promise(resolve => this.waitPaused = resolve);
this.gdb.pause();

View File

@ -57,4 +57,15 @@ export class ArduinoGDBBackend extends GDBBackend {
return this.sendCommand('-target-detach');
}
kill(): void {
if (!this.proc) {
return;
}
if (process.platform === 'win32') {
spawn('taskkill', ['/pid', this.proc.pid.toString(), '/f', '/t']);
} else {
this.proc.kill('SIGKILL');
}
}
}

View File

@ -2,7 +2,6 @@ import { ChildProcessWithoutNullStreams } from 'child_process';
import { Readable } from 'stream';
import { MIParser } from "cdt-gdb-adapter/dist/MIParser";
const READY_TIMEOUT = 7000;
const LINE_REGEX = /(.*)(\r?\n)/;
export class ArduinoParser extends MIParser {
@ -13,19 +12,13 @@ export class ArduinoParser extends MIParser {
return new Promise((resolve, reject) => {
// Detect errors when the child process could not be spawned
proc.on('error', reject);
// Detect hanging process (does not print command prompt or error)
const timeout = setTimeout(() => {
reject(new Error(`No response from gdb after ${READY_TIMEOUT} ms.`));
}, READY_TIMEOUT);
this.waitReady = () => {
this.rejectReady = undefined;
clearTimeout(timeout);
resolve();
}
this.rejectReady = (error: Error) => {
this.waitReady = undefined;
clearTimeout(timeout);
reject(error);
}
// Detect unexpected termination