webrtc/tools_webrtc/valgrind/valgrind.sh
kjellander 0393de4b56 Roll chromium_revision b032878ebd..e438353b8b (480186:480311)
Copy Valgrind scripts from Chromium's tools/ to unblock rolling:
valgrind/chrome_tests.bat
valgrind/chrome_tests.py
valgrind/chrome_tests.sh
valgrind/common.py
valgrind/gdb_helper.py
valgrind/locate_valgrind.sh
valgrind/memcheck_analyze.py
valgrind/valgrind.gni
valgrind/valgrind.sh
valgrind/valgrind_test.py

valgrind_test.py was stripped of its Mac and Dr Memory specific parts, which
we don't use. There's still more cleanup to do, tracked in bugs.webrc.org/7849.

Change log: b032878ebd..e438353b8b
Full diff: b032878ebd..e438353b8b

Changed dependencies:
* src/base: cfcc86588b..12890c2e86
* src/build: da7ab41c0b..9ec24027ab
* src/ios: 6a7a3c369e..50158a755d
* src/testing: 3e351800c5..1f3a1393a1
* src/third_party: 541ca472e8..733d9dc5c9
* src/third_party/catapult: e9dc4c57fb..57e600c76c
* src/third_party/gtest-parallel: 6fb62e80ac..4bf9c03d93
* src/tools: bf99adb051..919bf71aa0
DEPS diff: b032878ebd..e438353b8b/DEPS

No update to Clang.

TBR=ehmaldonado@webrtc.org
BUG=webrtc:7849
NOTRY=True

Review-Url: https://codereview.webrtc.org/2945753002
Cr-Commit-Position: refs/heads/master@{#18650}
2017-06-18 20:21:21 +00:00

110 lines
3.5 KiB
Bash
Executable file

#!/bin/bash
# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
# This is a small script for manually launching valgrind, along with passing
# it the suppression file, and some helpful arguments (automatically attaching
# the debugger on failures, etc). Run it from your repo root, something like:
# $ sh ./tools/valgrind/valgrind.sh ./out/Debug/chrome
#
# This is mostly intended for running the chrome browser interactively.
# To run unit tests, you probably want to run chrome_tests.sh instead.
# That's the script used by the valgrind buildbot.
export THISDIR=`dirname $0`
setup_memcheck() {
RUN_COMMAND="valgrind"
# Prompt to attach gdb when there was an error detected.
DEFAULT_TOOL_FLAGS=("--db-command=gdb -nw %f %p" "--db-attach=yes" \
# Keep the registers in gdb in sync with the code.
"--vex-iropt-register-updates=allregs-at-mem-access" \
# Overwrite newly allocated or freed objects
# with 0x41 to catch inproper use.
"--malloc-fill=41" "--free-fill=41" \
# Increase the size of stacks being tracked.
"--num-callers=30")
}
setup_unknown() {
echo "Unknown tool \"$TOOL_NAME\" specified, the result is not guaranteed"
DEFAULT_TOOL_FLAGS=()
}
set -e
if [ $# -eq 0 ]; then
echo "usage: <command to run> <arguments ...>"
exit 1
fi
TOOL_NAME="memcheck"
declare -a DEFAULT_TOOL_FLAGS[0]
# Select a tool different from memcheck with --tool=TOOL as a first argument
TMP_STR=`echo $1 | sed 's/^\-\-tool=//'`
if [ "$TMP_STR" != "$1" ]; then
TOOL_NAME="$TMP_STR"
shift
fi
if echo "$@" | grep "\-\-tool" ; then
echo "--tool=TOOL must be the first argument" >&2
exit 1
fi
case $TOOL_NAME in
memcheck*) setup_memcheck "$1";;
*) setup_unknown;;
esac
SUPPRESSIONS="$THISDIR/$TOOL_NAME/suppressions.txt"
CHROME_VALGRIND=`sh $THISDIR/locate_valgrind.sh`
if [ "$CHROME_VALGRIND" = "" ]
then
# locate_valgrind.sh failed
exit 1
fi
echo "Using valgrind binaries from ${CHROME_VALGRIND}"
set -x
PATH="${CHROME_VALGRIND}/bin:$PATH"
# We need to set these variables to override default lib paths hard-coded into
# Valgrind binary.
export VALGRIND_LIB="$CHROME_VALGRIND/lib/valgrind"
export VALGRIND_LIB_INNER="$CHROME_VALGRIND/lib/valgrind"
# G_SLICE=always-malloc: make glib use system malloc
# NSS_DISABLE_UNLOAD=1: make nss skip dlclosing dynamically loaded modules,
# which would result in "obj:*" in backtraces.
# NSS_DISABLE_ARENA_FREE_LIST=1: make nss use system malloc
# G_DEBUG=fatal_warnings: make GTK abort on any critical or warning assertions.
# If it crashes on you in the Options menu, you hit bug 19751,
# comment out the G_DEBUG=fatal_warnings line.
#
# GTEST_DEATH_TEST_USE_FORK=1: make gtest death tests valgrind-friendly
#
# When everyone has the latest valgrind, we might want to add
# --show-possibly-lost=no
# to ignore possible but not definite leaks.
G_SLICE=always-malloc \
NSS_DISABLE_UNLOAD=1 \
NSS_DISABLE_ARENA_FREE_LIST=1 \
G_DEBUG=fatal_warnings \
GTEST_DEATH_TEST_USE_FORK=1 \
$RUN_COMMAND \
--trace-children=yes \
--leak-check=yes \
--suppressions="$SUPPRESSIONS" \
"${DEFAULT_TOOL_FLAGS[@]}" \
"$@"