mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-27 05:06:42 +00:00
Workaround for Windows: We cannot use SIGINT to interrupt gdb, so kill the process on disconnect
This commit is contained in:
parent
a6cef7c605
commit
b055bd9e41
@ -4,7 +4,7 @@ import { GDBBackend } from 'cdt-gdb-adapter/dist/GDBBackend';
|
|||||||
import * as mi from 'cdt-gdb-adapter/dist/mi';
|
import * as mi from 'cdt-gdb-adapter/dist/mi';
|
||||||
import { ArduinoGDBBackend } from './arduino-gdb-backend';
|
import { ArduinoGDBBackend } from './arduino-gdb-backend';
|
||||||
import { ArduinoVariableHandler } from './arduino-variable-handler';
|
import { ArduinoVariableHandler } from './arduino-variable-handler';
|
||||||
import { Scope } from 'vscode-debugadapter';
|
import { Scope, OutputEvent } from 'vscode-debugadapter';
|
||||||
|
|
||||||
export interface ArduinoLaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
|
export interface ArduinoLaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
|
||||||
arduinoCli?: string;
|
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> {
|
protected async disconnectRequest(response: DebugProtocol.DisconnectResponse): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (this.isRunning) {
|
if (this.isRunning) {
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
// We cannot pause on Windows
|
||||||
|
this.arduinoBackend.kill();
|
||||||
|
this.sendResponse(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Need to pause first
|
// Need to pause first
|
||||||
const waitPromise = new Promise(resolve => this.waitPaused = resolve);
|
const waitPromise = new Promise(resolve => this.waitPaused = resolve);
|
||||||
this.gdb.pause();
|
this.gdb.pause();
|
||||||
|
@ -57,4 +57,15 @@ export class ArduinoGDBBackend extends GDBBackend {
|
|||||||
return this.sendCommand('-target-detach');
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ import { ChildProcessWithoutNullStreams } from 'child_process';
|
|||||||
import { Readable } from 'stream';
|
import { Readable } from 'stream';
|
||||||
import { MIParser } from "cdt-gdb-adapter/dist/MIParser";
|
import { MIParser } from "cdt-gdb-adapter/dist/MIParser";
|
||||||
|
|
||||||
const READY_TIMEOUT = 7000;
|
|
||||||
const LINE_REGEX = /(.*)(\r?\n)/;
|
const LINE_REGEX = /(.*)(\r?\n)/;
|
||||||
|
|
||||||
export class ArduinoParser extends MIParser {
|
export class ArduinoParser extends MIParser {
|
||||||
@ -13,19 +12,13 @@ export class ArduinoParser extends MIParser {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Detect errors when the child process could not be spawned
|
// Detect errors when the child process could not be spawned
|
||||||
proc.on('error', reject);
|
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.waitReady = () => {
|
||||||
this.rejectReady = undefined;
|
this.rejectReady = undefined;
|
||||||
clearTimeout(timeout);
|
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
this.rejectReady = (error: Error) => {
|
this.rejectReady = (error: Error) => {
|
||||||
this.waitReady = undefined;
|
this.waitReady = undefined;
|
||||||
clearTimeout(timeout);
|
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
// Detect unexpected termination
|
// Detect unexpected termination
|
||||||
|
Loading…
x
Reference in New Issue
Block a user