Skip to content

Commit 1c24db4

Browse files
authored
Merge pull request #765 from puremourning/data-breakpoints
Basic Data breakpoints
2 parents d5fa72a + c3bf6a7 commit 1c24db4

File tree

18 files changed

+662
-61
lines changed

18 files changed

+662
-61
lines changed

README.md

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ Example:
474474
```json
475475
{
476476
"adapters": {
477-
"lldb-vscode": {
477+
"lldb-dap": {
478478
"variables": {
479479
"LLVM": {
480480
"shell": "brew --prefix llvm"
@@ -485,7 +485,7 @@ Example:
485485
"pidSelect": "ask"
486486
},
487487
"command": [
488-
"${LLVM}/bin/lldb-vscode"
488+
"lldb-dap"
489489
],
490490
"env": {
491491
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY": "YES"
@@ -1057,6 +1057,28 @@ then answer `Y` to that (for example).
10571057
You can configure your choices in the `.vimspector.json`. See
10581058
[the configuration guide][vimspector-ref-exception] for details on that.
10591059

1060+
### Data breakpoints
1061+
1062+
Data breakpoints are not supported by all debug adapters. They are breakpoints
1063+
which trigger when some memory is read or written. They can be created:
1064+
1065+
- For a given variable in the variables window (`<F9>` on variable)
1066+
- For a given child variable in the watches or variables windows
1067+
(`<F9>` on child variable)
1068+
- For an arbitrary expression which evaluates to an address (`<F9>` in watch
1069+
window, not on any variable)
1070+
1071+
When specifying an expression, you can also specify a size.
1072+
1073+
In general, if you hit `<F9>` (or whatever mapping you have) in the Variables or
1074+
Watch window, you'll be adding a Data Breakpoint. If the context looks like a
1075+
variable, then Vimspector will ask the debug adapter to create a data breakpoint
1076+
on that variable expression. Otherwise, you'll be asked to enter an expression,
1077+
or an address and a size, depending on the capabilities of the debugger.
1078+
1079+
NOTE: Not all debug adapters support data breakpoints, and the ability to
1080+
actually create them often depends on the hardware of the target.
1081+
10601082
### API Summary
10611083

10621084
***NOTE:*** Previously, ToggleBreakpoint would cycle between 3 states:
@@ -1082,6 +1104,7 @@ deletes a breakpoint. If you wish to 'disable' breakpoints, use the
10821104
* `call vimspector#ListBreakpoints()` - toggle breakpoints window
10831105
* `call vimspector#BreakpointsAsQuickFix()` - return the current set of
10841106
breakpoints in vim quickfix format
1107+
* `call vimspector#AddDataBreakpoint()` - add a data breakpoint
10851108

10861109
Examples:
10871110

@@ -1209,6 +1232,7 @@ autocmd SessionLoadPost * silent! VimspectorLoadSession
12091232
* View the type of the variable via mouse hover.
12101233
* When changing the stack frame the locals window updates.
12111234
* While paused, hover to see values.
1235+
* Create a data breakpoint with `<F9>`.
12121236

12131237
![locals window](https://puremourning.github.io/vimspector-web/img/vimspector-locals-window.png)
12141238

@@ -1259,6 +1283,7 @@ to add a new watch expression.
12591283
* Set the value of the variable with `<C-CR>` (control + `<CR>`) or
12601284
`<leader><CR>` (if `modifyOtherKeys` doesn't work for you)
12611285
* Delete with `<DEL>`.
1286+
* Create a data breakpoint with `<F9>`.
12621287

12631288
![watch window](https://puremourning.github.io/vimspector-web/img/vimspector-watch-window.png)
12641289

@@ -1571,14 +1596,16 @@ Currently tested with the following debug adapters.
15711596

15721597
## C, C++, Rust, etc.
15731598

1599+
* Recommended: [CodeLLDB](#rust)
15741600
* [vscode-cpptools](https://github.com/Microsoft/vscode-cpptools)
1575-
* On macOS, I *strongly* recommend using [CodeLLDB](#rust) instead for C and C++
1601+
* [lldb-dap](https://marketplace.visualstudio.com/items?itemName=llvm-vs-code-extensions.lldb-dap)
1602+
* I *strongly* recommend using [CodeLLDB](#rust) over cpptools for almost all
15761603
projects. It's really excellent, has fewer dependencies and doesn't open console
15771604
apps in another Terminal window.
15781605

15791606

1580-
Example `.vimspector.json` (works with both `vscode-cpptools` and `lldb-vscode`.
1581-
For `lldb-vscode` replace the name of the adapter with `lldb-vscode`:
1607+
Example `.vimspector.json` (works with both `vscode-cpptools` and `lldb-dap`.
1608+
For `lldb-dap` replace the name of the adapter with `lldb-dap`:
15821609

15831610
* vscode-cpptools Linux/MacOS:
15841611

@@ -1634,6 +1661,31 @@ licensing.
16341661
}
16351662
```
16361663

1664+
* `lldb-dap`
1665+
1666+
```json
1667+
1668+
"lldb-dap": {
1669+
"adapter": {
1670+
"command": [
1671+
// TODO: Replace this with the path to your installation of lldb
1672+
"/opt/homebrew/Cellar/llvm/bin/lldb-dap"
1673+
],
1674+
"name": "lldb"
1675+
},
1676+
"configuration": {
1677+
"request": "launch",
1678+
"program": "${workspaceRoot}/${fileBasenameNoExtension}",
1679+
"args": [
1680+
"*${args}"
1681+
],
1682+
"stopOnEntry": true,
1683+
"runInTerminal": true,
1684+
"cwd": "${workspaceRoot}"
1685+
}
1686+
}
1687+
```
1688+
16371689
### Data visualization / pretty printing
16381690

16391691
Depending on the backend you need to enable pretty printing of complex types
@@ -1681,22 +1733,22 @@ an example of getting Vimspector to remotely launch and attach.
16811733

16821734
* CodeLLDB (MacOS)
16831735

1684-
CodeLLDB is superior to vscode-cpptools in a number of ways on macOS at least.
1736+
CodeLLDB is superior to vscode-cpptools in a number of ways.
16851737

16861738
See [Rust](#rust).
16871739

1688-
* lldb-vscode (MacOS)
1740+
* lldb-dap (MacOS)
16891741

1690-
An alternative is to to use `lldb-vscode`, which comes with llvm. Here's how:
1742+
An alternative is to to use `lldb-dap`, which comes with llvm. Here's how:
16911743

16921744
* Install llvm (e.g. with HomeBrew: `brew install llvm`)
16931745
* Create a file named
1694-
`/path/to/vimspector/gadgets/macos/.gadgets.d/lldb-vscode.json`:
1746+
`/path/to/vimspector/gadgets/macos/.gadgets.d/lldb-dap.json`:
16951747

16961748
```json
16971749
{
16981750
"adapters": {
1699-
"lldb-vscode": {
1751+
"lldb-dap": {
17001752
"variables": {
17011753
"LLVM": {
17021754
"shell": "brew --prefix llvm"
@@ -1707,7 +1759,7 @@ An alternative is to to use `lldb-vscode`, which comes with llvm. Here's how:
17071759
"pidSelect": "ask"
17081760
},
17091761
"command": [
1710-
"${LLVM}/bin/lldb-vscode"
1762+
"${LLVM}/bin/lldb-dap"
17111763
],
17121764
"env": {
17131765
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY": "YES"
@@ -1721,7 +1773,7 @@ An alternative is to to use `lldb-vscode`, which comes with llvm. Here's how:
17211773
## Rust
17221774

17231775
Rust is supported with any gdb/lldb-based debugger. So it works fine with
1724-
`vscode-cpptools` and `lldb-vscode` above. However, support for rust is best in
1776+
`vscode-cpptools` and `lldb-dap` above. However, support for rust is best in
17251777
[`CodeLLDB`](https://github.com/vadimcn/vscode-lldb#features).
17261778

17271779
* `./install_gadget.py --enable-rust` or `:VimspectorInstall CodeLLDB`
@@ -1735,7 +1787,8 @@ Rust is supported with any gdb/lldb-based debugger. So it works fine with
17351787
"filetypes": [ "rust" ],
17361788
"configuration": {
17371789
"request": "launch",
1738-
"program": "${workspaceRoot}/target/debug/vimspector_test"
1790+
"program": "${workspaceRoot}/target/debug/vimspector_test",
1791+
"sourceLanguages": [ "rust" ]
17391792
}
17401793
},
17411794
"attach": {
@@ -1744,7 +1797,8 @@ Rust is supported with any gdb/lldb-based debugger. So it works fine with
17441797
"configuration": {
17451798
"request": "attach",
17461799
"program": "${workspaceRoot}/${fileBasenameNoExtension}",
1747-
"PID": "${PID}"
1800+
"PID": "${PID}",
1801+
"sourceLanguages": [ "rust" ]
17481802
}
17491803
}
17501804
}

autoload/vimspector.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ function! vimspector#ShowDisassembly( ... ) abort
439439
py3 _vimspector_session.ShowDisassembly()
440440
endfunction
441441

442+
function! vimspector#AddDataBreakpoint( ... ) abort
443+
if !s:Enabled()
444+
return
445+
endif
446+
" TODO: how to set options?
447+
py3 _vimspector_session.AddDataBreakpoint( {} )
448+
endfunction
449+
442450
function! vimspector#DeleteWatch() abort
443451
if !s:Enabled()
444452
return

0 commit comments

Comments
 (0)