2
0

valgrind.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # Copyright (c) 2017 The LibYuv Project Authors. All rights reserved.
  3. #
  4. # Use of this source code is governed by a BSD-style license
  5. # that can be found in the LICENSE file in the root of the source
  6. # tree. An additional intellectual property rights grant can be found
  7. # in the file PATENTS. All contributing project authors may
  8. # be found in the AUTHORS file in the root of the source tree.
  9. # This is a small script for manually launching valgrind, along with passing
  10. # it the suppression file, and some helpful arguments (automatically attaching
  11. # the debugger on failures, etc). Run it from your repo root, something like:
  12. # $ sh ./tools/valgrind/valgrind.sh ./out/Debug/chrome
  13. #
  14. # This is mostly intended for running the chrome browser interactively.
  15. # To run unit tests, you probably want to run chrome_tests.sh instead.
  16. # That's the script used by the valgrind buildbot.
  17. export THISDIR=`dirname $0`
  18. setup_memcheck() {
  19. RUN_COMMAND="valgrind"
  20. # Prompt to attach gdb when there was an error detected.
  21. DEFAULT_TOOL_FLAGS=("--db-command=gdb -nw %f %p" "--db-attach=yes" \
  22. # Keep the registers in gdb in sync with the code.
  23. "--vex-iropt-register-updates=allregs-at-mem-access" \
  24. # Overwrite newly allocated or freed objects
  25. # with 0x41 to catch inproper use.
  26. "--malloc-fill=41" "--free-fill=41" \
  27. # Increase the size of stacks being tracked.
  28. "--num-callers=30")
  29. }
  30. setup_unknown() {
  31. echo "Unknown tool \"$TOOL_NAME\" specified, the result is not guaranteed"
  32. DEFAULT_TOOL_FLAGS=()
  33. }
  34. set -e
  35. if [ $# -eq 0 ]; then
  36. echo "usage: <command to run> <arguments ...>"
  37. exit 1
  38. fi
  39. TOOL_NAME="memcheck"
  40. declare -a DEFAULT_TOOL_FLAGS[0]
  41. # Select a tool different from memcheck with --tool=TOOL as a first argument
  42. TMP_STR=`echo $1 | sed 's/^\-\-tool=//'`
  43. if [ "$TMP_STR" != "$1" ]; then
  44. TOOL_NAME="$TMP_STR"
  45. shift
  46. fi
  47. if echo "$@" | grep "\-\-tool" ; then
  48. echo "--tool=TOOL must be the first argument" >&2
  49. exit 1
  50. fi
  51. case $TOOL_NAME in
  52. memcheck*) setup_memcheck "$1";;
  53. *) setup_unknown;;
  54. esac
  55. SUPPRESSIONS="$THISDIR/$TOOL_NAME/suppressions.txt"
  56. CHROME_VALGRIND=`sh $THISDIR/locate_valgrind.sh`
  57. if [ "$CHROME_VALGRIND" = "" ]
  58. then
  59. # locate_valgrind.sh failed
  60. exit 1
  61. fi
  62. echo "Using valgrind binaries from ${CHROME_VALGRIND}"
  63. set -x
  64. PATH="${CHROME_VALGRIND}/bin:$PATH"
  65. # We need to set these variables to override default lib paths hard-coded into
  66. # Valgrind binary.
  67. export VALGRIND_LIB="$CHROME_VALGRIND/lib/valgrind"
  68. export VALGRIND_LIB_INNER="$CHROME_VALGRIND/lib/valgrind"
  69. # G_SLICE=always-malloc: make glib use system malloc
  70. # NSS_DISABLE_UNLOAD=1: make nss skip dlclosing dynamically loaded modules,
  71. # which would result in "obj:*" in backtraces.
  72. # NSS_DISABLE_ARENA_FREE_LIST=1: make nss use system malloc
  73. # G_DEBUG=fatal_warnings: make GTK abort on any critical or warning assertions.
  74. # If it crashes on you in the Options menu, you hit bug 19751,
  75. # comment out the G_DEBUG=fatal_warnings line.
  76. #
  77. # GTEST_DEATH_TEST_USE_FORK=1: make gtest death tests valgrind-friendly
  78. #
  79. # When everyone has the latest valgrind, we might want to add
  80. # --show-possibly-lost=no
  81. # to ignore possible but not definite leaks.
  82. G_SLICE=always-malloc \
  83. NSS_DISABLE_UNLOAD=1 \
  84. NSS_DISABLE_ARENA_FREE_LIST=1 \
  85. G_DEBUG=fatal_warnings \
  86. GTEST_DEATH_TEST_USE_FORK=1 \
  87. $RUN_COMMAND \
  88. --trace-children=yes \
  89. --leak-check=yes \
  90. --suppressions="$SUPPRESSIONS" \
  91. "${DEFAULT_TOOL_FLAGS[@]}" \
  92. "$@"