Results 1 to 3 of 3
Thread: debugging source code
Enjoy an ad free experience by logging in. Not a member yet? Register.
- Join Date
- Oct 2011
debugging source code
I wanted to ask how to debug a source code for eg. kernel source code using gdb, also how to compile one entire directory in linux.
Please help me out with this as soon as possible...
- Join Date
- Mar 2009
If you want to debug kernel code, you should look at kgdb. However, 'debugging kernels' is a tricky thing, it's not like you can start the kernel via gdb and step through the instructions and set breakpoints etc.
As to 'compile one entire directory' - what exactly do you mean?
If your application contains a lot of components, you'd normally use make, so I'd start looking for a makefile (or Makefile, ymmv).
- Join Date
- Nov 2008
- Tokyo, Japan
To compile all file in a directory, using the command line, you simply use the "glob" operator, wihch is an asterisk (*) charachter. So lets say your program directory contains the files "one.c", "two.c" and "three.c". If you first change directories to your program directory:Code:
gcc -o myApp *.c # this is exactly the same as typing: gcc -o myApp one.c two.c three.cCode:
gdb --args myApp --flag1 --flag2 --etc
Once you set your break point, type "run" to execute the program, and it will pause as soon as it executes the line of code where your break point was set. If you typed "b main", it will pause right at the beginning of your program.
When GDB pauses, you can use one-letter commands to control what it does next, like "l", "s", or "n". You can then enter "s" to tell gdb to execute one line of code in your program. Keep entering "s" until you get to where you want.
If you come to a line of code with a function call like "printf" and you enter "s", it will take you through each line of code of "printf", which may not be C code, it may be assembler. You probably don't care what "printf" is doing, so if you want to execute "printf" without seeing the code inside of it, enter "n" in the GDB command line when GDB pauses on "printf()" or any other standard library function call.
If you want to know where you are in your program, enter "l" (lowercase "L") in the command line, and you will see 10 lines of code from your program around the current line GDB is executing.
That is the simplest introduction to GDB you can get. Play around with it until you get stuck. If you want to learn more, you need to Google for "GDB tutorials".