Valgrind

Description

Valgrind is an instrumentation framework for building dynamic analysis tools. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.

Usage

Syntax

valgrind [options] prog-and-args

Options

    --help-debug              show this message, plus debugging options
    --version                 show version
    -q --quiet                run silently; only print error msgs
    -v --verbose              be more verbose -- show misc extra info
    --trace-children=no|yes   Valgrind-ise child processes (follow execve)? [no]
    --trace-children-skip=patt1,patt2,...    specifies a list of executables
                              that --trace-children=yes should not trace into
    --trace-children-skip-by-arg=patt1,patt2,...   same as --trace-children-skip=
                              but check the argv[] entries for children, rather
                              than the exe name, to make a follow/no-follow decision
    --child-silent-after-fork=no|yes omit child output between fork & exec? [no]
    --vgdb=no|yes|full        activate gdbserver? [yes]
                              full is slower but provides precise watchpoint/step
    --vgdb-error=<number>     invoke gdbserver after <number> errors [999999999]
                              to get started quickly, use --vgdb-error=0
                              and follow the on-screen directions
    --track-fds=no|yes        track open file descriptors? [no]
    --time-stamp=no|yes       add timestamps to log messages? [no]
    --log-fd=<number>         log messages to file descriptor [2=stderr]
    --log-file=<file>         log messages to <file>
    --log-socket=ipaddr:port  log messages to socket ipaddr:port

Example

cyborg@cyborg:~$ valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-caller=20 --trace-fds=yes ./test
valgrind: Bad option: --num-caller=20
valgrind: Use --help for more information or consult the user manual.
cyborg@cyborg:~/Downloads$ valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --trace-fds=yes ./test
valgrind: Bad option: --trace-fds=yes
valgrind: Use --help for more information or consult the user manual.
cyborg@cyborg:~/Downloads$ valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./test
==4926== Memcheck, a memory error detector
==4926== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==4926== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==4926== Command: ./test
==4926== 
==4926== 
==4926== FILE DESCRIPTORS: 3 open at exit.
==4926== Open file descriptor 2: /dev/pts/0
==4926==    <inherited from parent>
==4926== 
==4926== Open file descriptor 1: /dev/pts/0
==4926==    <inherited from parent>
==4926== 
==4926== Open file descriptor 0: /dev/pts/0
==4926==    <inherited from parent>
==4926== 
==4926== 
==4926== HEAP SUMMARY:
==4926==     in use at exit: 35 bytes in 2 blocks
==4926==   total heap usage: 3 allocs, 1 frees, 47 bytes allocated
==4926== 
==4926== 16 bytes in 1 blocks are definitely lost in loss record 1 of 2
==4926==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4926==    by 0x4005B6: main (test.c:15)
==4926== 
==4926== 19 bytes in 1 blocks are definitely lost in loss record 2 of 2
==4926==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4926==    by 0x40058E: main (test.c:8)
==4926== 
==4926== LEAK SUMMARY:
==4926==    definitely lost: 35 bytes in 2 blocks
==4926==    indirectly lost: 0 bytes in 0 blocks
==4926==      possibly lost: 0 bytes in 0 blocks
==4926==    still reachable: 0 bytes in 0 blocks
==4926==         suppressed: 0 bytes in 0 blocks
==4926== 
==4926== For counts of detected and suppressed errors, rerun with: -v
==4926== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)

0 Comments

Leave a reply

CONTACT US

We're are building as a community and a team. Be a part of it.

Sending

©2017 Ztrela Knowledge Solutions Pvt. Ltd

Log in with your credentials

Forgot your details?