[email protected] | eb49842 | 2009-09-22 02:00:47 | [diff] [blame] | 1 | #!/bin/bash |
[email protected] | e46cdae | 2009-08-25 20:59:27 | [diff] [blame] | 2 | |
[email protected] | 21d90b8 | 2012-03-15 10:34:38 | [diff] [blame] | 3 | # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 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: |
[email protected] | 016498e | 2010-12-03 00:59:23 | [diff] [blame] | 10 | # $ sh ./tools/valgrind/valgrind.sh ./out/Debug/chrome |
[email protected] | c72f16a | 2009-03-19 16:02:31 | [diff] [blame] | 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. |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 15 | |
[email protected] | a057041 | 2010-01-26 22:40:06 | [diff] [blame] | 16 | export THISDIR=`dirname $0` |
| 17 | |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 18 | setup_memcheck() { |
[email protected] | 79151339 | 2010-03-19 17:49:02 | [diff] [blame] | 19 | RUN_COMMAND="valgrind" |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 20 | |
| 21 | # Prompt to attach gdb when there was an error detected. |
[email protected] | 3a70be9 | 2014-07-22 02:39:28 | [diff] [blame] | 22 | DEFAULT_TOOL_FLAGS=("--db-command=gdb -nw %f %p" "--db-attach=yes" \ |
[email protected] | 21d90b8 | 2012-03-15 10:34:38 | [diff] [blame] | 23 | # Keep the registers in gdb in sync with the code. |
[email protected] | c1f8ef7 | 2013-07-05 07:04:23 | [diff] [blame] | 24 | "--vex-iropt-register-updates=allregs-at-mem-access" \ |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 25 | # Overwrite newly allocated or freed objects |
| 26 | # with 0x41 to catch inproper use. |
[email protected] | cc7b9cc | 2011-05-06 08:35:06 | [diff] [blame] | 27 | "--malloc-fill=41" "--free-fill=41" \ |
| 28 | # Increase the size of stacks being tracked. |
| 29 | "--num-callers=30") |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 30 | } |
| 31 | |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 32 | setup_unknown() { |
| 33 | echo "Unknown tool \"$TOOL_NAME\" specified, the result is not guaranteed" |
| 34 | DEFAULT_TOOL_FLAGS=() |
| 35 | } |
| 36 | |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 37 | set -e |
| 38 | |
| 39 | if [ $# -eq 0 ]; then |
| 40 | echo "usage: <command to run> <arguments ...>" |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 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 |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 52 | fi |
| 53 | |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 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 |
[email protected] | fe215da | 2013-03-05 19:39:38 | [diff] [blame] | 60 | memcheck*) setup_memcheck "$1";; |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 61 | *) setup_unknown;; |
| 62 | esac |
| 63 | |
[email protected] | 3f57958 | 2009-08-19 21:55:11 | [diff] [blame] | 64 | |
[email protected] | a057041 | 2010-01-26 22:40:06 | [diff] [blame] | 65 | SUPPRESSIONS="$THISDIR/$TOOL_NAME/suppressions.txt" |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 66 | |
[email protected] | a057041 | 2010-01-26 22:40:06 | [diff] [blame] | 67 | CHROME_VALGRIND=`sh $THISDIR/locate_valgrind.sh` |
| 68 | if [ "$CHROME_VALGRIND" = "" ] |
[email protected] | 3f57958 | 2009-08-19 21:55:11 | [diff] [blame] | 69 | then |
[email protected] | a057041 | 2010-01-26 22:40:06 | [diff] [blame] | 70 | # locate_valgrind.sh failed |
| 71 | exit 1 |
[email protected] | 3f57958 | 2009-08-19 21:55:11 | [diff] [blame] | 72 | fi |
[email protected] | a057041 | 2010-01-26 22:40:06 | [diff] [blame] | 73 | echo "Using valgrind binaries from ${CHROME_VALGRIND}" |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 74 | |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 75 | set -x |
[email protected] | a057041 | 2010-01-26 22:40:06 | [diff] [blame] | 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" |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 81 | |
[email protected] | 3f57958 | 2009-08-19 21:55:11 | [diff] [blame] | 82 | # G_SLICE=always-malloc: make glib use system malloc |
[email protected] | 342508e | 2011-06-08 21:30:11 | [diff] [blame] | 83 | # NSS_DISABLE_UNLOAD=1: make nss skip dlclosing dynamically loaded modules, |
| 84 | # which would result in "obj:*" in backtraces. |
[email protected] | 3f57958 | 2009-08-19 21:55:11 | [diff] [blame] | 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 | # |
[email protected] | 6aba927 | 2009-10-26 14:06:28 | [diff] [blame] | 90 | # GTEST_DEATH_TEST_USE_FORK=1: make gtest death tests valgrind-friendly |
[email protected] | 3f57958 | 2009-08-19 21:55:11 | [diff] [blame] | 91 | # |
| 92 | # When everyone has the latest valgrind, we might want to add |
[email protected] | 504088c | 2010-11-03 09:02:30 | [diff] [blame] | 93 | # --show-possibly-lost=no |
[email protected] | 3f57958 | 2009-08-19 21:55:11 | [diff] [blame] | 94 | # to ignore possible but not definite leaks. |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 95 | |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 96 | G_SLICE=always-malloc \ |
[email protected] | 342508e | 2011-06-08 21:30:11 | [diff] [blame] | 97 | NSS_DISABLE_UNLOAD=1 \ |
[email protected] | c72f16a | 2009-03-19 16:02:31 | [diff] [blame] | 98 | NSS_DISABLE_ARENA_FREE_LIST=1 \ |
[email protected] | 48190b3 | 2009-03-18 19:23:04 | [diff] [blame] | 99 | G_DEBUG=fatal_warnings \ |
[email protected] | 6aba927 | 2009-10-26 14:06:28 | [diff] [blame] | 100 | GTEST_DEATH_TEST_USE_FORK=1 \ |
[email protected] | 79151339 | 2010-03-19 17:49:02 | [diff] [blame] | 101 | $RUN_COMMAND \ |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 102 | --trace-children=yes \ |
[email protected] | c1f8ef7 | 2013-07-05 07:04:23 | [diff] [blame] | 103 | --leak-check=yes \ |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 104 | --suppressions="$SUPPRESSIONS" \ |
[email protected] | 68e3b472 | 2009-07-16 15:55:52 | [diff] [blame] | 105 | "${DEFAULT_TOOL_FLAGS[@]}" \ |
[email protected] | 51721db | 2009-03-12 17:28:52 | [diff] [blame] | 106 | "$@" |