gdb dump binary memory to file

参考:http://stackoverflow.com/questions/13568215/how-can-i-dump-the-output-of-the-x-command-in-gdb-to-a-file


目的:

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


gdb命令:

(gdb) dump binary memory ./file START STOP

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


举例:

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

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

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

int main ()
{
        char s1[] = "abcdefghijklmnopqrstuvwxyz";
        char s2[] = "0123456789";

  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


阅读更多

没有更多推荐了,返回首页