Skip to content

Commit

Permalink
Disconnect before exit for remote targets (#273)
Browse files Browse the repository at this point in the history
This changes fixes an issue whereby when debugging on a remote target,
the exit sequence is not entirely correct. We should send a "disconnect"
GDB command before "exit". This prevents a messages such as "Remote
doesn't know how to detach" and "Cannot execute this command while the
target is running" from appearing, as they can be somewhat misleading.
  • Loading branch information
AdhamRagabMCHP committed Jul 5, 2023
1 parent a08dee7 commit b59b928
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/GDBTargetDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export class GDBTargetDebugSession extends GDBDebugSession {
protected gdbserver?: ChildProcess;
protected killGdbServer = true;

/**
* Define the target type here such that we can run the "disconnect"
* command when servicing the disconnect request if the target type
* is remote.
*/
protected targetType?: string;

protected async attachOrLaunchRequest(
response: DebugProtocol.Response,
request: 'launch' | 'attach',
Expand Down Expand Up @@ -293,7 +300,7 @@ export class GDBTargetDebugSession extends GDBDebugSession {
}

if (target.connectCommands === undefined) {
const targetType =
this.targetType =
target.type !== undefined ? target.type : 'remote';
let defaultTarget: string[];
if (target.port !== undefined) {
Expand All @@ -310,12 +317,12 @@ export class GDBTargetDebugSession extends GDBDebugSession {
? target.parameters
: defaultTarget;
await mi.sendTargetSelectRequest(this.gdb, {
type: targetType,
type: this.targetType,
parameters: targetParameters,
});
this.sendEvent(
new OutputEvent(
`connected to ${targetType} target ${targetParameters.join(
`connected to ${this.targetType} target ${targetParameters.join(
' '
)}`
)
Expand Down Expand Up @@ -373,6 +380,9 @@ export class GDBTargetDebugSession extends GDBDebugSession {
_args: DebugProtocol.DisconnectArguments
): Promise<void> {
try {
if (this.targetType === "remote") {
await this.gdb.sendCommand("disconnect");
}
await this.gdb.sendGDBExit();
if (this.killGdbServer) {
await this.stopGDBServer();
Expand Down

0 comments on commit b59b928

Please sign in to comment.