24

What gdb frontends can I use with vim for debugging C and C++ code? Currently I use cgdb and am satisfied with it. Was just wondering what else is out there?

maxschlepzig
  • 35,645
  • 14
  • 145
  • 182
Letholdrus
  • 1,261
  • 3
  • 20
  • 36
  • 2
    Have you searched on google? simple search gives an elaborate [list](http://en.wikipedia.org/wiki/Debugger#List_of_debugger_front-ends) – Alok Save Jul 14 '11 at 15:12
  • 4
    Check out this thread: http://stackoverflow.com/questions/185043/gvim-and-gdb-for-c personally I starting using cgdb and have never looked back. – Grammin Jul 14 '11 at 15:13
  • 3
    By the way, you _do_ use the gdb `ed` command, do you? The combination of pure gdb + ed + ctags is killer, IMHO – sehe Jul 14 '11 at 15:19

4 Answers4

14

Look at pyclewn. As written on vim.org:

Pyclewn - an extension for Vim that supports full use of gdb from Vim. With breakpoints, watch variables, gdb command completion, etc. Uses the NetBeans interface.

Maybe it's not so easy to start use it as cgdb, but it's easy to use it.

First you need to compile vim with +netbeans_intg feature and +python/dyn or +python3/dyn For example you use python3. Configure vim like this:

./configure --with-features=huge --enable-python3interp

Don't forget to install python header files (package python3-dev). Then download pyclewn-1.7.py3.tar.gz and install.

You can use installation manual from site or install it with pathogen. To install with pathogen:

tar zxvf pyclewn-1.7.py3.tar.gz
vimdir=$HOME/.vim/bundle/pyclewn python3 setup.py install --force --home=$HOME/.vim/local

Change line $HOME/.vim/local/lib/python/clewn/vim.py:343 from 'runtime plugin/pyclewn.vim' to 'runtime bundle/pyclewn/plugin/pyclewn.vim'

Add path $HOME/.vim/local/bin (or any other that you use) to your PATH.

Add variable

export CLEWNDIR=$HOME/.vim/bundle/pyclewn/macros

You can change key mapping in file $HOME/.vim/bundle/pyclewn/macros/.pyclewn_keys.gdb

For easy pyclewn running I use next bash file: $HOME/.vim/local/bin/pclewn

#!/bin/bash
pyclewn --gdb="async" --args="--args $@" --cargs='-c "runtime misc/pclewn.vim" -c "call PyClewnPre()"'

and vim script $HOME/.vim/misc/pclewn.vim

function! PyClewnInit()
    C tbreak main
    Cmapkeys
    unmap <CR>
endfunction

function! PyClewnPre()
    map <CR> :call PyClewnInit()<CR>
    0put ='Press <Enter> to start'
    setlocal buftype=nofile
endfunction

So, to start debugging I use command:

pclewn my_program arg1 arg2 argN

UPD: Your C++ program probably uses STL containers. To display them nicely download dbinit_stl_views-1.03.txt and rename this file to ~/.gdbinit. After this you can use commands like:

pstring stl_variable
pvector stl_variable

Help available from gdb, for example by command 'help pmap'. Read more here

And of course you can map key to print string under cursor like this:

nmap <F1> :exe "C pstring " . expand("<cword>")<CR>
KOlegA
  • 638
  • 6
  • 8
  • Assuming the OP is using G++ the standard library comes with its own python-based pretty printers that are better than the "stl views" macros – Jonathan Wakely Jan 19 '13 at 16:01
13

Google is your friend. http://clewn.sourceforge.net/

Honestly, I think that you're better off sticking with cgdb.

Yang
  • 7,712
  • 9
  • 48
  • 65
user606723
  • 4,918
  • 2
  • 27
  • 34
  • 5
    +1 I stick with gdb. The good old basics (very good to prevent the [`programming by accident habit`](http://en.wikipedia.org/wiki/Programming_by_permutation) that is encouraged by smooth interactive debugging. Slowing down the steps makes you **think** carefully; In my experience, that helps you find problems faster) – sehe Jul 14 '11 at 15:17
  • 2
    Thanks all who answered I think I will stay with cgdb then. – Letholdrus Jul 14 '11 at 15:49
8

Conque GDB is very similar to cgdb. It is a terminal emulator which turns a vim buffer into a gdb command line interface. See http://www.vim.org/scripts/script.php?script_id=4582

Druesukker
  • 249
  • 3
  • 10
-1

IMO, gdb TUI is the easiest. You can look at the list of key bindings here: http://sourceware.org/gdb/onlinedocs/gdb/TUI-Keys.html#TUI-Keys

Especially, s (step-in) and f (finish the function and return) are most useful key bindings.

Arun
  • 1,399
  • 12
  • 21
  • The TUI is a great debugger, but a useless source code viewer. Having vim jump to the relevant line of code is very nice, it allows you to see the whole function easily and to search within the source file. – Jonathan Wakely Jan 19 '13 at 16:03