Skip to content

Commit

Permalink
package.json: add showLog/logOutput/dlvFlags to go.delveConfig setting
Browse files Browse the repository at this point in the history
These allow to enable delve-side logging and set custom dlv flags
for debug sessions started with debug test codelens.

Fixes golang#1723

Change-Id: I3ff423ae81e6b482e14d009232860e31838200cf
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/351249
Trust: Hyang-Ah Hana Kim <[email protected]>
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
Reviewed-by: Suzy Mueller <[email protected]>
  • Loading branch information
hyangah committed Sep 22, 2021
1 parent 6f98706 commit 022e403
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 51 deletions.
22 changes: 4 additions & 18 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,14 @@ Default: `"showBothCoveredAndUncoveredCode"`
Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.
| Properties | Description |
| --- | --- |
| `apiVersion` | Delve Api Version to use. Default value is 2. <br/> Allowed Options: `1`, `2` <br/> Default: `2` |
| `apiVersion` | Delve Api Version to use. Default value is 2. This applies only when using the 'legacy' debug adapter. <br/> Allowed Options: `1`, `2` <br/> Default: `2` |
| `debugAdapter` | Select which debug adapter to use by default. This is also used for choosing which debug adapter to use when no launch.json is present and with codelenses. <br/> Allowed Options: `legacy`, `dlv-dap` <br/> Default: `"dlv-dap"` |
| `dlvFlags` | Extra flags for `dlv`. See `dlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error. |
| `dlvLoadConfig` | LoadConfig describes to delve, how to load values from target's memory. Ignored by 'dlv-dap'. <br/> Default: ``` { <pre>"followPointers" : true,<br/>"maxArrayValues" : 64,<br/>"maxStringLen" : 64,<br/>"maxStructFields" : -1,<br/>"maxVariableRecurse" : 1,</pre>} ``` |
| `logOutput` | Comma separated list of components that should produce debug output. Maps to dlv's `--log-output` flag. Check `dlv log` for details. <br/> Allowed Options: `debugger`, `gdbwire`, `lldbout`, `debuglineerr`, `rpc`, `dap` <br/> Default: `"debugger"` |
| `showGlobalVariables` | Boolean value to indicate whether global package variables should be shown in the variables pane or not. <br/> Default: `false` |
| `showLog` | Show log output from the delve debugger. Maps to dlv's `--log` flag. <br/> Default: `false` |
| `substitutePath` | An array of mappings from a local path to the remote path that is used by the debuggee. The debug adapter will replace the local path with the remote path in all of the calls. Overriden by `remotePath` (in attach request). |

Default:
```
{
"apiVersion" : 2,
"debugAdapter" : "legacy",
"dlvLoadConfig" : {
"followPointers" : true,
"maxArrayValues" : 64,
"maxStringLen" : 64,
"maxStructFields" : -1,
"maxVariableRecurse" : 1,
},
"showGlobalVariables" : false,
"substitutePath" : [],
}
```
### `go.disableConcurrentTests`

If true, tests will not run concurrently. When a new test run is started, the previous will be cancelled.
Expand Down
42 changes: 28 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1794,14 +1794,32 @@
1,
2
],
"description": "Delve Api Version to use. Default value is 2.",
"description": "Delve Api Version to use. Default value is 2. This applies only when using the 'legacy' debug adapter.",
"default": 2
},
"showGlobalVariables": {
"type": "boolean",
"description": "Boolean value to indicate whether global package variables should be shown in the variables pane or not.",
"default": false
},
"showLog": {
"type": "boolean",
"description": "Show log output from the delve debugger. Maps to dlv's `--log` flag.",
"default": false
},
"logOutput": {
"type": "string",
"enum": [
"debugger",
"gdbwire",
"lldbout",
"debuglineerr",
"rpc",
"dap"
],
"description": "Comma separated list of components that should produce debug output. Maps to dlv's `--log-output` flag. Check `dlv log` for details.",
"default": "debugger"
},
"debugAdapter": {
"type": "string",
"enum": [
Expand All @@ -1811,6 +1829,14 @@
"description": "Select which debug adapter to use by default. This is also used for choosing which debug adapter to use when no launch.json is present and with codelenses.",
"default": "dlv-dap"
},
"dlvFlags": {
"type": "array",
"description": "Extra flags for `dlv`. See `dlv help` for the full list of supported. Flags such as `--log-output`, `--log`, `--log-dest`, `--api-version`, `--output`, `--backend` already have corresponding properties in the debug configuration, and flags such as `--listen` and `--headless` are used internally. If they are specified in `dlvFlags`, they may be ignored or cause an error.",
"items": {
"type": "string"
},
"default": []
},
"substitutePath": {
"type": "array",
"items": {
Expand All @@ -1832,19 +1858,7 @@
"default": []
}
},
"default": {
"dlvLoadConfig": {
"followPointers": true,
"maxVariableRecurse": 1,
"maxStringLen": 64,
"maxArrayValues": 64,
"maxStructFields": -1
},
"apiVersion": 2,
"showGlobalVariables": false,
"debugAdapter": "legacy",
"substitutePath": []
},
"default": {},
"description": "Delve settings that applies to all debugging sessions. Debug configuration in the launch.json file will override these values.",
"scope": "resource"
},
Expand Down
22 changes: 11 additions & 11 deletions src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
"'dlvLoadConfig' is deprecated with dlv-dap debug adapter.\n\nDlv-dap loads composite data on demand and uses increased string limits on source code hover, in Debug Console and via Copy Value. Please file an issue if these are not sufficient for your use case."
);
}
if (!debugConfiguration.hasOwnProperty('dlvLoadConfig') && dlvConfig.hasOwnProperty('dlvLoadConfig')) {
debugConfiguration['dlvLoadConfig'] = dlvConfig['dlvLoadConfig'];
}
if (
!debugConfiguration.hasOwnProperty('showGlobalVariables') &&
dlvConfig.hasOwnProperty('showGlobalVariables')
) {
debugConfiguration['showGlobalVariables'] = dlvConfig['showGlobalVariables'];
}
if (!debugConfiguration.hasOwnProperty('substitutePath') && dlvConfig.hasOwnProperty('substitutePath')) {
debugConfiguration['substitutePath'] = dlvConfig['substitutePath'];

// Reflect the defaults set through go.delveConfig setting.
const dlvProperties = ['showGlobalVariables', 'substitutePath', 'showLog', 'logOutput', 'dlvFlags'];
if (debugAdapter !== 'dlv-dap') {
dlvProperties.push('dlvLoadConfig');
}
dlvProperties.forEach((p) => {
if (!debugConfiguration.hasOwnProperty(p) && dlvConfig.hasOwnProperty(p)) {
debugConfiguration[p] = dlvConfig[p];
}
});

if (debugAdapter !== 'dlv-dap' && debugConfiguration.request === 'attach' && !debugConfiguration['cwd']) {
debugConfiguration['cwd'] = '${workspaceFolder}';
if (vscode.workspace.workspaceFolders?.length > 1) {
Expand Down
21 changes: 13 additions & 8 deletions test/integration/goDebugConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ suite('Debug Configuration Merge User Settings', () => {
apiVersion: 1,
showGlobalVariables: true,
debugAdapter: 'dlv-dap',
substitutePath: [{ from: 'hello', to: 'goodbye' }]
substitutePath: [{ from: 'hello', to: 'goodbye' }],
showLog: true,
logOutput: 'dap,debugger',
dlvFlags: ['--check-go-version=false']
}
});
sinon.stub(config, 'getGoConfig').returns(goConfig);
Expand All @@ -300,12 +303,11 @@ suite('Debug Configuration Merge User Settings', () => {
assert.strictEqual(result.substitutePath.length, 1);
assert.strictEqual(result.substitutePath[0].from, 'hello');
assert.strictEqual(result.substitutePath[0].to, 'goodbye');
assert.strictEqual(result.showLog, true);
assert.strictEqual(result.logOutput, 'dap,debugger');
assert.deepStrictEqual(result.dlvFlags, ['--check-go-version=false']);
const dlvLoadConfig = result.dlvLoadConfig;
assert.strictEqual(dlvLoadConfig.followPointers, false);
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 3);
assert.strictEqual(dlvLoadConfig.maxStringLen, 32);
assert.strictEqual(dlvLoadConfig.maxArrayValues, 32);
assert.strictEqual(dlvLoadConfig.maxStructFields, 5);
assert.strictEqual(dlvLoadConfig, undefined); // dlvLoadConfig does not apply in dlv-dap mode.
});

test('delve config in settings.json is overriden by launch.json', async () => {
Expand Down Expand Up @@ -337,8 +339,8 @@ suite('Debug Configuration Merge User Settings', () => {
request: 'launch',
mode: 'auto',
program: '${fileDirname}',
apiVersion: 2,
showGlobalVariables: false,
apiVersion: 2,
dlvLoadConfig: {
followPointers: true,
maxVariableRecurse: 6,
Expand All @@ -347,14 +349,17 @@ suite('Debug Configuration Merge User Settings', () => {
maxStructFields: -1
},
debugAdapter: 'legacy',
substitutePath: []
substitutePath: [],
logOutput: 'rpc'
};

const result = await debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
assert.strictEqual(result.apiVersion, 2);
assert.strictEqual(result.showGlobalVariables, false);
assert.strictEqual(result.debugAdapter, 'legacy');
assert.strictEqual(result.substitutePath.length, 0);
assert.strictEqual(result.showLog, undefined);
assert.strictEqual(result.logOutput, 'rpc');
const dlvLoadConfig = result.dlvLoadConfig;
assert.strictEqual(dlvLoadConfig.followPointers, true);
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 6);
Expand Down

0 comments on commit 022e403

Please sign in to comment.