Skip to content

Commit b055bd9

Browse files
committed
Workaround for Windows: We cannot use SIGINT to interrupt gdb, so kill the process on disconnect
1 parent a6cef7c commit b055bd9

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

arduino-debugger-extension/src/node/debug-adapter/arduino-debug-session.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { GDBBackend } from 'cdt-gdb-adapter/dist/GDBBackend';
44
import * as mi from 'cdt-gdb-adapter/dist/mi';
55
import { ArduinoGDBBackend } from './arduino-gdb-backend';
66
import { ArduinoVariableHandler } from './arduino-variable-handler';
7-
import { Scope } from 'vscode-debugadapter';
7+
import { Scope, OutputEvent } from 'vscode-debugadapter';
88

99
export interface ArduinoLaunchRequestArguments extends DebugProtocol.LaunchRequestArguments {
1010
arduinoCli?: string;
@@ -51,9 +51,25 @@ export class ArduinoDebugSession extends GDBDebugSession {
5151
}
5252
}
5353

54+
protected pauseRequest(response: DebugProtocol.PauseResponse, args: DebugProtocol.PauseArguments): Promise<void> {
55+
if (process.platform === 'win32') {
56+
const message = 'Pause is not supported on Windows. Please stop the debug session and set a breakpoint instead.';
57+
this.sendEvent(new OutputEvent(message));
58+
this.sendErrorResponse(response, 1, message);
59+
return Promise.resolve();
60+
}
61+
return super.pauseRequest(response, args);
62+
}
63+
5464
protected async disconnectRequest(response: DebugProtocol.DisconnectResponse): Promise<void> {
5565
try {
5666
if (this.isRunning) {
67+
if (process.platform === 'win32') {
68+
// We cannot pause on Windows
69+
this.arduinoBackend.kill();
70+
this.sendResponse(response);
71+
return;
72+
}
5773
// Need to pause first
5874
const waitPromise = new Promise(resolve => this.waitPaused = resolve);
5975
this.gdb.pause();

arduino-debugger-extension/src/node/debug-adapter/arduino-gdb-backend.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,15 @@ export class ArduinoGDBBackend extends GDBBackend {
5757
return this.sendCommand('-target-detach');
5858
}
5959

60+
kill(): void {
61+
if (!this.proc) {
62+
return;
63+
}
64+
if (process.platform === 'win32') {
65+
spawn('taskkill', ['/pid', this.proc.pid.toString(), '/f', '/t']);
66+
} else {
67+
this.proc.kill('SIGKILL');
68+
}
69+
}
70+
6071
}

arduino-debugger-extension/src/node/debug-adapter/arduino-parser.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ChildProcessWithoutNullStreams } from 'child_process';
22
import { Readable } from 'stream';
33
import { MIParser } from "cdt-gdb-adapter/dist/MIParser";
44

5-
const READY_TIMEOUT = 7000;
65
const LINE_REGEX = /(.*)(\r?\n)/;
76

87
export class ArduinoParser extends MIParser {
@@ -13,19 +12,13 @@ export class ArduinoParser extends MIParser {
1312
return new Promise((resolve, reject) => {
1413
// Detect errors when the child process could not be spawned
1514
proc.on('error', reject);
16-
// Detect hanging process (does not print command prompt or error)
17-
const timeout = setTimeout(() => {
18-
reject(new Error(`No response from gdb after ${READY_TIMEOUT} ms.`));
19-
}, READY_TIMEOUT);
2015

2116
this.waitReady = () => {
2217
this.rejectReady = undefined;
23-
clearTimeout(timeout);
2418
resolve();
2519
}
2620
this.rejectReady = (error: Error) => {
2721
this.waitReady = undefined;
28-
clearTimeout(timeout);
2922
reject(error);
3023
}
3124
// Detect unexpected termination

0 commit comments

Comments
 (0)