sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 1 | #!/bin/sh |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 2 | ##--------------------------------------------------------------------## |
| 3 | ##--- The startup script. valgrind ---## |
| 4 | ##--------------------------------------------------------------------## |
| 5 | |
njn | c953984 | 2002-10-02 13:26:35 +0000 | [diff] [blame] | 6 | # This file is part of Valgrind, an extensible x86 protected-mode |
| 7 | # emulator for monitoring program execution on x86-Unixes. |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 8 | # |
njn | 0e1b514 | 2003-04-15 14:58:06 +0000 | [diff] [blame] | 9 | # Copyright (C) 2002-2003 Julian Seward |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 10 | # jseward@acm.org |
| 11 | # |
| 12 | # This program is free software; you can redistribute it and/or |
| 13 | # modify it under the terms of the GNU General Public License as |
| 14 | # published by the Free Software Foundation; either version 2 of the |
| 15 | # License, or (at your option) any later version. |
| 16 | # |
| 17 | # This program is distributed in the hope that it will be useful, but |
| 18 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | # General Public License for more details. |
| 21 | # |
| 22 | # You should have received a copy of the GNU General Public License |
| 23 | # along with this program; if not, write to the Free Software |
| 24 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 25 | # 02111-1307, USA. |
| 26 | # |
| 27 | # The GNU General Public License is contained in the file COPYING. |
| 28 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 29 | |
| 30 | # Should point to the installation directory |
| 31 | prefix="@prefix@" |
| 32 | exec_prefix="@exec_prefix@" |
| 33 | VALGRIND="@libdir@/valgrind" |
sewardj | 2e10a68 | 2003-04-07 19:36:41 +0000 | [diff] [blame] | 34 | nptl_threading="@NPTL_THREADING@" |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 35 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 36 | # Other stuff ... |
| 37 | version="@VERSION@" |
| 38 | emailto="jseward@acm.org" |
| 39 | |
| 40 | # The default name of the suppressions file |
| 41 | vgsupp="--suppressions=$VALGRIND/default.supp" |
| 42 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 43 | # Valgrind options |
| 44 | vgopts= |
| 45 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 46 | # --skin=<foo> arg, specifying skin used |
| 47 | skin_arg= |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 48 | |
njn | 42e23f2 | 2003-05-05 12:47:25 +0000 | [diff] [blame] | 49 | # --in-place=<dir> arg, for using non-installed version |
| 50 | in_place_arg= |
| 51 | |
| 52 | # Default core+skin to use are the installed ones |
| 53 | coredir=$VALGRIND |
| 54 | skindir=$VALGRIND |
| 55 | |
| 56 | # Collect up args for Valgrind. Only some are intercepted here; |
| 57 | # the rest are passed to vg_main.c. |
sewardj | 5dcde04 | 2003-02-24 21:42:53 +0000 | [diff] [blame] | 58 | while [ $# != 0 ] |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 59 | do |
sewardj | 557fb85 | 2002-04-22 22:26:51 +0000 | [diff] [blame] | 60 | arg=$1 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 61 | case "$arg" in |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 62 | --version) echo "valgrind-$version"; exit 1 ;; |
| 63 | --skin=*) skin_arg=$arg; shift;; |
njn | 42e23f2 | 2003-05-05 12:47:25 +0000 | [diff] [blame] | 64 | --in-place=*) in_place_arg=$arg; shift;; |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 65 | -*) vgopts="$vgopts $arg"; shift;; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 66 | *) break;; |
| 67 | esac |
| 68 | done |
| 69 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 70 | |
| 71 | # Decide on the skin. Default to memory checking if not specified. |
| 72 | if [ z"$skin_arg" = z ]; then |
| 73 | skin=memcheck |
| 74 | else |
| 75 | # Hack off the "--skin=" prefix. |
| 76 | skin=`echo $skin_arg | sed 's/--skin=//'` |
| 77 | fi |
| 78 | |
njn | 42e23f2 | 2003-05-05 12:47:25 +0000 | [diff] [blame] | 79 | # If running uninstalled version in-place... |
| 80 | if [ z"$in_place_arg" != z ]; then |
| 81 | in_place_dir=`echo $in_place_arg | sed 's/--in-place=//'` |
| 82 | skindir="$in_place_dir/$skin" |
daywalker | 6672df0 | 2003-06-01 19:06:03 +0000 | [diff] [blame] | 83 | coredir="$in_place_dir/coregrind/.in_place" |
njn | 42e23f2 | 2003-05-05 12:47:25 +0000 | [diff] [blame] | 84 | vgsupp="--suppressions=$in_place_dir/default.supp" |
| 85 | fi |
| 86 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 87 | # Setup skin shared object. |
| 88 | skin_so="vgskin_${skin}.so" |
njn | 42e23f2 | 2003-05-05 12:47:25 +0000 | [diff] [blame] | 89 | if [ ! -r "$skindir/$skin_so" ] ; then |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 90 | echo |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame] | 91 | echo "Skin error:" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 92 | echo " The shared library \`$skin_so' for the chosen" |
| 93 | echo " skin \`$skin' could not be found in" |
njn | 42e23f2 | 2003-05-05 12:47:25 +0000 | [diff] [blame] | 94 | echo " $skindir" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 95 | echo |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 96 | exit 1 |
| 97 | fi |
| 98 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 99 | VG_ARGS="$VALGRIND_OPTS $vgsupp $vgopts" |
| 100 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 101 | export VG_ARGS |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 102 | |
sewardj | d5815ec | 2003-04-06 12:23:27 +0000 | [diff] [blame] | 103 | # Red Hat Linux 9 uses NPTL, which has a kernel interface |
njn | e709de4 | 2003-04-23 17:49:09 +0000 | [diff] [blame] | 104 | # unlike the linuxthreads interface valgrind expects. We can |
sewardj | d5815ec | 2003-04-06 12:23:27 +0000 | [diff] [blame] | 105 | # tell the dynamic loader to disable this interface using |
| 106 | # an environment variable. |
| 107 | |
sewardj | 2e10a68 | 2003-04-07 19:36:41 +0000 | [diff] [blame] | 108 | if [ z"$nptl_threading" = zyes ]; then |
| 109 | LD_ASSUME_KERNEL=2.2.5 |
| 110 | export LD_ASSUME_KERNEL |
| 111 | fi |
sewardj | d5815ec | 2003-04-06 12:23:27 +0000 | [diff] [blame] | 112 | |
njn | dc8d5e5 | 2003-09-25 18:20:17 +0000 | [diff] [blame] | 113 | # Ensure the program isn't statically linked. |
| 114 | if [ $# != 0 ] ; then |
| 115 | which_prog="`which $1`" |
njn | f45a4eb | 2003-09-28 18:18:47 +0000 | [diff] [blame] | 116 | case `file "$which_prog"` in |
| 117 | *"statically linked"*) |
njn | dc8d5e5 | 2003-09-25 18:20:17 +0000 | [diff] [blame] | 118 | echo "\`$which_prog' is statically linked" |
| 119 | echo "Valgrind only works on dynamically linked executables; your" |
| 120 | echo "program must rely on at least one shared object for Valgrind" |
| 121 | echo "to work with it. Read FAQ #5 for more information." |
| 122 | exit 1 ;; |
| 123 | esac |
| 124 | fi |
| 125 | |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 126 | # A bit subtle. The LD_PRELOAD added entry must be absolute |
| 127 | # and not depend on LD_LIBRARY_PATH. This is so that we can |
| 128 | # mess with LD_LIBRARY_PATH for child processes, which makes |
| 129 | # libpthread.so fall out of visibility, independently of |
| 130 | # whether valgrind.so is visible. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 131 | |
njn | 42e23f2 | 2003-05-05 12:47:25 +0000 | [diff] [blame] | 132 | LD_LIBRARY_PATH=$coredir:$LD_LIBRARY_PATH |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 133 | export LD_LIBRARY_PATH |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 134 | |
| 135 | # Insert skin .so before valgrind.so to override template functions. |
njn | 42e23f2 | 2003-05-05 12:47:25 +0000 | [diff] [blame] | 136 | LD_PRELOAD=$skindir/$skin_so:$coredir/valgrind.so:$LD_PRELOAD |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 137 | export LD_PRELOAD |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 138 | #LD_DEBUG=files |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 139 | #LD_DEBUG=symbols |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 140 | #export LD_DEBUG |
sewardj | 5dcde04 | 2003-02-24 21:42:53 +0000 | [diff] [blame] | 141 | |
| 142 | # If no command given, act like -h was given so vg_main.c prints out |
| 143 | # the usage string. And pass to 'exec' tha name of any program -- it doesn't |
njn | e709de4 | 2003-04-23 17:49:09 +0000 | [diff] [blame] | 144 | # matter which -- because it won't be run anyway (we use 'true'). |
sewardj | 5dcde04 | 2003-02-24 21:42:53 +0000 | [diff] [blame] | 145 | if [ $# != 0 ] ; then |
| 146 | exec "$@" |
| 147 | else |
| 148 | VG_ARGS="$VG_ARGS -h" |
| 149 | exec true |
| 150 | fi |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 151 | |
| 152 | ##--------------------------------------------------------------------## |
| 153 | ##--- end valgrind ---## |
| 154 | ##--------------------------------------------------------------------## |