I would like to run a GTK+/C program line by line with some debugger. I have never debugged a Linux program so where can I find instructions to a very beginner on how to debug code? I have just an idea that I have to download the sources from net, compile the project with debug symbols and run sources through DDD or GDB. So can anyone give suggestions how to start studying these subjects and what could be a good debugger to start? I have at least time to learn things.
Look into using GDB and compiling with gcc -g, or using another debugger.
I'd go into more detail, but your 0% accept rate is concerning.
Also look into nemiver besides DDD, they are good at different things but nemiver is coming along very nicely.
PS. If you're on Ubuntu and you want to step through an application that's installed from the package repository, let's called it some_package, then do this:
- install the packages "build-essential" and "devscripts"
- run "sudo apt-get build-dep some_package" to install all things needed to compile that package
- run "mkdir -p ~/src/some_package ; cd ~/src/some_package" to create a directory for the source code
- Go into System::Administration::Software Sources and activate the "Source Code" repository
- run "apt-get source some_package" to download the source code for some_package and put it in the current directory
- use "cd" to move into the specific app directory, usually something like "some-app-1.2.3"
7A. run "debuild -us -uc -b" to compile the source into a fresh installable .DEB file compiled in release mode WITHOUT debug information
or (and this is the central part):
7B. run "MAKEFLAGS=-j6 DEB_BUILD_OPTIONS="nostrip noopt parallel=5" CFLAGS="-g3 -O0" debuild -us -uc" to build a deb in debug mode WITH debug information
- use "cd .." to move up one step and then do "ls" and you should see the generated DEB files (multiple binary packages, i.e. DEBs, can be generated from a single source package)
- sudo "sudo dpkg -i some_package_123.deb" to install the version you just built
Of course, you could optionally modify the code between steps 6 and 7. The nice thing about this method is that it works for pretty much any application. You can use it for Firefox, the Linux kernel, the mesa stack or whatever.
http://www.sourceware.org/current/onlinedocs/gdb%5Ftoc.html
Full gdb user manual online.