Thread: debugging program?

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    230

    debugging program?

    Can anyone tell me a program to debug my "C programs" ? thanks... i am using Ubutnu!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    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
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    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...

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    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.

  5. #5
    Registered User
    Join Date
    Aug 2010
    Posts
    230
    thank you all! i will check them out and post if i got a problem...thanks again...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging strings program help plz
    By allen9190 in forum C Programming
    Replies: 1
    Last Post: 11-08-2009, 08:17 PM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM