Thread: gdb help

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    4

    gdb help

    i want to know

    how we can debug the program line by line with gdb

    for ex
    #gdb <program name>

    so how to proceed

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    143
    typing 'help' gives quite a lot of info on the available commands.
    I'm sure there is documentation on the web as well, eg here:
    http://sources.redhat.com/gdb/onlinedocs/gdb_toc.html
    DavT
    -----------------------------------------------

  3. #3
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    When you compile your code with gcc, be sure to include the -g flag. This adds the debugging symbols that gdb will use to help you walk through the code.
    Code:
    gcc -g -o myProg myProg.c
    As DavT pointed out, 'help' will show you what gdb is capable of. Here are a few commonly used commands:
    [list=1][*]l - List the source code. Optionally, you can provide a line number, code segment address, or function name after the L (such as "l main" to list the main function)[*]b <location> - Breakpoint. The location may be a line number, code segment address, or function name. When the application hits a breakpoint, execution is suspended (so you can do whatever it is you wanted to do at that point, such as examine variables).[*]r - Run the application.[*]n - Next. Executes the current statement and then pauses.[*]s - Step. Similar to next. If you 'step' with a statement that has a function call in it, step will take you into the function (next does not).[*]c - Continue. Allows the program to continue executing after you have interrupted (with control-c) or after hitting a breakpoint.[*]p <variable> - Print value of a variable or memory location.[*]set args <arguments> - Set the command line arguments for the program you're debugging.[*]k - Kill the application being debugged.[*]q - Quit gdb.[*]d b <number> - Delete a breakpoint.[/list=1]
    There are plenty of other commands worth knowing (show and watch come to mind), so be sure to play around with gdb's built in help and experiment with the other commands.

    For your first time through with gdb, set a breakpoint at main() (b main) and run (r) the application. The program will stop at the first instruction in main() and show it to you. Then use next (n) to go through each statement, one by one.
    Jason Deckard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. buffered vs unbuffered question
    By Overworked_PhD in forum Linux Programming
    Replies: 6
    Last Post: 07-04-2008, 04:57 PM
  2. Memory allocation error
    By cunnus88 in forum C++ Programming
    Replies: 5
    Last Post: 01-25-2008, 04:24 PM
  3. Contiguous Array version of Linked List
    By ampersand11 in forum C Programming
    Replies: 19
    Last Post: 10-07-2007, 03:05 AM
  4. Too much output in GDB
    By MacNilly in forum Tech Board
    Replies: 0
    Last Post: 09-13-2006, 12:45 PM
  5. does gdb lie?
    By dinjas in forum C Programming
    Replies: 8
    Last Post: 03-10-2005, 05:17 PM