xref: /openbsd-src/gnu/llvm/lldb/tools/lldb-vscode/README.md (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1061da546Spatrick
2061da546Spatrick# Table of Contents
3061da546Spatrick
4061da546Spatrick- [Introduction](#Introduction)
5061da546Spatrick- [Installation](#Installation-Visual-Studio-Code)
6061da546Spatrick- [Configurations](#configurations)
7061da546Spatrick	- [Launch Configuration Settings](#launch-configuration-settings)
8061da546Spatrick	- [Attach Configuration Settings](#attach-configuration-settings)
9061da546Spatrick	- [Example configurations](#example-configurations)
10061da546Spatrick		- [Launching](#launching)
11061da546Spatrick		- [Attach to process using process ID](#attach-using-pid)
12061da546Spatrick		- [Attach to process by name](#attach-by-name)
13061da546Spatrick		- [Loading a core file](#loading-a-core-file)
14061da546Spatrick
15061da546Spatrick# Introduction
16061da546Spatrick
17061da546SpatrickThe `lldb-vscode` tool creates a command line tool that implements the [Visual
18061da546SpatrickStudio Code Debug API](https://code.visualstudio.com/docs/extensionAPI/api-debugging).
19061da546SpatrickIt can be installed as an extension for the Visual Studio Code and Nuclide IDE.
20061da546SpatrickThe protocol is easy to run remotely and also can allow other tools and IDEs to
21061da546Spatrickget a full featured debugger with a well defined protocol.
22061da546Spatrick
23061da546Spatrick# Installation for Visual Studio Code
24061da546Spatrick
25061da546SpatrickInstalling the plug-in involves creating a directory in the `~/.vscode/extensions` folder and copying the package.json file that is in the same directory as this
26061da546Spatrickdocumentation into it, and copying to symlinking a lldb-vscode binary into
27061da546Spatrickthe `bin` directory inside the plug-in directory.
28061da546Spatrick
29061da546SpatrickIf you want to make a stand alone plug-in that you can send to others on unix systems:
30061da546Spatrick
31061da546Spatrick```
32061da546Spatrick$ mkdir -p ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
33061da546Spatrick$ cp package.json ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0
34061da546Spatrick$ cd ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
35061da546Spatrick$ cp /path/to/a/built/lldb-vscode .
36061da546Spatrick$ cp /path/to/a/built/liblldb.so .
37061da546Spatrick```
38061da546Spatrick
39*f6aab3d8SrobertIt is important to note that the directory `~/.vscode/extensions` works for users logged in locally to the machine. If you are remoting into the box using Visual Studio Code's Remote plugins (SSH, WSL, Docker) it will look for extensions on `~/.vscode-server/extensions` only and you will not see your just installed lldb-vscode plug-in. If you want this plugin to be visible to remoting users, you will need to either repeat the process above for the `~/.vscode-server` folder or create a symbolic link from it to `~/.vscode/extensions`:
40*f6aab3d8Srobert
41*f6aab3d8Srobert```
42*f6aab3d8Srobert$ cd ~/.vscode-server/extensions
43*f6aab3d8Srobert$ ln -s ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0  llvm-org.lldb-vscode-0.1.0
44*f6aab3d8Srobert```
45061da546Spatrick
46061da546SpatrickIf you want to make a stand alone plug-in that you can send to others on macOS systems:
47061da546Spatrick
48061da546Spatrick```
49061da546Spatrick$ mkdir -p ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
50061da546Spatrick$ cp package.json ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0
51061da546Spatrick$ cd ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
52061da546Spatrick$ cp /path/to/a/built/lldb-vscode .
53061da546Spatrick$ rsync -av /path/to/a/built/LLDB.framework LLDB.framework
54061da546Spatrick```
55061da546Spatrick
56061da546SpatrickYou might need to create additional directories for the `liblldb.so` or `LLDB.framework` inside or next to the `bin` folder depending on how the [rpath](https://en.wikipedia.org/wiki/Rpath) is set in your `lldb-vscode` binary. By default the `Debug` builds of LLDB usually includes
57061da546Spatrickthe current executable directory in the rpath, so these steps should work for most people.
58061da546Spatrick
59061da546SpatrickTo create a plug-in that symlinks into your `lldb-vscode` in your build directory:
60061da546Spatrick
61061da546Spatrick```
62061da546Spatrick$ mkdir -p ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
63061da546Spatrick$ cp package.json ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0
64061da546Spatrick$ cd ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
65061da546Spatrick$ ln -s /path/to/a/built/lldb-vscode
66061da546Spatrick```
67061da546Spatrick
68061da546SpatrickThis is handy if you want to debug and develope the `lldb-vscode` executable when adding features or fixing bugs.
69061da546Spatrick
70*f6aab3d8Srobert
71*f6aab3d8Srobert
72061da546Spatrick# Configurations
73061da546Spatrick
74061da546SpatrickLaunching to attaching require you to create a [launch configuration](https://code.visualstudio.com/Docs/editor/debugging#_launch-configurations). This file
75061da546Spatrickdefines arguments that get passed to `lldb-vscode` and the configuration settings
76061da546Spatrickcontrol how the launch or attach happens.
77061da546Spatrick
78061da546Spatrick## Launch Configuration Settings
79061da546Spatrick
80061da546SpatrickWhen you launch a program with Visual Studio Code you will need to create a [launch.json](https://code.visualstudio.com/Docs/editor/debugging#_launch-configurations)
81061da546Spatrickfile that defines how your program will be run. The JSON configuration file can contain the following `lldb-vscode` specific launch key/value pairs:
82061da546Spatrick
83061da546Spatrick|parameter          |type|req |         |
84061da546Spatrick|-------------------|----|:--:|---------|
85061da546Spatrick|**name**           |string|Y| A configuration name that will be displayed in the IDE.
86061da546Spatrick|**type**           |string|Y| Must be "lldb-vscode".
87061da546Spatrick|**request**        |string|Y| Must be "launch".
88061da546Spatrick|**program**        |string|Y| Path to the executable to launch.
89061da546Spatrick|**args**           |[string]|| An array of command line argument strings to be passed to the program being launched.
90061da546Spatrick|**cwd**            |string| | The program working directory.
91061da546Spatrick|**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.
92061da546Spatrick|**stopOnEntry**    |boolean| | Whether to stop program immediately after launching.
93061da546Spatrick|**initCommands**   |[string]| | LLDB commands executed upon debugger startup prior to creating the LLDB target. Commands and command output will be sent to the debugger console when they are executed.
94061da546Spatrick|**preRunCommands** |[string]| | LLDB commands executed just before launching after the LLDB target has been created. Commands and command output will be sent to the debugger console when they are executed.
95061da546Spatrick|**stopCommands**   |[string]| | LLDB commands executed just after each stop. Commands and command output will be sent to the debugger console when they are executed.
96061da546Spatrick|**exitCommands**   |[string]| | LLDB commands executed when the program exits. Commands and command output will be sent to the debugger console when they are executed.
97dda28197Spatrick|**terminateCommands** |[string]| | LLDB commands executed when the debugging session ends. Commands and command output will be sent to the debugger console when they are executed.
98061da546Spatrick|**sourceMap**      |[string[2]]| | Specify an array of path re-mappings. Each element in the array must be a two element array containing a source and destination pathname.
99061da546Spatrick|**debuggerRoot**   | string| |Specify a working directory to use when launching lldb-vscode. If the debug information in your executable contains relative paths, this option can be used so that `lldb-vscode` can find source files and object files that have relative paths.
100061da546Spatrick
101061da546Spatrick## Attaching Settings
102061da546Spatrick
103061da546SpatrickWhen attaching to a process using LLDB you can attach in a few ways
104061da546Spatrick
105061da546Spatrick1. Attach to an existing process using the process ID
106061da546Spatrick2. Attach to an existing process by name
107061da546Spatrick3. Attach by name by waiting for the next instance of a process to launch
108061da546Spatrick
109061da546SpatrickThe JSON configuration file can contain the following `lldb-vscode` specific launch key/value pairs:
110061da546Spatrick
111061da546Spatrick|parameter          |type    |req |         |
112061da546Spatrick|-------------------|--------|:--:|---------|
113061da546Spatrick|**name**           |string  |Y| A configuration name that will be displayed in the IDE.
114061da546Spatrick|**type**           |string  |Y| Must be "lldb-vscode".
115061da546Spatrick|**request**        |string  |Y| Must be "attach".
116061da546Spatrick|**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.
117061da546Spatrick|**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 **porgram**. Setting this value to `${command:pickMyProcess}` will allow interactive process selection in the IDE.
118061da546Spatrick|**stopOnEntry**    |boolean| | Whether to stop program immediately after launching.
119061da546Spatrick|**waitFor**        |boolean | | Wait for the process to launch.
120061da546Spatrick|**initCommands**   |[string]| | LLDB commands executed upon debugger startup prior to creating the LLDB target. Commands and command output will be sent to the debugger console when they are executed.
121061da546Spatrick|**preRunCommands** |[string]| | LLDB commands executed just before launching after the LLDB target has been created. Commands and command output will be sent to the debugger console when they are executed.
122061da546Spatrick|**stopCommands**   |[string]| | LLDB commands executed just after each stop. Commands and command output will be sent to the debugger console when they are executed.
123061da546Spatrick|**exitCommands**   |[string]| | LLDB commands executed when the program exits. Commands and command output will be sent to the debugger console when they are executed.
124dda28197Spatrick|**terminateCommands** |[string]| | LLDB commands executed when the debugging session ends. Commands and command output will be sent to the debugger console when they are executed.
125061da546Spatrick|**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.
126061da546Spatrick
127061da546Spatrick
128061da546Spatrick## Example configurations
129061da546Spatrick
130061da546Spatrick### Launching
131061da546Spatrick
132061da546SpatrickThis will launch `/tmp/a.out` with arguments `one`, `two`, and `three` and
133061da546Spatrickadds `FOO=1` and `bar` to the environment:
134061da546Spatrick
135061da546Spatrick```javascript
136061da546Spatrick{
137061da546Spatrick  "type": "lldb-vscode",
138061da546Spatrick  "request": "launch",
139061da546Spatrick  "name": "Debug",
140061da546Spatrick  "program": "/tmp/a.out",
141061da546Spatrick  "args": [ "one", "two", "three" ],
142061da546Spatrick  "env": [ "FOO=1", "BAR" ],
143061da546Spatrick}
144061da546Spatrick```
145061da546Spatrick
146061da546Spatrick### Attach using PID
147061da546Spatrick
148061da546SpatrickThis will attach to a process `a.out` whose process ID is 123:
149061da546Spatrick
150061da546Spatrick```javascript
151061da546Spatrick{
152061da546Spatrick  "type": "lldb-vscode",
153061da546Spatrick  "request": "attach",
154061da546Spatrick  "name": "Attach to PID",
155061da546Spatrick  "program": "/tmp/a.out",
156061da546Spatrick  "pid": 123
157061da546Spatrick}
158061da546Spatrick```
159061da546Spatrick
160061da546Spatrick### Attach by Name
161061da546Spatrick
162061da546SpatrickThis will attach to an existing process whose base
163061da546Spatrickname matches `a.out`. All we have to do is leave the `pid` value out of the
164061da546Spatrickabove configuration:
165061da546Spatrick
166061da546Spatrick```javascript
167061da546Spatrick{
168061da546Spatrick  "name": "Attach to Name",
169061da546Spatrick  "type": "lldb-vscode",
170061da546Spatrick  "request": "attach",
171061da546Spatrick  "program": "/tmp/a.out",
172061da546Spatrick}
173061da546Spatrick```
174061da546Spatrick
175061da546SpatrickIf you want to ignore any existing a.out processes and wait for the next instance
176061da546Spatrickto be launched you can add the "waitFor" key value pair:
177061da546Spatrick
178061da546Spatrick```javascript
179061da546Spatrick{
180061da546Spatrick  "name": "Attach to Name (wait)",
181061da546Spatrick  "type": "lldb-vscode",
182061da546Spatrick  "request": "attach",
183061da546Spatrick  "program": "/tmp/a.out",
184061da546Spatrick  "waitFor": true
185061da546Spatrick}
186061da546Spatrick```
187061da546Spatrick
188061da546SpatrickThis will work as long as the architecture, vendor and OS supports waiting
189061da546Spatrickfor processes. Currently MacOS is the only platform that supports this.
190061da546Spatrick
191061da546Spatrick
192061da546Spatrick### Loading a Core File
193061da546Spatrick
194dda28197SpatrickThis loads the coredump file `/cores/123.core` associated with the program
195dda28197Spatrick`/tmp/a.out`:
196061da546Spatrick
197061da546Spatrick```javascript
198061da546Spatrick{
199dda28197Spatrick  "name": "Load coredump",
200061da546Spatrick  "type": "lldb-vscode",
201061da546Spatrick  "request": "attach",
202dda28197Spatrick  "coreFile": "/cores/123.core",
203dda28197Spatrick  "program": "/tmp/a.out"
204061da546Spatrick}
205061da546Spatrick```
206