blob: 59b4071941960a2e2e906e07b22afaa69ff78c84 [file] [log] [blame]
[email protected]eb498422009-09-22 02:00:471#!/bin/bash
[email protected]e46cdae2009-08-25 20:59:272
[email protected]21d90b82012-03-15 10:34:383# Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]51721db2009-03-12 17:28:524# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7# This is a small script for manually launching valgrind, along with passing
8# it the suppression file, and some helpful arguments (automatically attaching
9# the debugger on failures, etc). Run it from your repo root, something like:
[email protected]016498e2010-12-03 00:59:2310# $ sh ./tools/valgrind/valgrind.sh ./out/Debug/chrome
[email protected]c72f16a2009-03-19 16:02:3111#
12# This is mostly intended for running the chrome browser interactively.
13# To run unit tests, you probably want to run chrome_tests.sh instead.
14# That's the script used by the valgrind buildbot.
[email protected]51721db2009-03-12 17:28:5215
[email protected]a0570412010-01-26 22:40:0616export THISDIR=`dirname $0`
17
[email protected]68e3b4722009-07-16 15:55:5218setup_memcheck() {
[email protected]791513392010-03-19 17:49:0219 RUN_COMMAND="valgrind"
[email protected]68e3b4722009-07-16 15:55:5220
21 # Prompt to attach gdb when there was an error detected.
[email protected]3a70be92014-07-22 02:39:2822 DEFAULT_TOOL_FLAGS=("--db-command=gdb -nw %f %p" "--db-attach=yes" \
[email protected]21d90b82012-03-15 10:34:3823 # Keep the registers in gdb in sync with the code.
[email protected]c1f8ef72013-07-05 07:04:2324 "--vex-iropt-register-updates=allregs-at-mem-access" \
[email protected]68e3b4722009-07-16 15:55:5225 # Overwrite newly allocated or freed objects
26 # with 0x41 to catch inproper use.
[email protected]cc7b9cc2011-05-06 08:35:0627 "--malloc-fill=41" "--free-fill=41" \
28 # Increase the size of stacks being tracked.
29 "--num-callers=30")
[email protected]68e3b4722009-07-16 15:55:5230}
31
[email protected]68e3b4722009-07-16 15:55:5232setup_unknown() {
33 echo "Unknown tool \"$TOOL_NAME\" specified, the result is not guaranteed"
34 DEFAULT_TOOL_FLAGS=()
35}
36
[email protected]51721db2009-03-12 17:28:5237set -e
38
39if [ $# -eq 0 ]; then
40 echo "usage: <command to run> <arguments ...>"
41 exit 1
42fi
43
[email protected]68e3b4722009-07-16 15:55:5244TOOL_NAME="memcheck"
45declare -a DEFAULT_TOOL_FLAGS[0]
46
47# Select a tool different from memcheck with --tool=TOOL as a first argument
48TMP_STR=`echo $1 | sed 's/^\-\-tool=//'`
49if [ "$TMP_STR" != "$1" ]; then
50 TOOL_NAME="$TMP_STR"
51 shift
[email protected]51721db2009-03-12 17:28:5252fi
53
[email protected]68e3b4722009-07-16 15:55:5254if echo "$@" | grep "\-\-tool" ; then
55 echo "--tool=TOOL must be the first argument" >&2
56 exit 1
57fi
58
59case $TOOL_NAME in
[email protected]fe215da2013-03-05 19:39:3860 memcheck*) setup_memcheck "$1";;
[email protected]68e3b4722009-07-16 15:55:5261 *) setup_unknown;;
62esac
63
[email protected]3f579582009-08-19 21:55:1164
[email protected]a0570412010-01-26 22:40:0665SUPPRESSIONS="$THISDIR/$TOOL_NAME/suppressions.txt"
[email protected]51721db2009-03-12 17:28:5266
[email protected]a0570412010-01-26 22:40:0667CHROME_VALGRIND=`sh $THISDIR/locate_valgrind.sh`
68if [ "$CHROME_VALGRIND" = "" ]
[email protected]3f579582009-08-19 21:55:1169then
[email protected]a0570412010-01-26 22:40:0670 # locate_valgrind.sh failed
71 exit 1
[email protected]3f579582009-08-19 21:55:1172fi
[email protected]a0570412010-01-26 22:40:0673echo "Using valgrind binaries from ${CHROME_VALGRIND}"
[email protected]51721db2009-03-12 17:28:5274
[email protected]68e3b4722009-07-16 15:55:5275set -x
[email protected]a0570412010-01-26 22:40:0676PATH="${CHROME_VALGRIND}/bin:$PATH"
77# We need to set these variables to override default lib paths hard-coded into
78# Valgrind binary.
79export VALGRIND_LIB="$CHROME_VALGRIND/lib/valgrind"
80export VALGRIND_LIB_INNER="$CHROME_VALGRIND/lib/valgrind"
[email protected]51721db2009-03-12 17:28:5281
[email protected]3f579582009-08-19 21:55:1182# G_SLICE=always-malloc: make glib use system malloc
[email protected]342508e2011-06-08 21:30:1183# NSS_DISABLE_UNLOAD=1: make nss skip dlclosing dynamically loaded modules,
84# which would result in "obj:*" in backtraces.
[email protected]3f579582009-08-19 21:55:1185# NSS_DISABLE_ARENA_FREE_LIST=1: make nss use system malloc
86# G_DEBUG=fatal_warnings: make GTK abort on any critical or warning assertions.
87# If it crashes on you in the Options menu, you hit bug 19751,
88# comment out the G_DEBUG=fatal_warnings line.
89#
[email protected]6aba9272009-10-26 14:06:2890# GTEST_DEATH_TEST_USE_FORK=1: make gtest death tests valgrind-friendly
[email protected]3f579582009-08-19 21:55:1191#
92# When everyone has the latest valgrind, we might want to add
[email protected]504088c2010-11-03 09:02:3093# --show-possibly-lost=no
[email protected]3f579582009-08-19 21:55:1194# to ignore possible but not definite leaks.
[email protected]68e3b4722009-07-16 15:55:5295
[email protected]51721db2009-03-12 17:28:5296G_SLICE=always-malloc \
[email protected]342508e2011-06-08 21:30:1197NSS_DISABLE_UNLOAD=1 \
[email protected]c72f16a2009-03-19 16:02:3198NSS_DISABLE_ARENA_FREE_LIST=1 \
[email protected]48190b32009-03-18 19:23:0499G_DEBUG=fatal_warnings \
[email protected]6aba9272009-10-26 14:06:28100GTEST_DEATH_TEST_USE_FORK=1 \
[email protected]791513392010-03-19 17:49:02101$RUN_COMMAND \
[email protected]51721db2009-03-12 17:28:52102 --trace-children=yes \
[email protected]c1f8ef72013-07-05 07:04:23103 --leak-check=yes \
[email protected]51721db2009-03-12 17:28:52104 --suppressions="$SUPPRESSIONS" \
[email protected]68e3b4722009-07-16 15:55:52105 "${DEFAULT_TOOL_FLAGS[@]}" \
[email protected]51721db2009-03-12 17:28:52106 "$@"