|
From: ajit g. <pea...@ya...> - 2010-05-12 18:37:06
|
Hi,
I have a small project with few C,C++ files in it.I want to chk if the whole project has a memleak or not.Can I do this using valgrind.If yes How and where can i find more info on this.
Please help.
Thanks
|
|
From: Oliver S. <ol...@f-...> - 2010-05-12 19:25:08
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Hi there,
yes you can do it with Valgrind. All you need to do is to skim over the
first few pages of the manual. Since memcheck is the default tool, not
much prior knowledge is needed ...
Frankly I source two different functions in my bash profile which are:
function vgdbg
{
local COMMAND="$1"
[[ -n "$COMMAND" ]] || { echo "Syntax: vgrun <command>"; return; }
valgrind \
--leak-check=full --error-limit=no --track-origins=yes \
--undef-value-errors=yes --read-var-info=yes --db-attach=yes \
$COMMAND
}
which will simply run the command that you give as the first parameter
under Valgrind and ask for the debugger (GDB by default) to be attached
when it finds an issue. However, since you seem to be *only* after
memory leaks (Valgrind has many more nice functions than leak checking,
though), this one may be more suitable:
function vgrun
{
local COMMAND="$1"
local NAME="$2"
[[ -n "$COMMAND" ]] || { echo "Syntax: vgrun <command> <name>"; return; }
[[ -n "$NAME" ]] || { echo "Syntax vgrun <command> <name>"; return; }
valgrind \
--leak-check=full --error-limit=no --track-origins=yes \
--undef-value-errors=yes --log-file=valgrind-${NAME}.log \
--read-var-info=yes --trace-children=no|yes \
$COMMAND | tee valgrind-${NAME}-output.log 2>&1
}
it takes two parameters, the first one being again the command to run
under Valgrind and the second being an arbitrary name (which is used for
the log file names. Due to the use of tee it will output the whole thing
to the console as well as into the file.
I've gotten some in-house users to use these "macros" even though they'd
never even touch Valgrind or other tools targeted at developers otherwise.
Hope this helps a bit to get you kick-started,
// Oliver
On 2010-05-12 18:36, ajit gunge wrote:
> Hi,
> I have a small project with few C,C++ files in it.I want to chk if the whole project has a memleak or not.Can I do this using valgrind.If yes How and where can i find more info on this.
> Please help.
>
> Thanks
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
iQEcBAEBCAAGBQJL6wCKAAoJEJm+Ui/QYLFPoW0H/14BtEzqZESwyavaJRcRnB+r
iDHvJ7LDhu8SAcrkcn2SPZx0lL9bVJlKY7lIqMkKby8e3H8jpTfnCkf762F6ORkh
p9gzfFiIi1Mhk1AdEgINWZVJhMArj0mKMXc+19orgHOO6yt6nzaw6cTNgq4X2OgX
sFH98XTsC1r/Pq7o8gzeMWCy5nekuLLaS4f0BgXLM0t1iZZsEqEHz6f2MLpePkOH
a/XmrzB60XmjPIldz/oXZV2o1UJJV5nMRJNVar+HrZFsxZJ6hBqryP6JqPA1ZWnT
O0vYqogqaaKHK7P5Tq8zP1WHO/1RfayPUpHfy6o40DMVKBWHB+qy6uftFO2t4cA=
=z5Ca
-----END PGP SIGNATURE-----
|