我还没有找到我要找的东西,所以我会自己提出问题.
考虑一下下面的C程序
char heap[<some-static-size>];
void main() {
<this-code-reads-and-writes-to-heap>
}
我想在初始化heap
之后,在gdb
中执行这个程序.一种可能性是,我将数组的内容放在一个文件中,然后以某种方式将其提供给GDB.我怎么才能最容易做到这一点呢?一旦main
完成,我想读取heap
的内容并将其写入其他文件.
我还没有找到我要找的东西,所以我会自己提出问题.
考虑一下下面的C程序
char heap[<some-static-size>];
void main() {
<this-code-reads-and-writes-to-heap>
}
我想在初始化heap
之后,在gdb
中执行这个程序.一种可能性是,我将数组的内容放在一个文件中,然后以某种方式将其提供给GDB.我怎么才能最容易做到这一点呢?一旦main
完成,我想读取heap
的内容并将其写入其他文件.
这里可以使用gdb dump and restore命令.将断点设置在main
和exit
.使用&heap[0]
作为起始地址.
$ cat heap.c
char heap[100];
int main() {
heap[0]++;
}
$ dd if=/dev/random of=input.bin count=1 ibs=100
1+0 records in
0+1 records out
100 bytes copied, 0.000306025 s, 327 kB/s
$ gdb -q heap
(gdb) b main
(gdb) commands
>restore input.bin binary &heap[0]
>continue
>end
(gdb) b exit
(gdb) commands
>dump binary memory output.bin &heap[0] &heap[100]
>continue
>end
(gdb) run
Breakpoint 1, main () at heap.c:4
4 heap[0]++;
Restoring binary file input.bin into memory (0x555555558040 to 0x5555555580a4)
Breakpoint 2, __GI__exit (status=0) at ../sysdeps/unix/sysv/linux/_exit.c:140
[Inferior 1 (process 9802) exited normally]
(gdb) q
$ cmp -l input.bin output.bin
1 52 53