Valgrind报告转储丢失的内存内容 [英] Dumping contents of lost memory reported by Valgrind
问题描述
当我在程序上运行valgrind --leak-check=yes
时,报告了一些字节的内存丢失.是否可以查看该内存的内容(即转储存储在其中的数据)?
When I run valgrind --leak-check=yes
on a program, a few bytes of lost memory are reported. Is it possible to view the contents of this memory (i.e. dump the data that is stored in it)?
推荐答案
您可以使用最新版本的Valgrind(3.8.1)来做到这一点:
You can do that with the last version of Valgrind (3.8.1):
启动可执行文件,在启动时激活gdbserver:
Start your executable activating the gdbserver at startup:
valgrind --vgdb-error=0 ....<your program>
然后在另一个窗口中,将gdb连接到Valgrind(遵循指示) 由Valgrind提供). 然后在相关位置(例如main的末尾)放置一个断点 并使用gdb
Then in another window, connect a gdb to Valgrind (following the indications given by Valgrind). Then put a breakpoint at a relevant place (e.g. at the end of main) and use the gdb
continue
命令,直到到达断点. 然后从gdb进行泄漏搜索:
command till the breakpoint is reached. Then do a leak search from gdb:
monitor leak_check full reachable any
然后列出相关损失记录nr的可到达块的地址
Then list the address(es) of the reachable blocks of the relevant loss record nr
monitor block_list <loss_record_nr>
然后可以使用gdb功能检查给定地址的内存. 另请注意可能有趣的命令"who_points_at" 如果您要搜索谁保留了指向该内存的指针.
You can then use gdb features to examine the memory of the given address(es). Note also the potentially interesting command "who_points_at" if you are searching who has kept a pointer to this memory.
这篇关于Valgrind报告转储丢失的内存内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!