How to use:
You can use the commands dump
, append
and to restore
copy data between target memory and a file. dump
append
The and commands write data to a file, and the restore
command reads data from a file back into the inferior ' s M Emory. Files May is in binary, Motorola S-record, Intel hex, or Tektronix hex format; However, GDB can only append to binary files.
-
-
dump
[format]
memory
filename start_addr end_addr
-
-
dump
[ format ]
value
filename expr
-
-
Dump the contents of memory from start_addr to end_addr , or the value OF&NB Sp expr , to filename in the given format.
the format parameter May is any one of:
-
binary
-
Raw binary form.
-
ihex
-
Intel Hex format.
-
Srec
-
Motorola S-record format.
-
Tekhex
-
Tektronix Hex format.
gdb uses the same definitions of these formats as The gnu&nbs P;binary utilities, like ' objdump ' and ' objcopy '. if format is omitted, gdb dumps the data in raw binary form.
-
-
append
[
binary
]
memory
filename start_addr end_addr
-
-
append
[
binary
]
value
filename expr
-
-
Append the contents of memory from start_addr end_addr to, or the value expr of, to the file filename , in raw bin ary form. ( gdb can only append the data to the files in raw binary form.)
-
-
restore
filename [
binary
] bias start end
-
Restore the contents of file filenameinto memory. The
restore
command can automatically recognize any known BFD file format, except for raw binary. To restore a raw binary file you must specify the optional keyword after the
binary
filename.
If bias is Non-zero, its value would be added to the addresses contained in the file. Binary files always start at address zero and so they'll be restored at address bias . Other BFD files has a built-in location; They'll is restored at offset from the bias .
If start and/or end is Non-zero, then only data between file offset and start file offset would be end restored. These offsets was relative to the addresses of the file, before the bias argument is applied.
As an example:
dump binary memory result.bin 0x200000000 0x20000c350
This would give you a plain binary dump int file result.bin
. You can also with the following to dump it in hex format:
dump ihex memory result.bin 0x200000000 0x20000c350
Using the dump command is a much clearer than using the GDB logging hack (which even did not work for me somehow)
Reference Document: Https://stackoverflow.com/questions/16095948/gdb-dump-memory-save-formatted-output-into-a-file
GDB Dump Mem Example and commands