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 # Wireshark - Network traffic analyzer
9 # By Gerald Combs <gerald@wireshark.org>
10 # Copyright 1998 Gerald Combs
12 # SPDX-License-Identifier: GPL-2.0-or-later
14 # Directory containing tshark or wireshark. Default: cmake run directory.
15 if [ -z "$WIRESHARK_BIN_DIR" ]; then
19 # Use tshark by default
27 while getopts ":2a:b:C:lmnpP:rstTYwcevWdG" OPTCHAR
; do
29 2) COMMAND_ARGS
="-2 $COMMAND_ARGS" ;;
30 a
) ADDITIONAL_SUPPRESSION_FILE
="$ADDITIONAL_SUPPRESSION_FILE --suppressions=$OPTARG" ;;
31 b
) WIRESHARK_BIN_DIR
=$OPTARG ;;
32 C
) COMMAND_ARGS
="-C $OPTARG $COMMAND_ARGS" ;;
33 l
) LEAK_CHECK
="--leak-check=full" ;;
37 p
) TOOL
="callgrind" ;;
39 CALLGRIND_OUT_FILE
="--callgrind-out-file=$OPTARG" ;;
40 r
) REACHABLE
="--show-reachable=yes" ;;
41 s
) GEN_SUPPRESSIONS
="--gen-suppressions=yes" ;;
42 t
) TRACK_ORIGINS
="--track-origins=yes" ;;
43 T
) COMMAND_ARGS
="-Vx $COMMAND_ARGS" ;; # "build the Tree"
44 Y
) COMMAND_ARGS
="-Y frame $COMMAND_ARGS" ;; # Run with a read filter (but no tree)
50 COMMAND_ARGS
="-E 0.02"
51 # We don't care about the output of editcap
52 COMMAND_ARGS2
="/dev/null" ;;
53 v
) VERBOSE
="--num-callers=256 -v" ;;
58 COMMAND_ARGS
="-i eth1 -c 3000"
60 *) printf "Unknown option: %s\\n" "$OPTARG"
64 shift $
(( OPTIND
- 1 ))
67 if [ "$COMMAND" != "tshark" ] && [[ $COMMAND_ARGS =~ Vx
]]
69 printf "\\nYou can't use -T if you're not using tshark\\n\\n" >&2
81 printf "\\nUsage: %s [-2] [-a file] [-b bin_dir] [-c] [-e] [-C config_profile] " "$(basename "$0")"
82 printf "[-l] [-m] [-n] [-p] [-r] [-s] [-t] [-T] [-w] [-v] /path/to/file.pcap\\n"
84 printf "[-2]: run tshark with 2-pass analysis\\n"
85 printf "[-a]: additional valgrind suppression file\\n"
86 printf "[-b]: tshark binary dir\\n"
87 printf "[-e]: use 'editcap -E 0.02' instead of tshark\\n"
88 printf "[-c]: use capinfos instead of tshark\\n"
89 printf "[-C]: binary profile file\\n"
90 printf "[-l]: add valgrind option --leak-check=full\\n"
91 printf "[-m]: use valgrind massif tool\\n"
92 printf "[-n]: print binary version\\n"
93 printf "[-p]: use callgrind massif tool\\n"
94 printf "[-r]: add valgrind option --show-reachable=yes\\n"
95 printf "[-s]: add valgrind option --gen-suppressions=yes\\n"
96 printf "[-t]: add valgrind option --track-origins=yes\\n"
97 printf "[-T]: build the tshark tree (-Vx)\\n"
98 printf "[-w]: use wireshark instead of tshark\\n"
99 printf "[-v]: run in verbose mode (--num-callers=256)\\n"
103 if [ "$WIRESHARK_BIN_DIR" = "." ]; then
104 export WIRESHARK_RUN_FROM_BUILD_DIRECTORY
=
107 if [ "$TOOL" != "callgrind" ]; then
108 export WIRESHARK_DEBUG_WMEM_OVERRIDE
=simple
109 export G_SLICE
=always-malloc
# or debug-blocks
112 COMMAND
="$WIRESHARK_BIN_DIR/$COMMAND"
114 cmdline
="valgrind --suppressions=$( dirname "$0" )/vg-suppressions $ADDITIONAL_SUPPRESSION_FILE \
115 --tool=$TOOL $CALLGRIND_OUT_FILE $VERBOSE $LEAK_CHECK $REACHABLE $GEN_SUPPRESSIONS $TRACK_ORIGINS \
116 $COMMAND $COMMAND_ARGS $PCAP $COMMAND_ARGS2"
118 if [ "$VERBOSE" != "" ];then
119 echo -e "\\n$cmdline\\n"
122 # shellcheck disable=SC2086
123 exec $cmdline > /dev
/null