Can anyone tell me a program to debug my "C programs" ? thanks... i am using Ubutnu!
Printable View
Can anyone tell me a program to debug my "C programs" ? thanks... i am using Ubutnu!
gcc -g prog.c
gdb a.out
Then type "help" at the gdb prompt
Then type "run"
Or you can use one of several GUI front-ends to gdb, like emacs or ddd
i was currently using gdb, but i don' t understand how this helps to debug programs...i mean, sometimes i have segmentation fault and all it does is print in the screen Segmentation Fault...which does not help me. however i may be wrong with my thoughts... Can you please help me a little? thanks...
If you run your program in gdb and it seg faults, gdb will "catch" the seg fault signal and halt the program on the offending line. You can then ask for a backtrace, using the...wait for it...backtrace command. This will show you the file name and line number that caused the crash, and you can even examine variable values, using "print variable_name_or_expression". There is a lot more to learn about it, but those two commands will help you find the majority of your common seg fault issues. There's also valgrind, a special memory usage analysis tool, and efence, a library you compile into your program to help catch memory errors.
Some info & tutorials:
Cprogramming.com - Debuggers
Cprogramming.com - Tutorials - An Introduction to GDB
Using Valgrind to Find Memory Leaks - Cprogramming.com
I can't find a good link for efence off hand, but I can work on that if you need it.
One caveat for using gdb, you have to compile your program to include debugging symbols (the "-g" flag that Salem mentioned) so that you can see and use function/variable names, otherwise you just get arbitrary addresses for all your identifiers.
thank you all! i will check them out and post if i got a problem...thanks again...