0%

gdb dump内存数据

gdb调试过程中从内存中dump出相关数据用于分析

help dump

在gdb中输入:

(gdb) help dump
Dump target code/data to a local file.

List of dump subcommands:

dump binary -- Write target code/data to a raw binary file
dump ihex -- Write target code/data to an intel hex file
dump memory -- Write contents of memory to a raw binary file
dump srec -- Write target code/data to an srec file
dump tekhex -- Write target code/data to a tekhex file
dump value -- Write the value of an expression to a raw binary file

Type "help dump" followed by dump subcommand name for full documentation.
Type "apropos word" to search for commands related to "word".
Command name abbreviations are allowed if unambiguous.

dump [格式] memory 文件名 起始地址 结构地址 #   把指定内存段写到文件
dump [格式] value 文件名 表达式             #   把指定值写到文件

格式包括:

  • binary 原始二进制格式
  • ihex intel 16进制格式
  • srec S-recored格式
  • tekhex tektronix 16进制格式

命令具体参数格式:

dump binary memory filename start_addr end_addr
    Dump contents of memory from start_addr to end_addr into raw binary format file filename.
dump binary value filename expression
    Dump value of expression into raw binary format file filename.
dump ihex memory filename start_addr end_addr
    Dump contents of memory from start_addr to end_addr into intel hex format file filename.
dump ihex value filename expression
    Dump value of expression into intel hex format file filename.
dump srec memory filename start_addr end_addr
    Dump contents of memory from start_addr to end_addr into srec format file filename.
dump srec value filename expression
    Dump value of expression into srec format file filename.
dump tekhex memory filename start_addr end_addr
    Dump contents of memory from start_addr to end_addr into tekhex format file filename.
dump tekhex value filename expression
    Dump value of expression into tekhex format file filename.

用法

(gdb) dump binary memory file $1 $2         //$1 $2为地址
(gdb) dump binary memory ./dump s1 s1+5     //s1为数组
(gdb) dump memory file 0x9000xxxx 0x9001xxxx     //s1为数组

通过以上command来完成内存对比。

  1. Copy between memory and a file
  2. gdb 内存复制到/从文件