Skip to content

Commit 954d6de

Browse files
committed
fix(initCommands): move commands to be executed before attaching
The current behavior described in documentation is misleading: "commands sent before attaching to inferior." The commands are sent after the GDB is attached, which is too late, especially if you wanted to set e.g. the baudrate. The "preRunCommands" should be executed after the connection to target.
1 parent 2e2b7c7 commit 954d6de

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/desktop/GDBTargetDebugSession.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ export class GDBTargetDebugSession extends GDBDebugSession {
572572
}
573573
}
574574

575+
// Send GDB commands before attaching to target
576+
await this.executeOrAbort(this.gdb.sendCommands.bind(this.gdb))(
577+
args.initCommands
578+
);
579+
575580
await this.setSessionState(SessionState.GDB_READY);
576581

577582
// Connect to remote server
@@ -620,11 +625,6 @@ export class GDBTargetDebugSession extends GDBDebugSession {
620625

621626
await this.setSessionState(SessionState.CONNECTED);
622627

623-
// Initialize debug target
624-
await this.executeOrAbort(this.gdb.sendCommands.bind(this.gdb))(
625-
args.initCommands
626-
);
627-
628628
// Initialize UART
629629
if (target.uart !== undefined) {
630630
this.initializeUARTConnection(target.uart, target.host);

src/gdb/GDBDebugSessionBase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
339339
}
340340
await this.gdb.sendEnablePrettyPrint();
341341

342+
await this.gdb.sendCommands(args.initCommands);
343+
342344
if (request === 'attach') {
343345
this.isAttach = true;
344346
const attachArgs = args as AttachRequestArguments;
@@ -350,8 +352,6 @@ export abstract class GDBDebugSessionBase extends LoggingDebugSession {
350352
);
351353
}
352354

353-
await this.gdb.sendCommands(args.initCommands);
354-
355355
if (request === 'launch') {
356356
const launchArgs = args as LaunchRequestArguments;
357357
if (launchArgs.arguments) {

src/web/GDBTargetDebugSession.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ export class GDBTargetDebugSession extends GDBDebugSession {
421421
}
422422
}
423423

424+
// Send GDB commands before attaching to target
425+
await this.executeOrAbort(this.gdb.sendCommands.bind(this.gdb))(
426+
args.initCommands
427+
);
428+
424429
await this.setSessionState(SessionState.GDB_READY);
425430

426431
// Connect to remote server
@@ -469,11 +474,6 @@ export class GDBTargetDebugSession extends GDBDebugSession {
469474

470475
await this.setSessionState(SessionState.CONNECTED);
471476

472-
// Initialize debug target
473-
await this.executeOrAbort(this.gdb.sendCommands.bind(this.gdb))(
474-
args.initCommands
475-
);
476-
477477
// Load additional code/symbols
478478
if (args.imageAndSymbols) {
479479
if (args.imageAndSymbols.imageFileName) {

0 commit comments

Comments
 (0)