Skip to content

Commit

Permalink
Ensure debugger is suspended before disconnecting
Browse files Browse the repository at this point in the history
This solution is similar to #287, except the pause method is not based
on an arbitrary timeout, but an emitted event from GDB that indicates
the target is actually suspended.

Signed-off-by: Luke Zhang <luke.zhang@microchip.com>
  • Loading branch information
Luke-zhang-mchp committed Nov 8, 2024
1 parent 75d56b2 commit b092c12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
13 changes: 6 additions & 7 deletions src/desktop/GDBTargetDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,13 +471,12 @@ export class GDBTargetDebugSession extends GDBDebugSession {
this.serialPort.close();

if (this.targetType === 'remote') {
if (this.gdb.getAsyncMode() && this.isRunning) {
// See #295 - this use of "await" is to try to slightly delay the
// call to disconnect. A proper solution that waits for the
// interrupt to be successful is needed to avoid future
// "Cannot execute this command while the target is running"
// errors
await this.gdb.sendCommand('interrupt');
this.waitPausedNeeded =
this.gdb.getAsyncMode() && this.isRunning;

if (this.waitPausedNeeded) {
// Need to pause first, then disconnect and exit
await this.pause();
}

await this.gdb.sendCommand('disconnect');
Expand Down
13 changes: 6 additions & 7 deletions src/web/GDBTargetDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,12 @@ export class GDBTargetDebugSession extends GDBDebugSession {
): Promise<void> {
try {
if (this.targetType === 'remote') {
if (this.gdb.getAsyncMode() && this.isRunning) {
// See #295 - this use of "await" is to try to slightly delay the
// call to disconnect. A proper solution that waits for the
// interrupt to be successful is needed to avoid future
// "Cannot execute this command while the target is running"
// errors
await this.gdb.sendCommand('interrupt');
this.waitPausedNeeded =
this.gdb.getAsyncMode() && this.isRunning;

if (this.waitPausedNeeded) {
// Need to pause first, then disconnect and exit
await this.pause();
}

await this.gdb.sendCommand('disconnect');
Expand Down

0 comments on commit b092c12

Please sign in to comment.