| OLD | NEW |
| (Empty) |
| 1 #!/bin/bash | |
| 2 | |
| 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 4 # 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: | |
| 10 # $ sh ./tools/valgrind/valgrind.sh ./out/Debug/chrome | |
| 11 # | |
| 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. | |
| 15 | |
| 16 export THISDIR=`dirname $0` | |
| 17 | |
| 18 setup_memcheck() { | |
| 19 RUN_COMMAND="valgrind" | |
| 20 | |
| 21 # Prompt to attach gdb when there was an error detected. | |
| 22 DEFAULT_TOOL_FLAGS=("--db-command=gdb -nw %f %p" "--db-attach=yes" \ | |
| 23 # Keep the registers in gdb in sync with the code. | |
| 24 "--vex-iropt-register-updates=allregs-at-mem-access" \ | |
| 25 # Overwrite newly allocated or freed objects | |
| 26 # with 0x41 to catch inproper use. | |
| 27 "--malloc-fill=41" "--free-fill=41" \ | |
| 28 # Increase the size of stacks being tracked. | |
| 29 "--num-callers=30") | |
| 30 } | |
| 31 | |
| 32 setup_unknown() { | |
| 33 echo "Unknown tool \"$TOOL_NAME\" specified, the result is not guaranteed" | |
| 34 DEFAULT_TOOL_FLAGS=() | |
| 35 } | |
| 36 | |
| 37 set -e | |
| 38 | |
| 39 if [ $# -eq 0 ]; then | |
| 40 echo "usage: <command to run> <arguments ...>" | |
| 41 exit 1 | |
| 42 fi | |
| 43 | |
| 44 TOOL_NAME="memcheck" | |
| 45 declare -a DEFAULT_TOOL_FLAGS[0] | |
| 46 | |
| 47 # Select a tool different from memcheck with --tool=TOOL as a first argument | |
| 48 TMP_STR=`echo $1 | sed 's/^\-\-tool=//'` | |
| 49 if [ "$TMP_STR" != "$1" ]; then | |
| 50 TOOL_NAME="$TMP_STR" | |
| 51 shift | |
| 52 fi | |
| 53 | |
| 54 if echo "$@" | grep "\-\-tool" ; then | |
| 55 echo "--tool=TOOL must be the first argument" >&2 | |
| 56 exit 1 | |
| 57 fi | |
| 58 | |
| 59 case $TOOL_NAME in | |
| 60 memcheck*) setup_memcheck "$1";; | |
| 61 *) setup_unknown;; | |
| 62 esac | |
| 63 | |
| 64 | |
| 65 SUPPRESSIONS="$THISDIR/$TOOL_NAME/suppressions.txt" | |
| 66 | |
| 67 CHROME_VALGRIND=`sh $THISDIR/locate_valgrind.sh` | |
| 68 if [ "$CHROME_VALGRIND" = "" ] | |
| 69 then | |
| 70 # locate_valgrind.sh failed | |
| 71 exit 1 | |
| 72 fi | |
| 73 echo "Using valgrind binaries from ${CHROME_VALGRIND}" | |
| 74 | |
| 75 set -x | |
| 76 PATH="${CHROME_VALGRIND}/bin:$PATH" | |
| 77 # We need to set these variables to override default lib paths hard-coded into | |
| 78 # Valgrind binary. | |
| 79 export VALGRIND_LIB="$CHROME_VALGRIND/lib/valgrind" | |
| 80 export VALGRIND_LIB_INNER="$CHROME_VALGRIND/lib/valgrind" | |
| 81 | |
| 82 # G_SLICE=always-malloc: make glib use system malloc | |
| 83 # NSS_DISABLE_UNLOAD=1: make nss skip dlclosing dynamically loaded modules, | |
| 84 # which would result in "obj:*" in backtraces. | |
| 85 # 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 # | |
| 90 # GTEST_DEATH_TEST_USE_FORK=1: make gtest death tests valgrind-friendly | |
| 91 # | |
| 92 # When everyone has the latest valgrind, we might want to add | |
| 93 # --show-possibly-lost=no | |
| 94 # to ignore possible but not definite leaks. | |
| 95 | |
| 96 G_SLICE=always-malloc \ | |
| 97 NSS_DISABLE_UNLOAD=1 \ | |
| 98 NSS_DISABLE_ARENA_FREE_LIST=1 \ | |
| 99 G_DEBUG=fatal_warnings \ | |
| 100 GTEST_DEATH_TEST_USE_FORK=1 \ | |
| 101 $RUN_COMMAND \ | |
| 102 --trace-children=yes \ | |
| 103 --leak-check=yes \ | |
| 104 --suppressions="$SUPPRESSIONS" \ | |
| 105 "${DEFAULT_TOOL_FLAGS[@]}" \ | |
| 106 "$@" | |
| OLD | NEW |