假设你的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
Run Code Online (Sandbox Code Playgroud)
现在,每当有人释放任何东西时,你都会得到一点打印输出(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
Run Code Online (Sandbox Code Playgroud)
或者,如果您已经知道自己感兴趣的内存地址,请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)
Run Code Online (Sandbox Code Playgroud)