Compile and debug Vim source code

Hi,

I want to debug Vim source code with GDB but I can't get it. It seems to run without debugger.

Here is my try. I have supressed output of most commands. Tell me if you need them.

$ uname -mor
2.6.37-ARCH i686 GNU/Linux
$ mkdir ~/birei && cd ~/birei
$ wget ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2
$ tar jxvf vim-7.3.tar.bz2 && cd vim73/src
$ cp Makefile Makefile.orig
$ # Change Makefile to request debugging info and install it in my home dir.
$ vim Makefile
$ diff Makefile Makefile.orig
540c540
< CFLAGS = -g
---
> #CFLAGS = -g
908c908
< prefix = ~/birei
---
> #prefix = $(HOME)
$ make
$ make test
...
Test results:
ALL DONE
...
$ make install
$ cd ~/birei/bin/
$ gdb ./vim
GNU gdb (GDB) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from ~/birei/bin/vim...(no debugging symbols found)...done.
(gdb) s
The program is not being run.
(gdb) b main
Function "main" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (main) pending.
(gdb) run
...

At this point Vim runs but without stopping in any point of the source code. How can I stop it in first line of code??

Regards,
Birei

It doesn't know where the source code is so most of the debugging information's missing. Try gdb -d /path/to/source

Also make sure your makefile didn't strip the debugging information out of it at any point.

1 Like

Thanks Corona668,

I got it, there was a line in the Makefile which it stripped the binary. I commented it and now it works. Here my modifications to the original Makefile.

$ vim Makefile
$ diff Makefile Makefile.orig
540c540
< CFLAGS = -g
---
> #CFLAGS = -g
908c908
< prefix = ~/birei
---
> #prefix = $(HOME)
1852c1852
< #    $(STRIP) $(DEST_BIN)/$(VIMTARGET)
---
>     $(STRIP) $(DEST_BIN)/$(VIMTARGET)

And after 'make && make test && make install'

$ gdb ./vim
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from ~/birei/bin/vim...done.
(gdb) b main
Breakpoint 1 at 0x80c7e47: file main.c, line 168.
(gdb) run
Starting program: /home/dcgub/Public/devvim/bin/vim 

Breakpoint 1, main (argc=1, argv=0xbffff444) at main.c:168
168    {
(gdb) 

Regards,
Birei

2 Likes