README.md
1
2# Table of Contents
3
4- [Introduction](#Introduction)
5- [Installation](#Installation-Visual-Studio-Code)
6- [Configurations](#configurations)
7 - [Launch Configuration Settings](#launch-configuration-settings)
8 - [Attach Configuration Settings](#attach-configuration-settings)
9 - [Example configurations](#example-configurations)
10 - [Launching](#launching)
11 - [Attach to process using process ID](#attach-using-pid)
12 - [Attach to process by name](#attach-by-name)
13 - [Loading a core file](#loading-a-core-file)
14
15# Introduction
16
17The `lldb-vscode` tool creates a command line tool that implements the [Visual
18Studio Code Debug API](https://code.visualstudio.com/docs/extensionAPI/api-debugging).
19It can be installed as an extension for the Visual Studio Code and Nuclide IDE.
20The protocol is easy to run remotely and also can allow other tools and IDEs to
21get a full featured debugger with a well defined protocol.
22
23# Installation for Visual Studio Code
24
25Installing 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
26documentation into it, and copying to symlinking a lldb-vscode binary into
27the `bin` directory inside the plug-in directory.
28
29If you want to make a stand alone plug-in that you can send to others on unix systems:
30
31```
32$ mkdir -p ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
33$ cp package.json ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0
34$ cd ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
35$ cp /path/to/a/built/lldb-vscode .
36$ cp /path/to/a/built/liblldb.so .
37```
38
39It 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
41```
42$ cd ~/.vscode-server/extensions
43$ ln -s ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0 llvm-org.lldb-vscode-0.1.0
44```
45
46If you want to make a stand alone plug-in that you can send to others on macOS systems:
47
48```
49$ mkdir -p ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
50$ cp package.json ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0
51$ cd ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
52$ cp /path/to/a/built/lldb-vscode .
53$ rsync -av /path/to/a/built/LLDB.framework LLDB.framework
54```
55
56You 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
57the current executable directory in the rpath, so these steps should work for most people.
58
59To create a plug-in that symlinks into your `lldb-vscode` in your build directory:
60
61```
62$ mkdir -p ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
63$ cp package.json ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0
64$ cd ~/.vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin
65$ ln -s /path/to/a/built/lldb-vscode
66```
67
68This is handy if you want to debug and develope the `lldb-vscode` executable when adding features or fixing bugs.
69
70
71
72# Configurations
73
74Launching to attaching require you to create a [launch configuration](https://code.visualstudio.com/Docs/editor/debugging#_launch-configurations). This file
75defines arguments that get passed to `lldb-vscode` and the configuration settings
76control how the launch or attach happens.
77
78## Launch Configuration Settings
79
80When 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)
81file that defines how your program will be run. The JSON configuration file can contain the following `lldb-vscode` specific launch key/value pairs:
82
83|parameter |type|req | |
84|-------------------|----|:--:|---------|
85|**name** |string|Y| A configuration name that will be displayed in the IDE.
86|**type** |string|Y| Must be "lldb-vscode".
87|**request** |string|Y| Must be "launch".
88|**program** |string|Y| Path to the executable to launch.
89|**args** |[string]|| An array of command line argument strings to be passed to the program being launched.
90|**cwd** |string| | The program working directory.
91|**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.
92|**stopOnEntry** |boolean| | Whether to stop program immediately after launching.
93|**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.
94|**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.
95|**stopCommands** |[string]| | LLDB commands executed just after each stop. Commands and command output will be sent to the debugger console when they are executed.
96|**exitCommands** |[string]| | LLDB commands executed when the program exits. Commands and command output will be sent to the debugger console when they are executed.
97|**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.
98|**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.
99|**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.
100
101## Attaching Settings
102
103When attaching to a process using LLDB you can attach in a few ways
104
1051. Attach to an existing process using the process ID
1062. Attach to an existing process by name
1073. Attach by name by waiting for the next instance of a process to launch
108
109The JSON configuration file can contain the following `lldb-vscode` specific launch key/value pairs:
110
111|parameter |type |req | |
112|-------------------|--------|:--:|---------|
113|**name** |string |Y| A configuration name that will be displayed in the IDE.
114|**type** |string |Y| Must be "lldb-vscode".
115|**request** |string |Y| Must be "attach".
116|**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.
117|**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.
118|**stopOnEntry** |boolean| | Whether to stop program immediately after launching.
119|**waitFor** |boolean | | Wait for the process to launch.
120|**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.
121|**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.
122|**stopCommands** |[string]| | LLDB commands executed just after each stop. Commands and command output will be sent to the debugger console when they are executed.
123|**exitCommands** |[string]| | LLDB commands executed when the program exits. Commands and command output will be sent to the debugger console when they are executed.
124|**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.
125|**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.
126
127
128## Example configurations
129
130### Launching
131
132This will launch `/tmp/a.out` with arguments `one`, `two`, and `three` and
133adds `FOO=1` and `bar` to the environment:
134
135```javascript
136{
137 "type": "lldb-vscode",
138 "request": "launch",
139 "name": "Debug",
140 "program": "/tmp/a.out",
141 "args": [ "one", "two", "three" ],
142 "env": [ "FOO=1", "BAR" ],
143}
144```
145
146### Attach using PID
147
148This will attach to a process `a.out` whose process ID is 123:
149
150```javascript
151{
152 "type": "lldb-vscode",
153 "request": "attach",
154 "name": "Attach to PID",
155 "program": "/tmp/a.out",
156 "pid": 123
157}
158```
159
160### Attach by Name
161
162This will attach to an existing process whose base
163name matches `a.out`. All we have to do is leave the `pid` value out of the
164above configuration:
165
166```javascript
167{
168 "name": "Attach to Name",
169 "type": "lldb-vscode",
170 "request": "attach",
171 "program": "/tmp/a.out",
172}
173```
174
175If you want to ignore any existing a.out processes and wait for the next instance
176to be launched you can add the "waitFor" key value pair:
177
178```javascript
179{
180 "name": "Attach to Name (wait)",
181 "type": "lldb-vscode",
182 "request": "attach",
183 "program": "/tmp/a.out",
184 "waitFor": true
185}
186```
187
188This will work as long as the architecture, vendor and OS supports waiting
189for processes. Currently MacOS is the only platform that supports this.
190
191
192### Loading a Core File
193
194This loads the coredump file `/cores/123.core` associated with the program
195`/tmp/a.out`:
196
197```javascript
198{
199 "name": "Load coredump",
200 "type": "lldb-vscode",
201 "request": "attach",
202 "coreFile": "/cores/123.core",
203 "program": "/tmp/a.out"
204}
205```
206