Skip to content

Commit 697f438

Browse files
committed
Add pause and detach before stop of gdb and server
1 parent def53ab commit 697f438

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/cmsis-backend.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import * as mi from './mi';
2828

2929
export class CmsisBackend extends GDBBackend {
3030

31+
public get isRunning(): boolean {
32+
return !!this.out;
33+
}
34+
3135
public pause() {
3236
mi.sendExecInterrupt(this);
3337
return true;

src/cmsis-debug-session.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,19 @@ export class CmsisDebugSession extends GDBDebugSession {
184184

185185
protected async disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): Promise<void> {
186186
try {
187+
if (this.isRunning) {
188+
// Need to pause first
189+
const waitPromise = new Promise(resolve => this.waitPaused = resolve);
190+
this.gdb.pause();
191+
await waitPromise;
192+
}
193+
if ((this.gdb as CmsisBackend).isRunning) {
194+
try {
195+
await mi.sendTargetDetach(this.gdb);
196+
} catch (e) {
197+
// Need to catch here as the command result being returned will never exist as it's detached
198+
}
199+
}
187200
await super.disconnectRequest(response, args);
188201
this.gdbServer.kill();
189202
if (!args || !args.restart) {

src/mi.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,9 @@ export function sendUserInput(gdb: GDBBackend, command: string): Promise<any> {
7272
return gdb.sendCommand(command);
7373
}
7474

75+
export function sendTargetDetach(gdb: GDBBackend) {
76+
const command = '-target-detach';
77+
return gdb.sendCommand(command);
78+
}
79+
7580
export * from 'cdt-gdb-adapter/dist/mi';

0 commit comments

Comments
 (0)