Reset contents of lost memory reported by Valgrind

When I run valgrind --leak-check=yes in the program, several bytes of lost memory are reported. Is it possible to view the contents of this memory (i.e., flush the data stored in it)?

+6
source share
1 answer

You can do this with the latest version of Valgrind (3.8.1):

Run the executable by activating gdbserver at startup:

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

Then in another window, connect gdb to Valgrind (following the instructions given by Valgrind). Then set a breakpoint in the appropriate place (for example, at the end of the main one) and use gdb

 continue 

before reaching the breakpoint. Then do a leak search from gdb:

  monitor leak_check full reachable any 

Then list the addresses of the reachable blocks of the corresponding loss record nr

  monitor block_list <loss_record_nr> 

Then you can use the gdb functions to check the memory with the specified addresses. Pay attention also to the potentially interesting command "who_points_at" if you are looking for who saved a pointer to this memory.

+8
source

Source: https://habr.com/ru/post/926621/


All Articles