Skip to content

Commit

Permalink
Add script mode and ability to connect to externally launched CMake p…
Browse files Browse the repository at this point in the history
…rocess. (#3277)

* storing initial thoughts

* rough version of trying to work on new options for debugger configurations

* made progress enabling script debugging from launch.json

* add some output messaging regarding the debugger and script

* add TODO's in case I don't get to it today

* log statements, ensure package.json allows the right args in right situation, set up env for script debugging

* push worst case copying the description and settings of the debugger options

* I think I've covered all launch config cases

* better package.json schema, though still not perfect, matches other debug types, and stub validation in code

* localize error messages

* add 'The'

* switch to double quotes

* add docs page for debugging

* slight modifications

* didn't handle case where scriptEnv was undefined

* add configurationSnippets

* add stub for debugconfigurationprovider

* add ability to 'run and debug' without launch.json on *.cmake files

* modify when we sanity check

* make adjustments based on feedback and add automatic configuration

* ensure that configure with debugger works with the right format

* update changelog
  • Loading branch information
gcampbell-msft authored Sep 20, 2023
1 parent b4bd314 commit 661e9ed
Show file tree
Hide file tree
Showing 11 changed files with 470 additions and 36 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Features:
Improvements:
- Updated debugging documentation to add the LLDB configuration needed for macOS. [PR #3332](https://github.com/microsoft/vscode-cmake-tools/pull/3332) [@slhck](https://github.com/slhck)
- In multi-root workspace, the Project Outline View now shows all configured projects. [PR #3270](https://github.com/microsoft/vscode-cmake-tools/pull/3270) [@vlavati](https://github.com/vlavati)
- Added script mode and ability to connect to externally launched CMake processes. [PR #3277](https://github.com/microsoft/vscode-cmake-tools/pull/3277)

## 1.15
Features:
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CMake Tools is an extension designed to make it easy to work with CMake-based pr
* [Quick debugging](debug-launch.md#quick-debugging)
* [Debug using a launch.json file](debug-launch.md#debug-using-a-launchjson-file)
* [Run without debugging](debug-launch.md#run-without-debugging)
* [Debugging CMake](debug.md)

[Configure CMake Tools settings](cmake-settings.md)
* [CMake Tools settings](cmake-settings.md#cmake-settings)
Expand Down
72 changes: 72 additions & 0 deletions docs/debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# CMake Debugging

Starting with CMake 3.27, debugging CMake is supported in CMake Tools.

The following documentation will help you understand the various ways you can debug CMake scripts and cache generation.

## Debugging from CMake Tools UI entry points

The most common reason to debug CMake scripts and cache generation is to debug CMake cache generation. There are many ways that you can accomplish this:

* Commands
* CMake: Configure with CMake Debugger
* CMake: Delete Cache and Reconfigure with CMake Debugger
* Folder Explorer
* Right click on CMakeLists.txt -> Configure All Projects with CMake Debugger.
* Project Outline
* Right click on CMakeLists.txt -> Configure All Projects with CMake Debugger.
* Expand the "..." in the project outline. There is an entry to use the Debugger.

## Debugging from launch.json

CMake Tools provides a new debug type `cmake`.

The `cmake` debug type supports three different types of `cmakeDebugType`: `configure`, `external`, `script`. They each come with their own settings that can be used to modify and control the debug session.

### Example launch.json

```json
{
"version": "0.2.0",
"configurations": [
{
"type": "cmake",
"request": "launch",
"name": "CMake script debugging",
"cmakeDebugType": "script",
"scriptPath": "${workspaceFolder}/<script>.cmake"
},
{
"type": "cmake",
"request": "launch",
"name": "Debug externally launched CMake process",
"cmakeDebugType": "external",
"pipeName": "<insert-pipe-name>"
}
]
}
```

Listed below are the settings that are available for each configuration based on `cmakeDebugType`:

* `configure`
* required: none
* optional
* `pipeName` - Name of the pipe (on Windows) or domain socket (on Unix) to use for debugger communication.
* `clean` - Clean prior to configuring.
* `configureAll` - Configure for all projects.
* `dapLog` - Where the debug adapter protocol (DAP) communication should be logged. If omitted, DAP communication is not logged.
* `external`
* required
* `pipeName` - Name of the pipe (on Windows) or domain socket (on Unix) to use for debugger communication.
* optional
* `script`
* required
* `scriptPath` - The path to the CMake script to debug.
* optional
* `scriptArgs` - Arguments for the CMake script to debug.
* `scriptEnv` - Environment for the CMake script to use.
* `pipeName` - Name of the pipe (on Windows) or domain socket (on Unix) to use for debugger communication.
* `dapLog` - Where the debug adapter protocol (DAP) communication should be logged. If omitted, DAP communication is not logged.

The `cmake` debug type only supports the `request` type: `launch`.
186 changes: 178 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"vscode": "^1.63.0"
},
"categories": [
"Other"
"Other",
"Debuggers"
],
"galleryBanner": {
"color": "#13578c",
Expand All @@ -49,6 +50,9 @@
"onCommand:cmake.executableTargets",
"onCommand:cmake.buildKit",
"onCommand:cmake.tasksBuildCommand",
"onDebugResolve:cmake",
"onDebugInitialConfigurations",
"onDebugDynamicConfigurations:cmake",
"workspaceContains:CMakeLists.txt",
"workspaceContains:*/CMakeLists.txt",
"workspaceContains:*/*/CMakeLists.txt",
Expand Down Expand Up @@ -692,7 +696,7 @@
},
"options": {
"type": "object",
"description": "%cmake-tools.taskDefinitions.properties.options.description",
"description": "%cmake-tools.taskDefinitions.properties.options.description%",
"properties": {
"cwd": {
"type": "string",
Expand Down Expand Up @@ -720,12 +724,52 @@
{
"type": "cmake",
"label": "%cmake-tools.debugger.label%",
"languages": [
"cmake"
],
"configurationAttributes": {
"launch": {
"properties": {
"scriptPath": {
"type": "string",
"descripttion": "%cmake-tools.debugger.scriptPath.description%",
"default": "script.cmake"
},
"scriptArgs": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "%cmake-tools.debugger.scriptArgs.description%"
},
"scriptEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "%cmake-tools.debugger.name%"
},
"value": {
"type": "string",
"description": "%cmake-tools.debugger.value%"
}
}
},
"default": [],
"description": "%cmake-tools.debugger.scriptEnv.description%"
},
"dapLog": {
"type": "string",
"description": "%cmake-tools.debugger.dapLog.description%",
"default": ""
},
"pipeName": {
"type": "string",
"description": "%cmake-tools.debugger.pipeName.description%"
"description": "%cmake-tools.debugger.pipeName.description%",
"default": ""
},
"clean": {
"type": "boolean",
Expand All @@ -737,14 +781,140 @@
"description": "%cmake-tools.debugger.configureAll.description%",
"default": false
},
"dapLog": {
"cmakeDebugType": {
"type": "string",
"description": "%cmake-tools.debugger.dapLog.description%",
"default": ""
}
"enum": ["configure", "external", "script"],
"description": "%cmake-tools.debugger.debugType.description%"
}
},
"required": [
"cmakeDebugType"
],
"oneOf": [
{
"properties": {
"cmakeDebugType": {
"enum": [
"script"
]
},
"scriptPath": {
"type": "string",
"description": "%cmake-tools.debugger.scriptPath.description%",
"default": ""
},
"scriptArgs": {
"type": "array",
"items": {
"type": "string"
},
"default": [],
"description": "%cmake-tools.debugger.scriptArgs.description%"
},
"scriptEnv": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "%cmake-tools.debugger.name%"
},
"value": {
"type": "string",
"description": "%cmake-tools.debugger.value%"
}
}
},
"default": [],
"description": "%cmake-tools.debugger.scriptEnv.description%"
},
"dapLog": {
"type": "string",
"description": "%cmake-tools.debugger.dapLog.description%",
"default": ""
}
},
"required": [
"scriptPath"
]
},
{
"properties": {
"cmakeDebugType": {
"enum": [
"configure"
]
},
"clean": {
"type": "boolean",
"description": "%cmake-tools.debugger.clean.description%",
"default": false
},
"configureAll": {
"type": "boolean",
"description": "%cmake-tools.debugger.configureAll.description%",
"default": false
},
"dapLog": {
"type": "string",
"description": "%cmake-tools.debugger.dapLog.description%",
"default": ""
}
}
},
{
"properties": {
"cmakeDebugType": {
"enum": [
"external"
]
}
},
"required": [
"pipeName"
]
}
]
}
},
"initialConfigurations": [],
"configurationSnippets": [
{
"label": "%cmake-tools.debugger.configure.snippet.label%",
"description": "%cmake-tools.debugger.configure.snippet.description%",
"body": {
"type": "cmake",
"request": "launch",
"name": "%cmake-tools.debugger.configure.snippet.body.name%",
"cmakeDebugType": "configure",
"clean": false,
"configureAll": false
}
},
{
"label": "%cmake-tools.debugger.script.snippet.label%",
"description": "%cmake-tools.debugger.script.snippet.description%",
"body": {
"type": "cmake",
"request": "launch",
"name": "%cmake-tools.debugger.script.snippet.body.name%",
"cmakeDebugType": "script",
"scriptPath": "^\"\\${workspaceFolder}/<...>.cmake\""
}
},
{
"label": "%cmake-tools.debugger.external.snippet.label%",
"description": "%cmake-tools.debugger.external.snippet.description%",
"body": {
"type": "cmake",
"request": "launch",
"name": "%cmake-tools.debugger.external.snippet.body.name%",
"cmakeDebugType": "external",
"pipeName": "<...>"
}
}
}
]
}
],
"menus": {
Expand Down
15 changes: 15 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@
"cmake-tools.debugger.clean.description": "Clean prior to configuring.",
"cmake-tools.debugger.configureAll.description": "Configure for all projects.",
"cmake-tools.debugger.dapLog.description": "Where the debugger DAP log should be logged.",
"cmake-tools.debugger.scriptPath.description": "The path to the script to debug.",
"cmake-tools.debugger.scriptArgs.description": "Arguments for the script to debug.",
"cmake-tools.debugger.scriptEnv.description": "Environment for the script to use.",
"cmake-tools.debugger.name": "Name",
"cmake-tools.debugger.value": "Value",
"cmake-tools.debugger.debugType.description": "The type of the CMake debug session. Available options are: \"configure\", \"external\", \"script\".",
"cmake-tools.debugger.configure.snippet.label": "CMake: Configure",
"cmake-tools.debugger.configure.snippet.description": "Debug a CMake project configuration",
"cmake-tools.debugger.configure.snippet.body.name": "CMake: Configure project",
"cmake-tools.debugger.script.snippet.label": "CMake: Script",
"cmake-tools.debugger.script.snippet.description": "Debug a CMake script",
"cmake-tools.debugger.script.snippet.body.name": "CMake: Script debugging",
"cmake-tools.debugger.external.snippet.label": "CMake: External",
"cmake-tools.debugger.external.snippet.description": "Connect to an externally launched CMake invocation",
"cmake-tools.debugger.external.snippet.body.name": "CMake: Externally launched",
"cmake-tools.taskDefinitions.properties.label.description": "The name of the task",
"cmake-tools.taskDefinitions.properties.command.description": "CMake command",
"cmake-tools.taskDefinitions.properties.targets.description": "CMake build targets",
Expand Down
6 changes: 4 additions & 2 deletions src/cmakeProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { PresetsController } from './presetsController';
import paths from './paths';
import { ProjectController } from './projectController';
import { MessageItem } from 'vscode';
import { DebugTrackerFactory, DebuggerInformation } from './debug/debuggerConfigureDriver';
import { DebugTrackerFactory, DebuggerInformation, getDebuggerPipeName } from './debug/debuggerConfigureDriver';

nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
Expand Down Expand Up @@ -1392,7 +1392,9 @@ export class CMakeProject {
{title: localize('no.configureWithDebugger.button', 'Cancel')})
.then(async chosen => {
if (chosen && chosen.title === yesButtonTitle) {
await this.configureInternal(trigger, extraArgs, ConfigureType.NormalWithDebugger);
await this.configureInternal(trigger, extraArgs, ConfigureType.NormalWithDebugger, {
pipeName: getDebuggerPipeName()
});
}
});
}
Expand Down
Loading

0 comments on commit 661e9ed

Please sign in to comment.