Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6550924
  • 博文数量: 1159
  • 博客积分: 12444
  • 博客等级: 上将
  • 技术积分: 12570
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 21:34
文章分类

全部博文(1159)

文章存档

2016年(126)

2015年(350)

2014年(56)

2013年(91)

2012年(182)

2011年(193)

2010年(138)

2009年(23)

分类: C/C++

2015-10-15 09:26:16

(gdb) help dump binary memory
Write contents of memory to a raw binary file.
Arguments are FILE START STOP.  Writes the contents of memory
within the range [START .. STOP) to the specified FILE in binary format.

(gdb) dump binary memory my_binary_file.bin 0x22fd8a 0x22fd8a+450

++++++++++++++++++++++++++++++++++++++++++++++++++


http://blog.csdn.net/zhangmiaoping23/article/details/40892261

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

 dump [格式] value 文件名 表达式                        #   把指定值写到文件
        格式包括:
            binary      原始二进制格式
            ihex        intel 16进制格式
            srec        S-recored格式
            tekhex      tektronix 16进制格式


 append [binary] memory 文件名 起始地址 结构地址 #   按2进制追加到文件
 append [binary] value 文件名 表达式             #   按2进制追加到文件
    

restore 文件名 [binary] bias 起始地址 结构地址 #   恢复文件中内容到内存.如果文件内容是原始二进制,需要指定binary参数,不然会gdb自动识别文件格式


目的:

在gdb调试过程中(甚至是在调试coredump时),将程序内存中的内容dump到指定文件中。


gdb命令:

(gdb) dump binary memory ./file START STOP

将 [START, STOP) 地址范围内的内存内容输出到文件 file 中


举例:

1)将 [$pc, $pc+450) 范围内的内存输出到./file 中

  1. (gdb) p $pc  
  2. $1 = (void (*)()) 0x4004a7 <main+11>  
  3. (gdb) p $pc + 450  
  4. $2 = (void (*)()) 0x400669  
  5. (gdb) dump binary memory ./file $1 $2 

  1. (gdb) p $pc  
  2. $1 = (void (*)()) 0x4004a7 <main+11>  
  3. (gdb) p $pc + 450  
  4. $2 = (void (*)()) 0x400669  
  5. (gdb) dump binary memory ./file $1 $2 

2)将字符串s1的前5个字节输出到./a中

  1. int main ()  
  2. {  
  3.         char s1[] = "abcdefghijklmnopqrstuvwxyz";  
  4.         char s2[] = "0123456789";  
  5.   
  6.   return 0;  

[root@ampcommons02 yasi]# gdb ./dump -q
Reading symbols from /home/yasi/s...done.
(gdb) b 6
Breakpoint 1 at 0x4005a4: file s.cpp, line 6.
(gdb) r
Starting program: /home/yasi/s

Breakpoint 1, main () at s.cpp:6
6         return 0;
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.80.el6_3.6.x86_64 libgcc-4.4.6-4.el6.x86_64 libstdc++-4.4.6-4.el6.x86_64
(gdb) dump binary memory ./dump s1 s1+5


[root@ampcommons02 yasi]# cat ./dump
abcde









阅读(2972) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~