vimspector安裝
vim配置文件加入一下內容
Plug 'puremourning/vimspector'
let g:vimspector_enable_mappings = 'HUMAN'
:PlugInstall
安裝插件即可。
上面的HUMAN是插件配置的一套快捷命令。具體如下
Key | Function | API |
---|---|---|
F5 |
When debugging, continue. Otherwise start debugging. | vimspector#Continue() |
F3 |
Stop debugging. | vimspector#Stop() |
F4 |
Restart debugging with the same configuration. | vimspector#Restart() |
F6 |
Pause debugee. | vimspector#Pause() |
F9 |
Toggle line breakpoint on the current line. | vimspector#ToggleBreakpoint() |
<leader>F9 |
Toggle conditional line breakpoint on the current line. | vimspector#ToggleBreakpoint( { trigger expr, hit count expr } ) |
F8 |
Add a function breakpoint for the expression under cursor | vimspector#AddFunctionBreakpoint('<cexpr>') |
F10 |
Step Over | vimspector#StepOver() |
F11 |
Step Into | vimspector#StepInto() |
F12 |
Step out of current function scope | vimspector#StepOut() |
vimspector配置
Language | Status | Switch | Adapter | Dependencies |
---|---|---|---|---|
C, C++, etc. | Tested | --all or --enable-c |
vscode-cpptools | mono-core |
Python | Tested | --all or --enable-python |
debugpy | Python 2.7 or Python 3 |
Go | Tested | --enable-go |
vscode-go | Go, [Delve][] |
TCL | Supported | --all or --enable-tcl |
tclpro | TCL 8.5 |
Bourne Shell | Supported | --all or --enable-bash |
vscode-bash-debug | Bash v?? |
Node.js | Supported | --force-enable-node |
vscode-node-debug2 | 6<Node<12, Npm |
Javascript | Supported | --force-enable-chrome |
debugger-for-chrome | Chrome |
Java | Supported | --force-enable-java |
vscode-java-debug | Compatible LSP plugin (see later) |
C# (dotnet core) | Experimental | --force-enable-csharp |
netcoredbg | DotNet core |
C# (mono) | Experimental | --force-enable-csharp |
vscode-mono-debug | Mono |
Python.legacy | Legacy | --force-enable-python.legacy |
vscode-python | Node 10, Python 2.7 or Python3 |
在vimspector目錄運行 以上按照你本所需調試語言的命令即可。這裏我只需調試C++代碼。在我本地~/.vim/plugged/vimspector/
下執行
./install.py --enable-c
這裏會去下載一個cpptools-osx.vsix
文件 可以掛vpn運行安裝。或者下好放到對應的文件加即可。
在~/.vim/plugged/vimspector/gadgets/macos
下添加.gadgets.json
文件
{
"adapters": {
"vscode-cpptools": {
"attach": {
"pidProperty": "processId",
"pidSelect": "ask"
},
"command": [
"${gadgetDir}/vscode-cpptools/debugAdapters/OpenDebugAD7"
],
"name": "cppdbg"
}
}
}
新建文件夾~/.vim/plugged/vimspector/gadgets/macos/.gadgets.d
添加lldb-vscode.json
文件
{
"adapters": {
"lldb-vscode": {
"variables": {
"LLVM": {
"shell": "brew --prefix llvm"
}
},
"attach": {
"pidProperty": "pid",
"pidSelect": "ask"
},
"command": [
"${LLVM}/bin/lldb-vscode"
],
"env": {
"LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY":
"YES"
},
"name":"lldb"
}
}
}
項目配置
在項目下添加.vimspector.json
{
"configurations": {
"cpp:launch": {
"adapter": "vscode-cpptools",
"configuration": {
"name": "cpp",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/a.out",
"args": ["*${ProgramArgs}"],
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"stopAtEntry": true,
"MIMode": "lldb",
"logging": {
"engineLogging": true
}
}
}
}
}
其中program
是本地的項目編譯後的文件。這的mac下需要使用clang進行編譯,使用gcc無法調試。
編輯a.cpp
文件
#include<stdio.h>
int main(){
int a = 1;
int b = 2;
int c = a + b;
printf("%d", c);
return 0;
}
vim打開a.cpp
文件 F9
添加斷點 F5
進入調試。結果如下圖所示
F11
逐步調試即可。