Vim plugin implement GDB front-end for c/c++ gdb base on Neovim + Tmux:
- Re-implement plugin neogdb.vim by python,
- Windows layout manage by Tmux
- Ref: /~https://github.com/sakhnik/nvim-gdb/
- gdb commands maps: next, step, finish, continue, etc.
- breakpoints:
- auto save/load,
- populate to local list: lopen
- side color sign
- triple state: enable -> disable -> delete
- toggle current line/toggle-all-breakpoints
- support condition set
- backtrace:
- populate to quickfix: copen
-
neovim +python3
-
tmux
-
python3 library:
- pip3 install --user pynvim
- pip3 install --user libtmux
-
Install This vim plugin vimgdb
- If using vim-plugin-manage like: vim-plug
- add to
.vimrc
Plug 'huawenyu/vimgdb' - install the plug Execute vim's command: ":PlugInstall"
- add to
- If using vim-plugin-manage like: vim-plug
-
Press to toggle local or remote(need script support login to remote host and start gdbserver listen on port).
-
About the remote gdbserver, we can use the auto-login script like autossh to make connect simple.
-
Debug: Focus the source code t1.c windows, and Press: F5 next S-F5 skip F6 step S-F6 return to caller F8 eval current value
- Open terminal like xterm, gnu-terminal
- start tmux: $ tmux new -s test
- edit a *.c file by neovim: $ nvim t1.c $ gcc -g -O0 -o t1 t1.c
- Press , or execute command :call VimGdb('local', 't1')
- The gdb frontend start:
- will close current tmux-window's other panes execept the nvim pane
- recreate another new pane for gdb-shell
- auto set breakpoint at main() if no breakpoint
- run and pause at main, or at your breakpoint
If define g:neobugger_leader, will ignore all g:gdb_keymap_... customized.
let g:neobugger_leader = ';'
Then the keymaps will be g:neobugger_leader
+ <char>
, the <char>
like:
r
: GdbRefreshc
: GdbContinuen
: GdbNexti
: GdbStepN
: GdbFinisht
: GdbUntilb
: GdbToggleBreaka
: GdbToggleBreakAllC
: GdbClearBreakx
: GdbDebugStopk
: GdbFrameUpj
: GdbFrameDown
Mapping | Command | Description |
---|---|---|
<F4> | :GdbContinue |
Continue execution (continue in gdb) |
<F5> | :GdbNext |
Step over the next statement (next in gdb) |
<F6> | :GdbStep |
Step into the next statement (step in gdb) |
<F7> | :GdbFinish |
Step out the current frame (finish in gdb) |
<F8> | :GdbEval |
Eval current variable's value (print var in gdb) |
<F9> | :GdbBreakpointToggle |
Toggle breakpoint in the coursor line |
<c-p> | :GdbFrameUp |
Navigate one frame up (up in gdb) |
<c-n> | :GdbFrameDown |
Navigate one frame down (down in gdb) |
" Howto map Shift+F#:
" - Goto insert mode and hit Ctrl-V Shift-F#, which gotted we can use that to map.
" - For example: We get "<F15>" when input Shift+F5, so ':nmap <F15> echo "HELLO"<cr>' should be work.
" The default config:
"
let g:gdb_keymap_refresh = '<f3>'
let g:gdb_keymap_continue = '<f4>'
let g:gdb_keymap_debug_stop = '<F14>'
let g:gdb_keymap_next = '<f5>'
let g:gdb_keymap_skip = '<F15>'
let g:gdb_keymap_step = '<f6>'
let g:gdb_keymap_finish = '<F16>'
let g:gdb_keymap_until = '<f7>'
let g:gdb_keymap_eval = '<f8>'
let g:gdb_keymap_watch = '<F18>'
let g:gdb_keymap_toggle_break = '<f9>'
let g:gdb_keymap_remove_break = '<F19>'
let g:gdb_keymap_toggle_break_all = '<f10>'
let g:gdb_keymap_clear_break = '<F20>'
let g:gdb_keymap_frame_up = '<c-n>'
let g:gdb_keymap_frame_down = '<c-p>'
let g:neogdb_gdbserver = 'gdbserver'
let g:neogdb_attach_remote_str = 't1 127.0.0.1:9999'
let g:gdb_auto_run = 1
let g:gdb_require_enter_after_toggling_breakpoint = 0
let g:restart_app_if_gdb_running = 1
let g:neobugger_smart_eval = 0
let g:neobugger_local_breakpoint = 0
let g:neobugger_local_backtrace = 0
let g:neobugger_server_breakpoint = 1
let g:neobugger_server_backtrace = 1
+-------------------------+--------------------------+
| | |
| | |
| | |
| | terminal> |
| Code c/c++ | (gdb) |
| | |
| | |
| | |
| | |
| +--------------------------+
| | |
+-------------------------+ backtrace |
| breakpoints | |
| | |
+-------------------------+--------------------------+
check source code class Common(BaseCommon)
-
change vimgdb/config/logger.py: LOGGING_CONFIG.loggers '': { 'level': 'DEBUG', <=== change log level 'handlers': ['file'], <=== Enable log by 'file', Disable log by 'null' 'propagate': False },
-
monitor the debug log: Monitor LOGGING_CONFIG.handlers.file.filename, here is '/tmp/vimgdb.log': $ tail -f /tmp/vimgdb.log
-
color the tail: "grc tail -f /tmp/vimgdb.log"
grc Install: $ brew install grc
Usage: $ grc netstat $ grc ping hostname $ grc tail /var/log/syslog $ grc ps aux