Skip to content

Commit a5d7037

Browse files
improve debugging documentation (#1596)
1 parent b390127 commit a5d7037

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@
15101510
},
15111511
"launchCommands": {
15121512
"type": "array",
1513-
"description": "Custom commands that are executed instead of launching a process. A target will be created with the launch arguments prior to executing these commands. The commands may optionally create a new target and must perform a launch. A valid process must exist after these commands complete or the \"launch\" will fail. Launch the process with \"process launch -s\" to make the process to at the entry point since lldb-vscode will auto resume if necessary.",
1513+
"description": "Custom commands that are executed instead of launching a process. A target will be created with the launch arguments prior to executing these commands. The commands may optionally create a new target and must perform a launch. A valid process must exist after these commands complete or the \"launch\" will fail. Launch the process with \"process launch -s\" to make the process to at the entry point since lldb-dap will auto resume if necessary.",
15141514
"default": []
15151515
},
15161516
"stopCommands": {
@@ -1520,7 +1520,12 @@
15201520
},
15211521
"exitCommands": {
15221522
"type": "array",
1523-
"description": "Commands executed at the end of debugging session.",
1523+
"description": "Commands executed when the program exits.",
1524+
"default": []
1525+
},
1526+
"terminateCommands": {
1527+
"type": "array",
1528+
"description": "Commands executed when the debugging session ends.",
15241529
"default": []
15251530
},
15261531
"runInTerminal": {

src/debugger/debugAdapterFactory.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ export class LLDBDebugConfigurationProvider implements vscode.DebugConfiguration
151151
if (!(await this.promptForCodeLldbSettings(toolchain))) {
152152
return undefined;
153153
}
154+
// Rename lldb-dap's "terminateCommands" to "preTerminateCommands" for CodeLLDB
155+
if ("terminateCommands" in launchConfig) {
156+
launchConfig["preTerminateCommands"] = launchConfig["terminateCommands"];
157+
delete launchConfig["terminateCommands"];
158+
}
154159
} else if (launchConfig.type === LaunchConfigType.LLDB_DAP) {
155160
if (launchConfig.env) {
156161
launchConfig.env = this.convertEnvironmentVariables(launchConfig.env);

userdocs/userdocs.docc/Articles/Features/debugging.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,63 @@ When you open a Swift package (a directory containing a `Package.swift` file), t
99
> Debugging works best when using a version of the Swift toolchain 6.0 or higher.
1010
1111
Use the **Run > Start Debugging** menu item to run an executable and start debugging. If you have multiple launch configurations you can choose which launch configuration to use in the debugger view.
12+
13+
## Launch Configurations
14+
15+
The Swift extension will automatically generate launch configurations for all of your executable products. You can customize these configurations via the `.vscode/launch.json` file in your workspace to add environment variables, arguments, etc.
16+
17+
Each generated launch configuration will have the `"type"` set to `"swift"`. The properties for the swift launch configuration match the ones [provided by `lldb-dap`](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap). You can use code completion in VS Code to help with adding properties to your launch configuration.
18+
19+
### Launching an Executable
20+
21+
The most basic launch configuration uses the `"launch"` request and provides a program that will be debugged. For example:
22+
23+
```javascript
24+
{
25+
"label": "Debug my-executable", // Human readable name for the configuration
26+
"type": "swift", // All Swift launch configurations use the same type
27+
"request": "launch", // Launch an executable
28+
"program": "${workspaceFolder}/.build/debug/my-executable"
29+
}
30+
```
31+
32+
There are many more options that you can specify which will alter the behavior of the debugger:
33+
34+
| Parameter | Type | Description |
35+
|-------------------------------|-------------|---------------------|
36+
| program | string | Path to the executable to launch.
37+
| args | [string] | An array of command line argument strings to be passed to the program being launched.
38+
| cwd | string | The program working directory.
39+
| env | dictionary | Environment variables to set when launching the program. The format of each environment variable string is "VAR=VALUE" for environment variables with values or just "VAR" for environment variables with no values.
40+
| stopOnEntry | boolean | Whether to stop program immediately after launching.
41+
| runInTerminal | boolean | Launch the program inside an integrated terminal in the IDE. Useful for debugging interactive command line programs.
42+
| initCommands | [string] | Initialization commands executed upon debugger startup.
43+
| preRunCommands | [string] | Commands executed just before the program is launched.
44+
| postRunCommands | [string] | Commands executed just as soon as the program is successfully launched when it's in a stopped state prior to any automatic continuation.
45+
| launchCommands | [string] | Custom commands that are executed instead of launching a process. A target will be created with the launch arguments prior to executing these commands. The commands may optionally create a new target and must perform a launch. A valid process must exist after these commands complete or the \"launch\" will fail. Launch the process with \"process launch -s\" to make the process to at the entry point since lldb-dap will auto resume if necessary.
46+
| stopCommands | [string] | Commands executed each time the program stops.
47+
| exitCommands | [string] | Commands executed when the program exits.
48+
| terminateCommands | [string] | Commands executed when the debugging session ends.
49+
50+
### Attaching to a Process
51+
52+
You can attach to an existing process by using the `"attach"` request and providing one or both of a `"program"` or `"pid"` to attach to:
53+
54+
```javascript
55+
{
56+
"label": "Debug my-executable", // Human readable name for the configuration
57+
"type": "swift", // All Swift launch configurations use the same type
58+
"request": "attach", // Attach to a process
59+
"program": "${workspaceFolder}/.build/debug/my-executable",
60+
"pid": "${command:pickProcess}"
61+
}
62+
```
63+
64+
The options for attach requests are mostly the same as the launch request with the addition of the following:
65+
66+
| Parameter | Type | Description |
67+
|--------------------|-------------|---------------------|
68+
| program | string | Path to the executable to attach to. This value is optional but can help to resolve breakpoints prior the attaching to the program.
69+
| pid | number | The process id of the process you wish to attach to. If `pid` is omitted, the debugger will attempt to attach to the program by finding a process whose file name matches the file name from `program`. Setting this value to `${command:pickMyProcess}` will allow interactive process selection in the IDE.
70+
| waitFor | boolean | Wait for the process to launch.
71+
| attachCommands | [string] | LLDB commands that will be executed after `preRunCommands` which take place of the code that normally does the attach. The commands can create a new target and attach or launch it however desired. This allows custom launch and attach configurations. Core files can use `target create --core /path/to/core` to attach to core files.

0 commit comments

Comments
 (0)