Skip to content

Commit 91bc884

Browse files
authored
Support auxiliary GDB with target parameters/connectCommands (#454)
* Support auxiliary GDB with target parameters/connectCommands. Before it only worked with target host and port settings. Signed-off-by: Jens Reinecke <[email protected]> * Another log message after connected to aux GDB. Fix test based on that. Signed-off-by: Jens Reinecke <[email protected]> * Skip new tests instead of accepting failure to save execution time. Skip aux GDB config tests if not remote, mode only supported for gdbtarget type. Signed-off-by: Jens Reinecke <[email protected]> --------- Signed-off-by: Jens Reinecke <[email protected]>
1 parent 541a2e2 commit 91bc884

File tree

2 files changed

+76
-18
lines changed

2 files changed

+76
-18
lines changed

src/desktop/GDBTargetDebugSession.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,13 @@ export class GDBTargetDebugSession extends GDBDebugSession {
642642
const targetString = targetHost
643643
? `${targetHost}:${targetPort}`
644644
: undefined;
645+
const defaultTarget = targetString ? [targetString] : [];
646+
const targetParameters = target.parameters ?? defaultTarget;
647+
const targetType = target.type ?? 'remote';
645648

646649
// Connect to remote server
647650
if (target.connectCommands === undefined) {
648-
this.targetType =
649-
target.type !== undefined ? target.type : 'remote';
650-
const defaultTarget = targetString ? [targetString] : [];
651-
const targetParameters = target.parameters ?? defaultTarget;
651+
this.targetType = targetType;
652652
await this.executeOrAbort(mi.sendTargetSelectRequest.bind(mi))(
653653
this.gdb,
654654
{
@@ -676,16 +676,23 @@ export class GDBTargetDebugSession extends GDBDebugSession {
676676
}
677677

678678
if (args.auxiliaryGdb && this.auxGdb) {
679+
this.logGDBRemote('connect auxiliary GDB to target');
679680
// Use connect commands to connect auxiliary GDB.
680-
this.logGDBRemote('connect to auxiliary GDB');
681-
const connectCommands: string[] = [
682-
...AuxiliaryConnectCommands,
683-
`target remote ${targetString}`,
684-
];
681+
const connectCommands: string[] = [...AuxiliaryConnectCommands];
682+
if (target.connectCommands) {
683+
connectCommands.push(...target.connectCommands);
684+
} else {
685+
connectCommands.push(
686+
`target ${targetType} ${targetParameters.join(' ')}`
687+
);
688+
}
685689
await this.executeOrAbort(
686690
this.auxGdb.sendCommands.bind(this.auxGdb)
687691
)(connectCommands);
688-
this.sendEvent(new OutputEvent('connected to auxiliary GDB'));
692+
this.sendEvent(
693+
new OutputEvent('connected auxiliary GDB to target')
694+
);
695+
this.logGDBRemote('connected auxiliary GDB to target');
689696
}
690697

691698
await this.setSessionState(SessionState.CONNECTED);

src/integration-tests/auxiliaryGdb.spec.ts

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ describe('auxiliary gdb configuration', function () {
4848
}
4949
});
5050

51-
it('correctly validates if auxiliary gdb mode can work with other settings', async function () {
52-
const expectToFail = gdbNonStop || gdbAsync === false;
53-
54-
const launchArgs = fillDefaults(this.test, {
55-
program,
56-
auxiliaryGdb: true,
57-
} as TargetLaunchRequestArguments);
51+
const auxUnsupported = gdbNonStop || gdbAsync === false || !isRemoteTest;
5852

53+
const testConnect = async (
54+
launchArgs: TargetLaunchRequestArguments,
55+
expectToFail: boolean
56+
) => {
5957
if (expectToFail) {
6058
// Expecting launch to fail, check for correct error message
6159
const expectedErrorMessage = gdbNonStop
@@ -72,6 +70,57 @@ describe('auxiliary gdb configuration', function () {
7270
)) as DebugProtocol.LaunchResponse;
7371
expect(launchResponse.success).to.be.true;
7472
}
73+
};
74+
75+
it('correctly validates if auxiliary gdb mode can work with other settings', async function () {
76+
if (!isRemoteTest) {
77+
this.skip();
78+
}
79+
80+
const expectToFail = gdbNonStop || gdbAsync === false;
81+
82+
const launchArgs = fillDefaults(this.test, {
83+
program,
84+
auxiliaryGdb: true,
85+
} as TargetLaunchRequestArguments);
86+
87+
await testConnect(launchArgs, expectToFail);
88+
});
89+
90+
it('can establish auxiliary gdb connection with target parameters', async function () {
91+
if (auxUnsupported) {
92+
this.skip();
93+
}
94+
95+
const launchArgs = fillDefaults(this.test, {
96+
program,
97+
auxiliaryGdb: true,
98+
target: {
99+
parameters: ['localhost:3333'],
100+
serverPortRegExp: 'Listening on port',
101+
serverParameters: ['--once', ':3333', program],
102+
},
103+
} as TargetLaunchRequestArguments);
104+
105+
await testConnect(launchArgs, false);
106+
});
107+
108+
it('can establish auxiliary gdb connection with target connect commands', async function () {
109+
if (auxUnsupported) {
110+
this.skip();
111+
}
112+
113+
const launchArgs = fillDefaults(this.test, {
114+
program,
115+
auxiliaryGdb: true,
116+
target: {
117+
connectCommands: ['-target-select remote localhost:3333'],
118+
serverPortRegExp: 'Listening on port',
119+
serverParameters: ['--once', ':3333', program],
120+
},
121+
} as TargetLaunchRequestArguments);
122+
123+
await testConnect(launchArgs, false);
75124
});
76125
});
77126

@@ -159,7 +208,9 @@ describe('auxiliary gdb', function () {
159208
);
160209
// Test if relevant output events came during 'beforeEach'
161210
expect(
162-
stdOutputContains('GDB Remote session: connect to auxiliary GDB')
211+
stdOutputContains(
212+
'GDB Remote session: connected auxiliary GDB to target'
213+
)
163214
).to.be.true;
164215
expect(
165216
stdOutputContains(

0 commit comments

Comments
 (0)