Skip to content

Commit dbc8198

Browse files
committed
Add support for debugging the CLI server
1 parent b3a51d7 commit dbc8198

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

.vscode/launch.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
// change to 'true' debug the IDE or Query servers
2222
"IDE_SERVER_JAVA_DEBUG": "false",
2323
"QUERY_SERVER_JAVA_DEBUG": "false",
24+
"CLI_SERVER_JAVA_DEBUG": "false",
25+
// Uncomment to set the JAVA_HOME for the codeql instance to use
26+
// "CODEQL_JAVA_HOME": "/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home"
2427
}
2528
},
2629
{

extensions/ql-vscode/src/cli.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,16 @@ export class CodeQLCliServer implements Disposable {
257257
*/
258258
private async launchProcess(): Promise<child_process.ChildProcessWithoutNullStreams> {
259259
const codeQlPath = await this.getCodeQlPath();
260+
const args = [];
261+
if (shouldDebugCliServer()) {
262+
args.push('-J=-agentlib:jdwp=transport=dt_socket,address=localhost:9012,server=n,suspend=y,quiet=y');
263+
}
264+
260265
return await spawnServer(
261266
codeQlPath,
262267
'CodeQL CLI Server',
263268
['execute', 'cli-server'],
264-
[],
269+
args,
265270
this.logger,
266271
_data => { /**/ }
267272
);
@@ -605,7 +610,7 @@ export class CodeQLCliServer implements Disposable {
605610
if (target) subcommandArgs.push('--target', target);
606611
if (name) subcommandArgs.push('--name', name);
607612
subcommandArgs.push(archivePath);
608-
613+
609614
return await this.runCodeQlCliCommand(['database', 'unbundle'], subcommandArgs, `Extracting ${archivePath} to directory ${target}`);
610615
}
611616

@@ -1049,6 +1054,12 @@ export function shouldDebugQueryServer() {
10491054
&& process.env.QUERY_SERVER_JAVA_DEBUG?.toLocaleLowerCase() !== 'false';
10501055
}
10511056

1057+
export function shouldDebugCliServer() {
1058+
return 'CLI_SERVER_JAVA_DEBUG' in process.env
1059+
&& process.env.CLI_SERVER_JAVA_DEBUG !== '0'
1060+
&& process.env.CLI_SERVER_JAVA_DEBUG?.toLocaleLowerCase() !== 'false';
1061+
}
1062+
10521063
export class CliVersionConstraint {
10531064

10541065
/**
@@ -1088,6 +1099,16 @@ export class CliVersionConstraint {
10881099
*/
10891100
public static CLI_VERSION_WITH_DATABASE_UNBUNDLE = new SemVer('2.6.0');
10901101

1102+
/**
1103+
* CLI version where the `--no-precompile` option for pack creation was introduced.
1104+
*/
1105+
public static CLI_VERSION_WITH_NO_PRECOMPILE = new SemVer('2.7.0');
1106+
1107+
/**
1108+
* CLI version where `pack packlist` layout changed from array to object
1109+
*/
1110+
public static CLI_VERSION_PACK_PACKLIST_LAYOUT_CHANGE = new SemVer('2.7.0');
1111+
10911112
constructor(private readonly cli: CodeQLCliServer) {
10921113
/**/
10931114
}
@@ -1124,4 +1145,11 @@ export class CliVersionConstraint {
11241145
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_DATABASE_UNBUNDLE);
11251146
}
11261147

1148+
async supportsNoPrecompile() {
1149+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_WITH_NO_PRECOMPILE);
1150+
}
1151+
1152+
async usesNewPackPacklistLayout() {
1153+
return this.isVersionAtLeast(CliVersionConstraint.CLI_VERSION_PACK_PACKLIST_LAYOUT_CHANGE);
1154+
}
11271155
}

0 commit comments

Comments
 (0)