Say you want to debug vim. If you install vim using apt-get install command, it will install binary, which does not include debug symbol. Here is how to compile a program, for example vim, from source and compile with debug symbols.
First, un-comment lines that start with deb-src in /etc/apt/sources.list file.
Next, update the sources list
$ sudo apt-get update
Download source files
$ apt-get source vim
Note that I am issuing apt-get without sudo command.
Move to the vim directory and configure with -g option
$ cd vim_7.4.1689
$ ./configure CFLAGS='-g'
This -g option is important, as this will tell gcc to compile with debug symbols. If you need to tweak more options, run the following for help:
$ ./configure --help
Finally, make and install.
$ make -j4
$ sudo make install