Skip to content

Commit

Permalink
Reordered some code for stop/detach
Browse files Browse the repository at this point in the history
  • Loading branch information
haneefdm committed Sep 21, 2021
1 parent c2bb4b7 commit 4375d89
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/backend/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class GDBServer extends EventEmitter {
}

private onExit(code, signal) {
console.log('GDBServer: exited')
console.log(`GDBServer: exited ${code} ${signal}`);
this.process = null;
this.emit('exit', code, signal);
this.disconnectConsole();
Expand Down
54 changes: 34 additions & 20 deletions src/gdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export class GDBDebugSession extends DebugSession {
protected started: boolean;
protected debugReady: boolean;
protected miDebugger: MI2;
protected commandServer: net.Server;
protected forceDisassembly: boolean = false;
protected activeEditorPath: string = null;
// currentThreadId is the currently selected thread or where execution has stopped. It not very
Expand Down Expand Up @@ -947,8 +946,27 @@ export class GDBDebugSession extends DebugSession {
}

protected disconnectRequest(response: DebugProtocol.DisconnectResponse, args: DebugProtocol.DisconnectArguments): void {
let bkptsDeleted = false;
const doDisconnectProcessing = () => {
this.miDebugger.sendCommand('break-delete');
if (!bkptsDeleted) {
this.miDebugger.sendCommand('break-delete');
}
this.disableSendStoppedEvents = false;
this.attached = false;
let to = setTimeout(() => { // Give gdb a chance to disconnect and exit normally
to = null;
try {
this.server.exit();
}
catch (e) {}
}, 600); // Bit more than gbd-kill
this.server.once('exit', () => {
if (to) {
clearTimeout(to);
}
this.sendResponse(response);
});

if (args.terminateDebuggee || args.suspendDebuggee) {
// There is no such thing as terminate for us. Hopefully, the gdb-server will
// do the right thing and remain in halted state
Expand All @@ -958,29 +976,25 @@ export class GDBDebugSession extends DebugSession {
// should continue
this.miDebugger.detach();
}
this.attached = false;
if (this.commandServer) {
this.commandServer.close();
this.commandServer = undefined;
}
setTimeout(() => { // Give gdb a chance to disconnect and exit normally
try {
this.disableSendStoppedEvents = false;
this.server.exit();
}
catch (e) {}
finally {
this.sendResponse(response);
}
}, 600); // Bit more than gbd-kill
};

this.disableSendStoppedEvents = true;
if (this.miDebugger) {
if (this.stopped) {
bkptsDeleted = true;
this.miDebugger.sendCommand('break-delete');
}
let deferred = false;
if (/*(this.attached && !this.stopped) || */ args.terminateDebuggee || args.suspendDebuggee) {
this.miDebugger.once('generic-stopped', doDisconnectProcessing);
this.miDebugger.sendCommand('exec-interrupt');
} else {
if (!this.stopped) {
deferred = true;
this.miDebugger.once('generic-stopped', doDisconnectProcessing);
this.miDebugger.sendCommand('exec-interrupt');
}
} else if (this.stopped) {
this.sendContinue(true);
}
if (!deferred) {
doDisconnectProcessing();
}
}
Expand Down

0 comments on commit 4375d89

Please sign in to comment.