[英]How to get notified in gdb when memory is freed?
我正在調試C中的內存問題。我正在訪問的內存塊被意外free()
:由其他人的模塊執行。 當一塊內存free()
時, gdb
有沒有辦法得到通知free()
:d?
假設你的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
現在,每當有人釋放任何東西時,你都會得到一點打印輸出(如果你想讓它在每次free
時都停止,你可以省略c
):
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
或者,如果您已經知道您感興趣的內存地址,請在有人試圖free
該地址時使用cond
中斷:
(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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.