Skip to content

Commit 3f27385

Browse files
committed
New "pause" button on debugger that sends SIGINT to remote process
Since fixing the restart button, the pause button is always enabled. There doesn't seem to be a way to disable it, so let's make it do something useful. For example, if a python program is run with PYTHONINSPECT=1 environment variable, then the pause button will interrupt the program an open a REPL for inspecting the current program state. Know bug: pause button does not work after restarting with the restart button. This is caused by <microsoft/vscode#88784>.
1 parent 9577157 commit 3f27385

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
55

66
## Unreleased
77
### Added
8+
- New "pause" button on debugger that sends SIGINT to remote process
89
- New "interactiveTerminal" debugger option to run remote programs in
910
interactive terminal instead of output pane
1011
### Fixed

src/debugServer.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DebugSession, Event, TerminatedEvent } from 'vscode-debugadapter';
1+
import { DebugSession, Event, TerminatedEvent, Thread, ThreadEvent, StoppedEvent, ContinuedEvent } from 'vscode-debugadapter';
22
import { DebugProtocol } from 'vscode-debugprotocol';
33

44
/**
@@ -13,6 +13,8 @@ export interface LaunchRequestArguments extends DebugProtocol.LaunchRequestArgum
1313
interactiveTerminal: boolean;
1414
}
1515

16+
const THREAD_ID = 0;
17+
1618
export class Ev3devBrowserDebugSession extends DebugSession {
1719
protected initializeRequest(response: DebugProtocol.InitializeResponse,
1820
args: DebugProtocol.InitializeRequestArguments): void {
@@ -29,6 +31,10 @@ export class Ev3devBrowserDebugSession extends DebugSession {
2931

3032
protected customRequest(command: string, response: DebugProtocol.Response, args: any): void {
3133
switch (command) {
34+
case 'ev3devBrowser.debugger.thread':
35+
this.sendEvent(new ThreadEvent(args, THREAD_ID));
36+
this.sendResponse(response);
37+
break;
3238
case 'ev3devBrowser.debugger.terminate':
3339
this.sendEvent(new TerminatedEvent());
3440
this.sendResponse(response);
@@ -41,6 +47,20 @@ export class Ev3devBrowserDebugSession extends DebugSession {
4147
this.sendEvent(new Event('ev3devBrowser.debugger.stop', args));
4248
this.sendResponse(response);
4349
}
50+
51+
protected threadsRequest(response: DebugProtocol.ThreadsResponse): void {
52+
response.body = {
53+
threads: [
54+
new Thread(THREAD_ID, 'thread')
55+
]
56+
};
57+
this.sendResponse(response);
58+
}
59+
60+
protected pauseRequest(response: DebugProtocol.PauseResponse, args: DebugProtocol.PauseArguments): void {
61+
this.sendEvent(new Event('ev3devBrowser.debugger.interrupt', args));
62+
this.sendResponse(response);
63+
}
4464
}
4565

4666
if (require.main === module) {

src/extension.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ async function handleCustomDebugEvent(event: vscode.DebugSessionCustomEvent): Pr
180180
ch.on('close', () => {
181181
if (debugRestarting) {
182182
activeDebugSessions.add(event.session.id);
183+
event.session.customRequest('ev3devBrowser.debugger.thread', 'started');
183184
} else {
184185
event.session.customRequest('ev3devBrowser.debugger.terminate');
185186
}
@@ -204,6 +205,7 @@ async function handleCustomDebugEvent(event: vscode.DebugSessionCustomEvent): Pr
204205
ch.destroy();
205206
});
206207
debugTerminal.show();
208+
event.session.customRequest('ev3devBrowser.debugger.thread', 'started');
207209
}
208210
else {
209211
output.show(true);
@@ -216,6 +218,7 @@ async function handleCustomDebugEvent(event: vscode.DebugSessionCustomEvent): Pr
216218
output.clear();
217219
output.appendLine(`Restarting: ${command}`);
218220
output.appendLine('----------');
221+
event.session.customRequest('ev3devBrowser.debugger.thread', 'started');
219222
} else {
220223
event.session.customRequest('ev3devBrowser.debugger.terminate');
221224
}
@@ -242,6 +245,7 @@ async function handleCustomDebugEvent(event: vscode.DebugSessionCustomEvent): Pr
242245
output.append(chunk.toString());
243246
});
244247
output.appendLine('----------');
248+
event.session.customRequest('ev3devBrowser.debugger.thread', 'started');
245249
}
246250
activeDebugSessions.add(event.session.id);
247251
}
@@ -257,6 +261,12 @@ async function handleCustomDebugEvent(event: vscode.DebugSessionCustomEvent): Pr
257261
device.exec('conrun-kill --signal=SIGKILL');
258262
}
259263
break;
264+
case 'ev3devBrowser.debugger.interrupt':
265+
device = ev3devBrowserProvider.getDeviceSync();
266+
if (activeDebugSessions.has(event.session.id) && device && device.isConnected) {
267+
device.exec('conrun-kill --signal=SIGINT');
268+
}
269+
break;
260270
}
261271
}
262272

0 commit comments

Comments
 (0)