Skip to content

Commit

Permalink
Allow attaching (remote and local) with no program
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jonahgraham committed Apr 21, 2023
1 parent affd1b3 commit e3dd592
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/GDBDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,19 @@ export class GDBDebugSession extends LoggingDebugSession {
);

await this.spawn(args);
if (!args.program) {
this.sendErrorResponse(
response,
1,
'The program must be specified in the request arguments'
);
return;
if (request == 'launch') {
if (!args.program) {
this.sendErrorResponse(
response,
1,
'The program must be specified in the request arguments'
);
return;
}
}
if (args.program) {
await this.gdb.sendFileExecAndSymbols(args.program);
}
await this.gdb.sendFileExecAndSymbols(args.program);
await this.gdb.sendEnablePrettyPrint();

if (request === 'attach') {
Expand Down Expand Up @@ -997,7 +1001,7 @@ export class GDBDebugSession extends LoggingDebugSession {
}
response.body = {
allThreadsContinued: isAllThreadsContinued,
}
};
this.sendResponse(response);
} catch (err) {
this.sendErrorResponse(
Expand Down
4 changes: 3 additions & 1 deletion src/GDBTargetDebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ export class GDBTargetDebugSession extends GDBDebugSession {
try {
this.isAttach = true;
await this.spawn(args);
await this.gdb.sendFileExecAndSymbols(args.program);
if (args.program) {
await this.gdb.sendFileExecAndSymbols(args.program);
}
await this.gdb.sendEnablePrettyPrint();
if (args.imageAndSymbols) {
if (args.imageAndSymbols.symbolFileName) {
Expand Down
13 changes: 13 additions & 0 deletions src/integration-tests/attach.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,17 @@ describe('attach', function () {
await dc.attachHitBreakpoint(attachArgs, { line: 25, path: src });
expect(await dc.evaluate('argv[1]')).to.contain('running-from-spawn');
});

it('can attach and hit a breakpoint with no program specified', async function () {
if (isRemoteTest) {
// attachRemote.spec.ts is the test for when isRemoteTest
this.skip();
}

const attachArgs = fillDefaults(this.test, {
processId: `${inferior.pid}`,
} as AttachRequestArguments);
await dc.attachHitBreakpoint(attachArgs, { line: 25, path: src });
expect(await dc.evaluate('argv[1]')).to.contain('running-from-spawn');
});
});
16 changes: 16 additions & 0 deletions src/integration-tests/attachRemote.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import * as cp from 'child_process';
import * as path from 'path';
import * as os from 'os';
import {
TargetAttachRequestArguments,
TargetAttachArguments,
Expand Down Expand Up @@ -74,4 +75,19 @@ describe('attach remote', function () {
await dc.attachHitBreakpoint(attachArgs, { line: 3, path: emptySrc });
expect(await dc.evaluate('argv[1]')).to.contain('running-from-spawn');
});

it('can attach remote and hit a breakpoint without a program', async function () {
if (os.platform() === 'win32') {
// win32 host does support this use case
this.skip();
}
const attachArgs = fillDefaults(this.test, {
target: {
type: 'remote',
parameters: [`localhost:${port}`],
} as TargetAttachArguments,
} as TargetAttachRequestArguments);
await dc.attachHitBreakpoint(attachArgs, { line: 3, path: emptySrc });
expect(await dc.evaluate('argv[1]')).to.contain('running-from-spawn');
});
});

0 comments on commit e3dd592

Please sign in to comment.