我正在调试 C 中的内存问题。我正在访问的内存块被free()
其他人的模块意外 :d 。有没有办法在gdb
一段内存为free()
:d 时得到通知?
问问题
3013 次
2 回答
9
假设你的 libc 的free
参数被称为mem
.
然后,您可以打印出所有被释放的内容:
(gdb) break __GI___libc_free # this is what my libc's free is actually called
Breakpoint 2 at 0x7ffff7af38e0: file malloc.c, line 3698.
(gdb) commands 2
Type commands for when breakpoint 2 is hit, one per line.
End with a line saying just "end".
>print mem
>c
>end
现在,每次任何人c
释放任何东西时,您都会得到一个小打印输出(如果您希望它在每次发生时都停止,您可以省略free
):
Breakpoint 2, *__GI___libc_free (mem=0x601010) at malloc.c:3698
3698 malloc.c: No such file or directory.
in malloc.c
$1 = (void *) 0x601010
或者,如果您已经知道自己感兴趣的内存地址,请cond
在有人尝试访问free
该地址时使用中断:
(gdb) cond 2 (mem==0x601010)
(gdb) c
Breakpoint 3, *__GI___libc_free (mem=0x601010) at malloc.c:3698
3698 malloc.c: No such file or directory.
in malloc.c
(gdb)
于 2012-10-06T07:20:42.340 回答