FIXUP: give names to sec_vt_command's
[wireshark-wip.git] / tools / valgrind-wireshark.sh
blobc2696db70c5a981ef72b1f0f33567534ba401a68
1 #!/bin/bash
3 # A small script to export some variables and run tshark or wireshark in
4 # valgrind on a given capture file.
6 # Copyright 2012 Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
8 # $Id$
10 # Wireshark - Network traffic analyzer
11 # By Gerald Combs <gerald@wireshark.org>
12 # Copyright 1998 Gerald Combs
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 # Directory containing tshark or wireshark. Default current directory.
29 BIN_DIR=.
31 # Use tshark by default
32 COMMAND=tshark
33 COMMAND_ARGS="-nr"
34 COMMAND_ARGS2=
35 VALID=0
36 PCAP=""
37 TOOL="memcheck"
39 while getopts ":2b:C:lmnpP:rtTYwcevW" OPTCHAR ; do
40 case $OPTCHAR in
41 2) COMMAND_ARGS="-2 $COMMAND_ARGS" ;;
42 b) BIN_DIR=$OPTARG ;;
43 C) COMMAND_ARGS="-C $OPTARG $COMMAND_ARGS" ;;
44 l) LEAK_CHECK="--leak-check=full" ;;
45 m) TOOL="massif" ;;
46 n) COMMAND_ARGS="-v"
47 VALID=1 ;;
48 p) TOOL="callgrind" ;;
49 P) TOOL="callgrind"
50 CALLGRIND_OUT_FILE="--callgrind-out-file=$OPTARG" ;;
51 r) REACHABLE="--show-reachable=yes" ;;
52 t) TRACK_ORIGINS="--track-origins=yes" ;;
53 T) COMMAND_ARGS="-Vx $COMMAND_ARGS" ;; # "build the Tree"
54 Y) COMMAND_ARGS="-Yframe $COMMAND_ARGS" ;; # Run with a read filter (but no tree)
55 w) COMMAND=wireshark
56 COMMAND_ARGS="-nr" ;;
57 c) COMMAND=capinfos
58 COMMAND_ARGS="" ;;
59 e) COMMAND=editcap
60 COMMAND_ARGS="-E 0.02"
61 # We don't care about the output of editcap
62 COMMAND_ARGS2="/dev/null" ;;
63 v) VERBOSE="--num-callers=256" ;;
64 W) COMMAND=wireshark
65 COMMAND_ARGS=""
66 VALID=1 ;;
67 *) printf "Unknown option -$OPTARG!\n"
68 exit ;;
69 esac
70 done
71 shift $(($OPTIND - 1))
73 if [ $# -ge 1 ]
74 then
75 PCAP=$1
76 VALID=1
79 if [ $VALID -eq 0 ]
80 then
81 printf "Usage: $0 [-2] [-b bin_dir] [-c] [-e] [-C config_profile] [-l] [-m] [-n] [-p] [-r] [-t] [-T] [-w] [-v] /path/to/file.pcap\n"
82 exit 1
85 if [ "$BIN_DIR" = "." ]; then
86 export WIRESHARK_RUN_FROM_BUILD_DIRECTORY=
89 if [ "$TOOL" != "callgrind" ]; then
90 export WIRESHARK_DEBUG_EP_NO_CHUNKS=
91 export WIRESHARK_DEBUG_SE_NO_CHUNKS=
92 export WIRESHARK_DEBUG_WMEM_OVERRIDE=simple
93 export G_SLICE=always-malloc # or debug-blocks
96 COMMAND="$BIN_DIR/$COMMAND"
98 if file $COMMAND | grep -q "ASCII text"; then
99 if [ -x "`dirname $0`/../libtool" ]; then
100 LIBTOOL="`dirname $0`/../libtool"
101 else
102 LIBTOOL="libtool"
104 LIBTOOL="$LIBTOOL --mode=execute"
105 else
106 LIBTOOL=""
109 $LIBTOOL valgrind --suppressions=`dirname $0`/vg-suppressions --tool=$TOOL $CALLGRIND_OUT_FILE $VERBOSE $LEAK_CHECK $REACHABLE $TRACK_ORIGINS $COMMAND $COMMAND_ARGS $PCAP $COMMAND_ARGS2 > /dev/null