Using GDB to dump memory variables

This is a discussion on Using GDB to dump memory variables within the Tech Board forums, part of the Community Boards category; Hi guys, I am new to GDB and I need to use it in my research. I have some questions: ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    4

    Post Using GDB to dump memory variables

    Hi guys,

    I am new to GDB and I need to use it in my research. I have some questions:

    1- I need to set the debugger to run instructions one by one and after each instruction, copy the value of all the variables in some file (I want to process this data in the future) and then do this again for the next instruction and so on... Does anyone know how can I do such thing (or something close to this, like dumping the memory used by my code in a file)?

    2- how can I write a script to run some commands in gdb? because I want to do the thing I mentioned for every instruction, so it is really a pain in the a@@ if I have to do it manually.

    Sorry if I seem so blunt, that's because I don't know much about gdb.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,498
    This would be more appropriate in the Linux or general board if a mod wants to move it. Since you're new to GDB I wont bust your balls too bad, but seriously, did you even try to figure this out on your own? I'm guessing no:
    Code:
    (gdb) help
    List of classes of commands:
    
    aliases -- Aliases of other commands
    breakpoints -- Making program stop at certain points
    data -- Examining data
    files -- Specifying and examining files
    internals -- Maintenance commands
    obscure -- Obscure features
    running -- Running the program
    stack -- Examining the stack
    status -- Status inquiries
    support -- Support facilities
    tracepoints -- Tracing of program execution without stopping the program
    user-defined -- User-defined commands
    
    Type "help" followed by a class name for a list of commands in that class.
    Type "help all" for the list of all commands.
    Type "help" followed by command name for full documentation.
    Type "apropos word" to search for commands related to "word".
    Command name abbreviations are allowed if unambiguous.
    (gdb) help data
    Examining data.
    
    List of commands:
    
    append -- Append target code/data to a local file
    append binary -- Append target code/data to a raw binary file
    append binary memory -- Append contents of memory to a raw binary file
    append binary value -- Append the value of an expression to a raw binary file
    append memory -- Append contents of memory to a raw binary file
    append value -- Append the value of an expression to a raw binary file
    call -- Call a function in the program
    disassemble -- Disassemble a specified section of memory
    display -- Print value of expression EXP each time the program stops
    dump -- Dump target code/data to a local file
    dump binary -- Write target code/data to a raw binary file
    dump binary memory -- Write contents of memory to a raw binary file
    dump binary value -- Write the value of an expression to a raw binary file
    dump ihex -- Write target code/data to an intel hex file
    dump ihex memory -- Write contents of memory to an ihex file
    dump ihex value -- Write the value of an expression to an ihex file
    dump memory -- Write contents of memory to a raw binary file
    dump srec -- Write target code/data to an srec file
    dump srec memory -- Write contents of memory to an srec file
    dump srec value -- Write the value of an expression to an srec file
    dump tekhex -- Write target code/data to a tekhex file
    dump tekhex memory -- Write contents of memory to a tekhex file
    dump tekhex value -- Write the value of an expression to a tekhex file
    dump value -- Write the value of an expression to a raw binary file
    ...
    (gdb) help support
    Support facilities.
    
    List of commands:
    
    apropos -- Search for commands matching a REGEXP
    define -- Define a new command name
    document -- Document a user-defined command
    dont-repeat -- Don't repeat this command
    down-silently -- Same as the `down' command
    echo -- Print a constant string
    help -- Print list of commands
    if -- Execute nested commands once IF the conditional expression is non zero
    interpreter-exec -- Execute a command in an interpreter
    make -- Run the ``make'' program using the rest of the line as arguments
    overlay -- Commands for debugging overlays
    overlay auto -- Enable automatic overlay debugging
    overlay list-overlays -- List mappings of overlay sections
    overlay load-target -- Read the overlay mapping state from the target
    overlay manual -- Enable overlay debugging
    overlay map-overlay -- Assert that an overlay section is mapped
    overlay off -- Disable overlay debugging
    overlay unmap-overlay -- Assert that an overlay section is unmapped
    quit -- Exit gdb
    require -- Prefix command for requiring features
    require command -- Demand-load a command by name
    require function -- Demand-load a function by name
    shell -- Execute the rest of the line as a shell command
    source -- Read commands from a file named FILE
    up-silently -- Same as the `up' command
    while -- Execute nested commands WHILE the conditional expression is non zero
    That should get you started in the right direction. GDB has pretty decent built-in help, and Google can fill you in with some details and examples. You can't do too much harm by playing around, and you stand to learn quite a bit, so give it a shot.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    4

    Post

    Thanks,
    Actually I looked at the help, but didn't see this, I'll try to figure out the rest by myself, I think this info will point me in the right direction for now.

    Quote Originally Posted by anduril462 View Post
    This would be more appropriate in the Linux or general board if a mod wants to move it. Since you're new to GDB I wont bust your balls too bad, but seriously, did you even try to figure this out on your own? I'm guessing no:
    Code:
    (gdb) help
    List of classes of commands:
    
    aliases -- Aliases of other commands
    breakpoints -- Making program stop at certain points
    data -- Examining data
    files -- Specifying and examining files
    internals -- Maintenance commands
    obscure -- Obscure features
    running -- Running the program
    stack -- Examining the stack
    status -- Status inquiries
    support -- Support facilities
    tracepoints -- Tracing of program execution without stopping the program
    user-defined -- User-defined commands
    
    Type "help" followed by a class name for a list of commands in that class.
    Type "help all" for the list of all commands.
    Type "help" followed by command name for full documentation.
    Type "apropos word" to search for commands related to "word".
    Command name abbreviations are allowed if unambiguous.
    (gdb) help data
    Examining data.
    
    List of commands:
    
    append -- Append target code/data to a local file
    append binary -- Append target code/data to a raw binary file
    append binary memory -- Append contents of memory to a raw binary file
    append binary value -- Append the value of an expression to a raw binary file
    append memory -- Append contents of memory to a raw binary file
    append value -- Append the value of an expression to a raw binary file
    call -- Call a function in the program
    disassemble -- Disassemble a specified section of memory
    display -- Print value of expression EXP each time the program stops
    dump -- Dump target code/data to a local file
    dump binary -- Write target code/data to a raw binary file
    dump binary memory -- Write contents of memory to a raw binary file
    dump binary value -- Write the value of an expression to a raw binary file
    dump ihex -- Write target code/data to an intel hex file
    dump ihex memory -- Write contents of memory to an ihex file
    dump ihex value -- Write the value of an expression to an ihex file
    dump memory -- Write contents of memory to a raw binary file
    dump srec -- Write target code/data to an srec file
    dump srec memory -- Write contents of memory to an srec file
    dump srec value -- Write the value of an expression to an srec file
    dump tekhex -- Write target code/data to a tekhex file
    dump tekhex memory -- Write contents of memory to a tekhex file
    dump tekhex value -- Write the value of an expression to a tekhex file
    dump value -- Write the value of an expression to a raw binary file
    ...
    (gdb) help support
    Support facilities.
    
    List of commands:
    
    apropos -- Search for commands matching a REGEXP
    define -- Define a new command name
    document -- Document a user-defined command
    dont-repeat -- Don't repeat this command
    down-silently -- Same as the `down' command
    echo -- Print a constant string
    help -- Print list of commands
    if -- Execute nested commands once IF the conditional expression is non zero
    interpreter-exec -- Execute a command in an interpreter
    make -- Run the ``make'' program using the rest of the line as arguments
    overlay -- Commands for debugging overlays
    overlay auto -- Enable automatic overlay debugging
    overlay list-overlays -- List mappings of overlay sections
    overlay load-target -- Read the overlay mapping state from the target
    overlay manual -- Enable overlay debugging
    overlay map-overlay -- Assert that an overlay section is mapped
    overlay off -- Disable overlay debugging
    overlay unmap-overlay -- Assert that an overlay section is unmapped
    quit -- Exit gdb
    require -- Prefix command for requiring features
    require command -- Demand-load a command by name
    require function -- Demand-load a function by name
    shell -- Execute the rest of the line as a shell command
    source -- Read commands from a file named FILE
    up-silently -- Same as the `up' command
    while -- Execute nested commands WHILE the conditional expression is non zero
    That should get you started in the right direction. GDB has pretty decent built-in help, and Google can fill you in with some details and examples. You can't do too much harm by playing around, and you stand to learn quite a bit, so give it a shot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How are variables stored in memory.
    By ineedmunchies in forum C++ Programming
    Replies: 3
    Last Post: 04-29-2010, 05:49 PM
  2. Accessing variables with memory address
    By ITAmember in forum C Programming
    Replies: 54
    Last Post: 06-28-2009, 03:35 AM
  3. find variables in memory
    By muehl in forum C++ Programming
    Replies: 8
    Last Post: 06-30-2007, 05:31 PM
  4. Freeing memory for non-pointer variables
    By SuperGodAntMan in forum C++ Programming
    Replies: 7
    Last Post: 02-11-2006, 12:30 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21