views:

230

answers:

2

Now I have a c language project which include three directories /bin, /inc and /src. All of header files (.h) are included in /inc and all of source(.c) files are stored in /src, i.e. a.c, b.c, c.c..., the final generated executable file will locate in /bin.

after compling with makefile, all of obj files will be generated in /src/obj like a.o, b.o, c.o, d....! Moreover an final.exe executable file will be generated in the /bin directory.

Now if I want to debug it with GDB, how can I do it???

To debug those obj files in /src/obj? or somewhat else?

Many thanks for the kind help!

A: 

What is the problem with gdb bin/binary.exe? If you compiled correctly and placed -g -ggdb in the compile flags GDB should have enough info to display inlined code

Arkaitz Jimenez
actually, all of the c source files and header files are complied by a Makefile. Do I need to put the "-g -ggdb" parameters into it? Thanks
MaiTiano
yes, the makefile should produce lines like `gcc -g -ggdb -o -c whatever.o whatever.c`
Arkaitz Jimenez
Sorry, `gcc -g -ggdb -c -o whatever.o whatever.c`
Arkaitz Jimenez
Thanks for your help.~
MaiTiano
+3  A: 

You can either debug an application by starting it with GDB

%> gdb <your_executable>

or what is usually easier is to start your application and then attach the debugger to the process using the PID.

%> gdb -p <pid>

For command line options, just type gdb -h and while running inside of gdb help is always available by typing "help" on the gdb command line.

Here is a quick cheat sheet and a tutorial site on some common commands.

As Arkaitz mentioned, be sure to compile your code so that it has the necessary debug information included in the executable.

If debugging from the command line is a bit daunting, there are some UIs available that use GDB. I do a lot of my debugging in Eclipse using gdb.

Once you get started down the gdb path, I'm sure you'll have more questions and I encourage you to ask those more specific questions on SO.

Good luck.

RC
yes, I use gdb lencod.exe.after that when I input "run", I get the following error:................................................Starting program: /home/jl/videocoding/AVS/rm52k_r1/bin/lencod.exe Profile_ID invaild.Program exited with code 0377...............................................So, is there something wrong with my operation?Thanks.
MaiTiano
It appears your code is calling exit on it's own for some reason. (is "Profile_ID invalid" something your outputting?) 0377 is the status code returned by a call to exit() in your program. (See %> man 3 exit)
RC
Thanks for your answer.May I add some information about my question again?? :)After I compling the project with a Makefile, the lencod.exe is generated. Then I can run it together with another config file like this: $./lencod.exe -f encoder.cfg. Do I need to add this cfg file information to the debugging process???Thank you very much again!
MaiTiano
No. The config file information isn't needed by the debugger. You should be able to verify it's use by examining the memory that you're using to store the information contained within the configuration.
RC