Dumping contents of lost memory reported by Valgrind

倖福魔咒の 提交于 2019-12-03 13:15:30

问题


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)?


回答1:


You can do that with the last version of Valgrind (3.8.1):

Start your executable activating the gdbserver at startup:

valgrind --vgdb-error=0 ....<your program>

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

command till the breakpoint is reached. Then do a leak search from gdb:

   monitor leak_check full reachable any

Then list the address(es) of the reachable blocks of the relevant loss record nr

   monitor block_list <loss_record_nr>

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.



来源:https://stackoverflow.com/questions/12663283/dumping-contents-of-lost-memory-reported-by-valgrind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!