Memcheck: a memory error detector
(gdb) monitor who_points_at 0x4028028
==20852== Searching for pointers to 0x4028028
==20852== *0x8049e20 points at 0x4028028
==20852==
Location 0x8049e20 is 0 bytes inside global var "t"
==20852==
declared at leak-tree.c:35
(gdb) monitor who_points_at 0x40281A8 16
==20852== Searching for pointers pointing in 16 bytes from 0x40281a8
==20852== *0x40280ac points at 0x40281a8
==20852==
Address 0x40280ac is 4 bytes inside a block of size 16 alloc’d
==20852==
at 0x40070B4: malloc (vg_replace_malloc.c:263)
==20852==
by 0x80484D5: mk (leak-tree.c:28)
==20852==
by 0x8048519: f (leak-tree.c:43)
==20852==
by 0x8048856: main (leak-tree.c:63)
==20852== tid 1 register ECX points at 0x40281a8
==20852== tid 1 register EBX interior points at 2 bytes inside 0x40281a8
(gdb)
4.7. Client Requests
The following client requests are defined in
memcheck.h
. See
memcheck.h
for exact details of their arguments.
•
VALGRIND_MAKE_MEM_NOACCESS
,
VALGRIND_MAKE_MEM_UNDEFINED
and
VALGRIND_MAKE_MEM_DEFINED
.
These mark address ranges as completely inaccessible, accessible but containing undefined data, and accessible
and containing defined data, respectively.
•
VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE
. This is just like
VALGRIND_MAKE_MEM_DEFINED
but only affects those bytes that are already addressable.
•
VALGRIND_CHECK_MEM_IS_ADDRESSABLE
and
VALGRIND_CHECK_MEM_IS_DEFINED
: check immedi-
ately whether or not the given address range has the relevant property, and if not, print an error message. Also, for
the convenience of the client, returns zero if the relevant property holds; otherwise, the returned value is the address
of the first byte for which the property is not true. Always returns 0 when not run on Valgrind.
•
VALGRIND_CHECK_VALUE_IS_DEFINED
: a quick and easy way to find out whether Valgrind thinks a particular
value (lvalue, to be precise) is addressable and defined. Prints an error message if not. It has no return value.
•
VALGRIND_DO_LEAK_CHECK
: does a full memory leak check (like
--leak-check=full
) right now. This is
useful for incrementally checking for leaks between arbitrary places in the program’s execution. It has no return
value.
•
VALGRIND_DO_ADDED_LEAK_CHECK
: same as
VALGRIND_DO_LEAK_CHECK
but only shows the entries
for which there was an increase in leaked bytes or leaked number of blocks since the previous leak search. It has
no return value.
•
VALGRIND_DO_CHANGED_LEAK_CHECK
: same as
VALGRIND_DO_LEAK_CHECK
but only shows the entries
for which there was an increase or decrease in leaked bytes or leaked number of blocks since the previous leak
search. It has no return value.
•
VALGRIND_DO_QUICK_LEAK_CHECK
: like
VALGRIND_DO_LEAK_CHECK
, except it produces only a leak
summary (like
--leak-check=summary
). It has no return value.
68