Skip to content

Commit ea8e74d

Browse files
committed
Allow attaching (remote and local) with no program
There is no strict need to have a program passed to GDB when attaching (remote or local). Either the program can be downloaded from the remote or otherwise read by GDB, or if not possible then GDB can do symbol-free debugging. Previously in eclipse-cdt-cloud#228 some work was done to better error when program was not specified. This change loosens the restrictions slightly. If the program is not specified, it is still a warning in VSCode because of [package.json](https://github.com/eclipse-cdt-cloud/cdt-gdb-vscode/blob/22a9f1048f9030689ed1f5f2b3e5d5e48df9047d/package.json#L205-L207) See this comment for how it is presented to a user: eclipse-cdt-cloud#261 (comment) Part of eclipse-cdt-cloud#261
1 parent affd1b3 commit ea8e74d

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

src/GDBDebugSession.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,19 @@ export class GDBDebugSession extends LoggingDebugSession {
338338
);
339339

340340
await this.spawn(args);
341-
if (!args.program) {
342-
this.sendErrorResponse(
343-
response,
344-
1,
345-
'The program must be specified in the request arguments'
346-
);
347-
return;
341+
if (request == 'launch') {
342+
if (!args.program) {
343+
this.sendErrorResponse(
344+
response,
345+
1,
346+
'The program must be specified in the request arguments'
347+
);
348+
return;
349+
}
350+
}
351+
if (args.program) {
352+
await this.gdb.sendFileExecAndSymbols(args.program);
348353
}
349-
await this.gdb.sendFileExecAndSymbols(args.program);
350354
await this.gdb.sendEnablePrettyPrint();
351355

352356
if (request === 'attach') {
@@ -997,7 +1001,7 @@ export class GDBDebugSession extends LoggingDebugSession {
9971001
}
9981002
response.body = {
9991003
allThreadsContinued: isAllThreadsContinued,
1000-
}
1004+
};
10011005
this.sendResponse(response);
10021006
} catch (err) {
10031007
this.sendErrorResponse(

src/GDBTargetDebugSession.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ export class GDBTargetDebugSession extends GDBDebugSession {
275275
try {
276276
this.isAttach = true;
277277
await this.spawn(args);
278-
await this.gdb.sendFileExecAndSymbols(args.program);
278+
if (args.program) {
279+
await this.gdb.sendFileExecAndSymbols(args.program);
280+
}
279281
await this.gdb.sendEnablePrettyPrint();
280282
if (args.imageAndSymbols) {
281283
if (args.imageAndSymbols.symbolFileName) {

src/integration-tests/attach.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,17 @@ describe('attach', function () {
5151
await dc.attachHitBreakpoint(attachArgs, { line: 25, path: src });
5252
expect(await dc.evaluate('argv[1]')).to.contain('running-from-spawn');
5353
});
54+
55+
it('can attach and hit a breakpoint with no program specified', async function () {
56+
if (isRemoteTest) {
57+
// attachRemote.spec.ts is the test for when isRemoteTest
58+
this.skip();
59+
}
60+
61+
const attachArgs = fillDefaults(this.test, {
62+
processId: `${inferior.pid}`,
63+
} as AttachRequestArguments);
64+
await dc.attachHitBreakpoint(attachArgs, { line: 25, path: src });
65+
expect(await dc.evaluate('argv[1]')).to.contain('running-from-spawn');
66+
});
5467
});

src/integration-tests/attachRemote.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,15 @@ describe('attach remote', function () {
7474
await dc.attachHitBreakpoint(attachArgs, { line: 3, path: emptySrc });
7575
expect(await dc.evaluate('argv[1]')).to.contain('running-from-spawn');
7676
});
77+
78+
it('can attach remote and hit a breakpoint without a program', async function () {
79+
const attachArgs = fillDefaults(this.test, {
80+
target: {
81+
type: 'remote',
82+
parameters: [`localhost:${port}`],
83+
} as TargetAttachArguments,
84+
} as TargetAttachRequestArguments);
85+
await dc.attachHitBreakpoint(attachArgs, { line: 3, path: emptySrc });
86+
expect(await dc.evaluate('argv[1]')).to.contain('running-from-spawn');
87+
});
7788
});

0 commit comments

Comments
 (0)