简体   繁体   中英

How to run a Linux program line by line

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.

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:

  1. install the packages "build-essential" and "devscripts"
  2. run "sudo apt-get build-dep some_package" to install all things needed to compile that package
  3. run "mkdir -p ~/src/some_package ; cd ~/src/some_package" to create a directory for the source code
  4. Go into System::Administration::Software Sources and activate the "Source Code" repository
  5. run "apt-get source some_package" to download the source code for some_package and put it in the current directory
  6. 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

  1. use "cd .." to move up one step and then do "ls" and you should see the generated DEB files (multiple binary packages, ie DEBs, can be generated from a single source package)
  2. 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.

Look into using GDB and compiling with gcc -g, or using another debugger.

http://en.wikipedia.org/wiki/Gdb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM