2011-10-27 02:32:32 +00:00
|
|
|
#!/bin/bash
|
2012-05-01 18:59:12 +00:00
|
|
|
|
|
|
|
# A small script to export some variables and run tshark or wireshark in
|
|
|
|
# valgrind on a given capture file.
|
|
|
|
#
|
|
|
|
# Copyright 2012 Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
|
2011-10-27 02:32:32 +00:00
|
|
|
#
|
2012-05-01 18:59:12 +00:00
|
|
|
# Wireshark - Network traffic analyzer
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
|
|
|
# Copyright 1998 Gerald Combs
|
|
|
|
#
|
2018-03-06 14:31:02 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2011-10-27 02:32:32 +00:00
|
|
|
|
2019-01-08 20:24:11 +00:00
|
|
|
# Directory containing tshark or wireshark. Default: cmake run directory.
|
2015-06-26 06:48:48 +00:00
|
|
|
if [ -z "$WIRESHARK_BIN_DIR" ]; then
|
2019-01-08 20:24:11 +00:00
|
|
|
WIRESHARK_BIN_DIR=run
|
2015-06-26 06:48:48 +00:00
|
|
|
fi
|
2011-10-27 02:32:32 +00:00
|
|
|
|
|
|
|
# Use tshark by default
|
|
|
|
COMMAND=tshark
|
2012-12-02 02:58:29 +00:00
|
|
|
COMMAND_ARGS="-nr"
|
2012-03-16 14:12:01 +00:00
|
|
|
COMMAND_ARGS2=
|
2012-11-09 02:10:48 +00:00
|
|
|
VALID=0
|
|
|
|
PCAP=""
|
2013-09-12 13:45:04 +00:00
|
|
|
TOOL="memcheck"
|
2011-10-27 02:32:32 +00:00
|
|
|
|
2016-02-07 14:01:28 +00:00
|
|
|
while getopts ":2a:b:C:lmnpP:rstTYwcevWdG" OPTCHAR ; do
|
2011-10-27 02:32:32 +00:00
|
|
|
case $OPTCHAR in
|
2012-07-26 02:38:34 +00:00
|
|
|
2) COMMAND_ARGS="-2 $COMMAND_ARGS" ;;
|
2017-01-20 22:27:17 +00:00
|
|
|
a) ADDITIONAL_SUPPRESSION_FILE="$ADDITIONAL_SUPPRESSION_FILE --suppressions=$OPTARG" ;;
|
2015-06-26 06:48:48 +00:00
|
|
|
b) WIRESHARK_BIN_DIR=$OPTARG ;;
|
2012-07-26 02:38:34 +00:00
|
|
|
C) COMMAND_ARGS="-C $OPTARG $COMMAND_ARGS" ;;
|
2011-10-27 02:32:32 +00:00
|
|
|
l) LEAK_CHECK="--leak-check=full" ;;
|
2013-09-12 13:45:04 +00:00
|
|
|
m) TOOL="massif" ;;
|
2012-11-09 02:10:48 +00:00
|
|
|
n) COMMAND_ARGS="-v"
|
|
|
|
VALID=1 ;;
|
2013-09-12 13:45:04 +00:00
|
|
|
p) TOOL="callgrind" ;;
|
2013-11-11 18:44:50 +00:00
|
|
|
P) TOOL="callgrind"
|
|
|
|
CALLGRIND_OUT_FILE="--callgrind-out-file=$OPTARG" ;;
|
2012-12-01 20:51:20 +00:00
|
|
|
r) REACHABLE="--show-reachable=yes" ;;
|
2016-02-07 14:01:28 +00:00
|
|
|
s) GEN_SUPPRESSIONS="--gen-suppressions=yes" ;;
|
2012-04-30 13:20:27 +00:00
|
|
|
t) TRACK_ORIGINS="--track-origins=yes" ;;
|
2012-12-04 00:05:58 +00:00
|
|
|
T) COMMAND_ARGS="-Vx $COMMAND_ARGS" ;; # "build the Tree"
|
2014-05-08 19:25:13 +00:00
|
|
|
Y) COMMAND_ARGS="-Y frame $COMMAND_ARGS" ;; # Run with a read filter (but no tree)
|
2012-07-26 02:38:34 +00:00
|
|
|
w) COMMAND=wireshark
|
|
|
|
COMMAND_ARGS="-nr" ;;
|
|
|
|
c) COMMAND=capinfos
|
|
|
|
COMMAND_ARGS="" ;;
|
|
|
|
e) COMMAND=editcap
|
|
|
|
COMMAND_ARGS="-E 0.02"
|
|
|
|
# We don't care about the output of editcap
|
|
|
|
COMMAND_ARGS2="/dev/null" ;;
|
2017-02-20 15:35:32 +00:00
|
|
|
v) VERBOSE="--num-callers=256 -v" ;;
|
2013-03-15 16:42:05 +00:00
|
|
|
W) COMMAND=wireshark
|
|
|
|
COMMAND_ARGS=""
|
|
|
|
VALID=1 ;;
|
2014-05-08 19:25:13 +00:00
|
|
|
d) COMMAND=dumpcap
|
2014-05-09 12:11:05 +00:00
|
|
|
COMMAND_ARGS="-i eth1 -c 3000"
|
2014-05-08 19:25:13 +00:00
|
|
|
VALID=1 ;;
|
2018-06-06 17:10:07 +00:00
|
|
|
*) printf "Unknown option: %s\\n" "$OPTARG"
|
2012-12-02 02:58:29 +00:00
|
|
|
exit ;;
|
2011-10-27 02:32:32 +00:00
|
|
|
esac
|
|
|
|
done
|
2018-06-06 17:10:07 +00:00
|
|
|
shift $(( OPTIND - 1 ))
|
2011-10-27 02:32:32 +00:00
|
|
|
|
2017-02-20 15:35:32 +00:00
|
|
|
# Sanitize parameters
|
|
|
|
if [ "$COMMAND" != "tshark" ] && [[ $COMMAND_ARGS =~ Vx ]]
|
|
|
|
then
|
2018-06-06 17:10:07 +00:00
|
|
|
printf "\\nYou can't use -T if you're not using tshark\\n\\n" >&2
|
2017-02-20 15:35:32 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-11-09 02:10:48 +00:00
|
|
|
if [ $# -ge 1 ]
|
2011-10-27 02:32:32 +00:00
|
|
|
then
|
2012-11-09 02:10:48 +00:00
|
|
|
PCAP=$1
|
|
|
|
VALID=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $VALID -eq 0 ]
|
|
|
|
then
|
2018-06-06 17:10:07 +00:00
|
|
|
printf "\\nUsage: %s [-2] [-a file] [-b bin_dir] [-c] [-e] [-C config_profile] " "$(basename "$0")"
|
|
|
|
printf "[-l] [-m] [-n] [-p] [-r] [-s] [-t] [-T] [-w] [-v] /path/to/file.pcap\\n"
|
|
|
|
printf "\\n"
|
|
|
|
printf "[-2]: run tshark with 2-pass analysis\\n"
|
|
|
|
printf "[-a]: additional valgrind suppression file\\n"
|
|
|
|
printf "[-b]: tshark binary dir\\n"
|
|
|
|
printf "[-e]: use 'editcap -E 0.02' instead of tshark\\n"
|
|
|
|
printf "[-c]: use capinfos instead of tshark\\n"
|
|
|
|
printf "[-C]: binary profile file\\n"
|
|
|
|
printf "[-l]: add valgrind option --leak-check=full\\n"
|
|
|
|
printf "[-m]: use valgrind massif tool\\n"
|
|
|
|
printf "[-n]: print binary version\\n"
|
|
|
|
printf "[-p]: use callgrind massif tool\\n"
|
|
|
|
printf "[-r]: add valgrind option --show-reachable=yes\\n"
|
|
|
|
printf "[-s]: add valgrind option --gen-suppressions=yes\\n"
|
|
|
|
printf "[-t]: add valgrind option --track-origins=yes\\n"
|
|
|
|
printf "[-T]: build the tshark tree (-Vx)\\n"
|
|
|
|
printf "[-w]: use wireshark instead of tshark\\n"
|
|
|
|
printf "[-v]: run in verbose mode (--num-callers=256)\\n"
|
2012-07-26 02:38:34 +00:00
|
|
|
exit 1
|
2011-10-27 02:32:32 +00:00
|
|
|
fi
|
|
|
|
|
2015-06-26 06:48:48 +00:00
|
|
|
if [ "$WIRESHARK_BIN_DIR" = "." ]; then
|
2011-10-27 02:32:32 +00:00
|
|
|
export WIRESHARK_RUN_FROM_BUILD_DIRECTORY=
|
|
|
|
fi
|
|
|
|
|
2013-09-12 13:45:04 +00:00
|
|
|
if [ "$TOOL" != "callgrind" ]; then
|
|
|
|
export WIRESHARK_DEBUG_WMEM_OVERRIDE=simple
|
|
|
|
export G_SLICE=always-malloc # or debug-blocks
|
|
|
|
fi
|
2011-10-27 02:32:32 +00:00
|
|
|
|
2015-06-26 06:48:48 +00:00
|
|
|
COMMAND="$WIRESHARK_BIN_DIR/$COMMAND"
|
2013-08-16 01:52:51 +00:00
|
|
|
|
2018-06-06 17:10:07 +00:00
|
|
|
cmdline="valgrind --suppressions=$( dirname "$0" )/vg-suppressions $ADDITIONAL_SUPPRESSION_FILE \
|
2016-02-07 14:01:28 +00:00
|
|
|
--tool=$TOOL $CALLGRIND_OUT_FILE $VERBOSE $LEAK_CHECK $REACHABLE $GEN_SUPPRESSIONS $TRACK_ORIGINS \
|
2020-10-19 10:14:23 +00:00
|
|
|
$COMMAND $COMMAND_ARGS $PCAP $COMMAND_ARGS2"
|
2016-02-07 14:01:28 +00:00
|
|
|
|
2017-02-20 15:35:32 +00:00
|
|
|
if [ "$VERBOSE" != "" ];then
|
2018-06-06 17:10:07 +00:00
|
|
|
echo -e "\\n$cmdline\\n"
|
2016-02-07 14:01:28 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-06 17:10:07 +00:00
|
|
|
# shellcheck disable=SC2086
|
Add valgrind support to randpkt-test.sh.
There's already valgrind support in fuzz-test.sh; This change simply clones the
relevant fragments of script into randpkt-test.sh, making very minor tweaks as
needed. Valgrind support in randpkt-test.sh is enabled through the "-g"
command-line option, just like with fuzz-test.sh.
In my testing here, it seems MAX_LEAK could be reduced somewhat, but I don't
think that that belongs as part of this change; I've simply kept the MAX_LEAK
value from fuzz-test.sh.
While we're here, the last line of valgrind-wireshark.sh launches a subprocess,
and that shell then simply returns its exit code, so there is no need for the
shell to stick around. So, let's use "exec" here to replace the shell with the
new process.
Testing Done: On Linux amd64, ran several iterations of randpkt-test.sh and
fuzz-test.sh, both with and without the "-g" option.
Change-Id: I87cc63559dc2e66c42c905f46657ce40cabf0104
Reviewed-on: https://code.wireshark.org/review/27741
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-05-23 08:53:59 +00:00
|
|
|
exec $cmdline > /dev/null
|