-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow pre-filling launch/attach on command line to adapter
Start the adapter using the given configuration as a starting point for the args in `launch` or `attach` request. For example, the default GDB can be set like this: ```sh node debugTargetAdapter.js --config='{"gdb":"arm-none-eabi-gdb"}' ``` The config can be passed on the command line as JSON, or a response file can be used by starting the argument with `@`. The rest of the argument will be interpreted as a file name to read. For example, to start the adapter defaulting to a process ID to attach to, create a file containing the JSON and reference it like this: ```sh cat >config.json <<END { "processId": 1234 } END node debugAdapter.js [email protected] ``` Similar to `--config`, the `--config-frozen` sets the provided configuration fields in the args to the `launch` or `attach` request to the given values, not allowing the user to override them. Specifying which type of request is allowed (`launch` or `attach`) can be specified with the `request` field. For example, the adapter can be configured for program to be frozen to a specific value. This may be useful for starting adapters in a container and exposing the server port. ```sh node debugAdapter.js --server=23221 --config-frozen='{"program":"/path/to/my.elf"}' ``` Fixes #227
- Loading branch information
1 parent
419e439
commit 7e2014f
Showing
6 changed files
with
320 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,54 @@ Build is pretty simple. | |
yarn | ||
``` | ||
|
||
## Running | ||
|
||
The entry point for the adapter is `cdtDebugAdapter` for local debugging | ||
and `cdtDebugTargetAdapter` for target (remote) debugging. | ||
|
||
### Command line arguments | ||
|
||
#### `--server=PORT` | ||
|
||
Start the adapter listening on the given port instead of on stdin/stdout. | ||
|
||
#### `--config=INITIALCONFIG` | ||
|
||
Start the adapter using the given configuration as a starting point for the args in `launch` or `attach` request. | ||
|
||
For example, the default GDB can be set like this: | ||
|
||
```sh | ||
node debugTargetAdapter.js --config='{"gdb":"arm-none-eabi-gdb"}' | ||
``` | ||
|
||
The config can be passed on the command line as JSON, or a response file can be used by starting the argument with `@`. | ||
The rest of the argument will be interpreted as a file name to read. | ||
For example, to start the adapter defaulting to a process ID to attach to, create a file containing the JSON and reference it like this: | ||
|
||
```sh | ||
cat >config.json <<END | ||
{ | ||
"processId": 1234 | ||
} | ||
END | ||
node debugAdapter.js [email protected] | ||
``` | ||
#### `--config-frozen=FROZENCONFIG` | ||
Similar to `--config`, the `--config-frozen` sets the provided configuration fields in the args to the `launch` or `attach` request to the given values, not allowing the user to override them. | ||
Specifying which type of request is allowed (`launch` or `attach`) can be specified with the `request` field. | ||
When freezing the type of request, regardless of which type of request the user requested, the frozen request type will be used. | ||
For example, the adapter can be configured for program to be frozen to a specific value. | ||
This may be useful for starting adapters in a container and exposing the server port. | ||
```sh | ||
node debugAdapter.js --server=23221 --config-frozen='{"program":"/path/to/my.elf"}' | ||
``` | ||
## Testing | ||
Testing of the adapter can be run with `yarn test`. See [Integration Tests readme](https://github.com/eclipse-cdt-cloud/cdt-gdb-adapter/blob/main/src/integration-tests/README.md) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2023 Kichwa Coders Canada Inc. and others. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*********************************************************************/ | ||
|
||
import * as path from 'path'; | ||
import * as tmp from 'tmp'; | ||
import * as fs from 'fs'; | ||
import { | ||
LaunchRequestArguments, | ||
AttachRequestArguments, | ||
} from '../GDBDebugSession'; | ||
import { | ||
debugServerPort, | ||
defaultAdapter, | ||
fillDefaults, | ||
standardBeforeEach, | ||
testProgramsDir, | ||
} from './utils'; | ||
|
||
describe('config', function () { | ||
const emptyProgram = path.join(testProgramsDir, 'empty'); | ||
const emptySrc = path.join(testProgramsDir, 'empty.c'); | ||
|
||
async function verifyLaunchWorks( | ||
test: Mocha.Context, | ||
commandLine: string[], | ||
requestArgs: LaunchRequestArguments | ||
) { | ||
if (debugServerPort) { | ||
// This test requires launching the adapter to work | ||
test.skip(); | ||
} | ||
|
||
const dc = await standardBeforeEach(defaultAdapter, commandLine); | ||
|
||
try { | ||
await dc.hitBreakpoint(fillDefaults(test.test, requestArgs), { | ||
path: emptySrc, | ||
line: 3, | ||
}); | ||
} finally { | ||
await dc.stop(); | ||
} | ||
} | ||
|
||
it('can specify program via --config=', async function () { | ||
const config = { program: emptyProgram }; | ||
await verifyLaunchWorks( | ||
this, | ||
[`--config=${JSON.stringify(config)}`], | ||
{} as LaunchRequestArguments | ||
); | ||
}); | ||
|
||
it('program via --config= can be overridden', async function () { | ||
const config = { program: '/program/that/does/not/exist' }; | ||
await verifyLaunchWorks(this, [`--config=${JSON.stringify(config)}`], { | ||
program: emptyProgram, | ||
} as LaunchRequestArguments); | ||
}); | ||
|
||
it('can specify program via --config-frozen=', async function () { | ||
const config = { program: emptyProgram }; | ||
await verifyLaunchWorks( | ||
this, | ||
[`--config-frozen=${JSON.stringify(config)}`], | ||
{} as LaunchRequestArguments | ||
); | ||
}); | ||
|
||
it('program via --config-frozen= can not be overridden', async function () { | ||
const config = { program: emptyProgram }; | ||
await verifyLaunchWorks( | ||
this, | ||
[`--config-frozen=${JSON.stringify(config)}`], | ||
{ | ||
program: '/program/that/does/not/exist', | ||
} as LaunchRequestArguments | ||
); | ||
}); | ||
|
||
it('can specify program via --config= using response file', async function () { | ||
const config = { program: emptyProgram }; | ||
const json = JSON.stringify(config); | ||
const jsonFile = tmp.fileSync(); | ||
fs.writeFileSync(jsonFile.fd, json); | ||
fs.closeSync(jsonFile.fd); | ||
|
||
await verifyLaunchWorks( | ||
this, | ||
[`--config=@${jsonFile.name}`], | ||
{} as LaunchRequestArguments | ||
); | ||
}); | ||
|
||
it('can specify program via --config-frozen= using response file', async function () { | ||
const config = { program: emptyProgram }; | ||
const json = JSON.stringify(config); | ||
const jsonFile = tmp.fileSync(); | ||
fs.writeFileSync(jsonFile.fd, json); | ||
fs.closeSync(jsonFile.fd); | ||
|
||
await verifyLaunchWorks( | ||
this, | ||
[`--config-frozen=@${jsonFile.name}`], | ||
{} as LaunchRequestArguments | ||
); | ||
}); | ||
|
||
// This test most closely models the original design goal | ||
// for the change that added --config and --config-frozen | ||
// as discussed in #227 and #228 | ||
// In summary we force a launch request for the given program, | ||
// but the user does not specify the program and specifies | ||
// an attach request | ||
it('config frozen forces specific launch type', async function () { | ||
if (debugServerPort) { | ||
// This test requires launching the adapter to work | ||
this.skip(); | ||
} | ||
|
||
const config = { request: 'launch', program: emptyProgram }; | ||
|
||
// Launch the adapter with the frozen config | ||
const dc = await standardBeforeEach(defaultAdapter, [ | ||
`--config-frozen=${JSON.stringify(config)}`, | ||
]); | ||
|
||
try { | ||
await Promise.all([ | ||
// Do an attach request omitting the program that we want | ||
// the adapter to force into a launch request | ||
dc.attachRequest( | ||
fillDefaults(this.test, {} as AttachRequestArguments) | ||
), | ||
|
||
// The rest of this code is to ensure we launcher properly by verifying | ||
// we can run to a breakpoint | ||
dc.waitForEvent('initialized').then((_event) => { | ||
return dc | ||
.setBreakpointsRequest({ | ||
lines: [3], | ||
breakpoints: [{ line: 3 }], | ||
source: { path: emptySrc }, | ||
}) | ||
.then((_response) => { | ||
return dc.configurationDoneRequest(); | ||
}); | ||
}), | ||
dc.assertStoppedLocation('breakpoint', { | ||
path: emptySrc, | ||
line: 3, | ||
}), | ||
]); | ||
} finally { | ||
await dc.stop(); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.