Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow attaching (remote and local) with no program #262

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});