All Projects → huawenyu → vimgdb

huawenyu / vimgdb

Licence: Unlicense license
Vim gdb base on Neovim + Tmux

Programming Languages

python
139335 projects - #7 most used programming language
Vim Script
2826 projects
shell
77523 projects

vimgdb

Vim plugin implement GDB front-end for c/c++ gdb base on Neovim + Tmux:

Feature

  • 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

PreRequire [must]

  • 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"
  • 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

QuickStart

  1. Open terminal like xterm, gnu-terminal
  2. start tmux: $ tmux new -s test
  3. edit a *.c file by neovim: $ nvim t1.c $ gcc -g -O0 -o t1 t1.c
  4. Press , or execute command :call VimGdb('local', 't1')
  5. 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

Command & Keymap

keymaps leader

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: GdbRefresh
  • c: GdbContinue
  • n: GdbNext
  • i: GdbStep
  • N: GdbFinish
  • t: GdbUntil
  • b: GdbToggleBreak
  • a: GdbToggleBreakAll
  • C: GdbClearBreak
  • x: GdbDebugStop
  • k: GdbFrameUp
  • j: GdbFrameDown

keymaps without leader

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

Layout

+-------------------------+--------------------------+
|                         |                          |
|                         |                          |
|                         |                          |
|                         |    terminal>             |
|     Code c/c++          |    (gdb)                 |
|                         |                          |
|                         |                          |
|                         |                          |
|                         |                          |
|                         +--------------------------+
|                         |                          |
+-------------------------+  backtrace               |
| breakpoints             |                          |
|                         |                          |
+-------------------------+--------------------------+

Screen Demo

screen

Const define

check source code class Common(BaseCommon)

Troubleshooting

Enable log

  1. 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 },

  2. monitor the debug log: Monitor LOGGING_CONFIG.handlers.file.filename, here is '/tmp/vimgdb.log': $ tail -f /tmp/vimgdb.log

  3. 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].