Using and understanding the Valgrind core: Advanced Topics
An example of a tool specific monitor command is the Memcheck monitor command
leak_check full
reachable any
. This requests a full reporting of the allocated memory blocks. To have this leak check executed,
use the GDB command:
(gdb) monitor leak_check full reachable any
GDB will send the
leak_check
command to the Valgrind gdbserver.
The Valgrind gdbserver will execute the
monitor command itself, if it recognises it to be a Valgrind core monitor command. If it is not recognised as such, it
is assumed to be tool-specific and is handed to the tool for execution. For example:
(gdb) monitor leak_check full reachable any
==2418== 100 bytes in 1 blocks are still reachable in loss record 1 of 1
==2418==
at 0x4006E9E: malloc (vg_replace_malloc.c:236)
==2418==
by 0x804884F: main (prog.c:88)
==2418==
==2418== LEAK SUMMARY:
==2418==
definitely lost: 0 bytes in 0 blocks
==2418==
indirectly lost: 0 bytes in 0 blocks
==2418==
possibly lost: 0 bytes in 0 blocks
==2418==
still reachable: 100 bytes in 1 blocks
==2418==
suppressed: 0 bytes in 0 blocks
==2418==
(gdb)
As with other GDB commands, the Valgrind gdbserver will accept abbreviated monitor command names and
arguments, as long as the given abbreviation is unambiguous.
For example, the above
leak_check
command
can also be typed as:
(gdb) mo l f r a
The letters
mo
are recognised by GDB as being an abbreviation for
monitor
. So GDB sends the string
l f r a
to
the Valgrind gdbserver. The letters provided in this string are unambiguous for the Valgrind gdbserver. This therefore
gives the same output as the unabbreviated command and arguments. If the provided abbreviation is ambiguous, the
Valgrind gdbserver will report the list of commands (or argument values) that can match:
(gdb) mo v. n
v. can match v.set v.info v.wait v.kill v.translate
(gdb) mo v.i n
n_errs_found 0 n_errs_shown 0 (vgdb-error 0)
(gdb)
Instead of sending a monitor command from GDB, you can also send these from a shell command line. For example,
the following command lines, when given in a shell, will cause the same leak search to be executed by the process
3145:
36