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 | |
| 6 | # This file is part of Valgrind, an x86 protected-mode emulator |
| 7 | # designed for debugging and profiling binaries on x86-Unixes. |
| 8 | # |
| 9 | # Copyright (C) 2002 Julian Seward |
| 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" |
| 34 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 35 | # Other stuff ... |
| 36 | version="@VERSION@" |
| 37 | emailto="jseward@acm.org" |
| 38 | |
| 39 | # The default name of the suppressions file |
| 40 | vgsupp="--suppressions=$VALGRIND/default.supp" |
| 41 | |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 42 | # Valgrind options |
| 43 | vgopts= |
| 44 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 45 | # --skin=<foo> arg, specifying skin used |
| 46 | skin_arg= |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 47 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 48 | # Collect up args for Valgrind. Only --version and --skin are intercepted |
| 49 | # here; the rest are passed to vg_main.c. |
sewardj | 557fb85 | 2002-04-22 22:26:51 +0000 | [diff] [blame] | 50 | while [ $+ != 0 ] |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 51 | do |
sewardj | 557fb85 | 2002-04-22 22:26:51 +0000 | [diff] [blame] | 52 | arg=$1 |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 53 | case "$arg" in |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 54 | --version) echo "valgrind-$version"; exit 1 ;; |
| 55 | --skin=*) skin_arg=$arg; shift;; |
| 56 | -*) vgopts="$vgopts $arg"; shift;; |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 57 | *) break;; |
| 58 | esac |
| 59 | done |
| 60 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 61 | |
| 62 | # Decide on the skin. Default to memory checking if not specified. |
| 63 | if [ z"$skin_arg" = z ]; then |
| 64 | skin=memcheck |
| 65 | else |
| 66 | # Hack off the "--skin=" prefix. |
| 67 | skin=`echo $skin_arg | sed 's/--skin=//'` |
| 68 | fi |
| 69 | |
| 70 | # Setup skin shared object. |
| 71 | skin_so="vgskin_${skin}.so" |
| 72 | if [ ! -r $VALGRIND/$skin_so ] ; then |
| 73 | echo |
njn25 | cac76cb | 2002-09-23 11:21:57 +0000 | [diff] [blame^] | 74 | echo "Skin error:" |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 75 | echo " The shared library \`$skin_so' for the chosen" |
| 76 | echo " skin \`$skin' could not be found in" |
| 77 | echo " $VALGRIND" |
| 78 | echo |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 79 | exit 1 |
| 80 | fi |
| 81 | |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 82 | VG_CMD="$@" |
| 83 | VG_ARGS="$VALGRIND_OPTS $vgsupp $vgopts" |
| 84 | |
| 85 | # If no command given, act like -h was given so vg_main.c prints out |
| 86 | # the usage string. And set VG_CMD to be any program, doesn't matter which |
| 87 | # because it won't be run anyway (we use 'true'). |
| 88 | if [ z"$VG_CMD" = z ] ; then |
| 89 | VG_ARGS="$VG_ARGS -h" |
| 90 | VG_CMD=true |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 91 | fi |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 92 | export VG_ARGS |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 93 | |
sewardj | 3e1eb1f | 2002-05-18 13:14:17 +0000 | [diff] [blame] | 94 | # A bit subtle. The LD_PRELOAD added entry must be absolute |
| 95 | # and not depend on LD_LIBRARY_PATH. This is so that we can |
| 96 | # mess with LD_LIBRARY_PATH for child processes, which makes |
| 97 | # libpthread.so fall out of visibility, independently of |
| 98 | # whether valgrind.so is visible. |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 99 | |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 100 | LD_LIBRARY_PATH=$VALGRIND:$LD_LIBRARY_PATH |
| 101 | export LD_LIBRARY_PATH |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 102 | |
| 103 | # Insert skin .so before valgrind.so to override template functions. |
| 104 | LD_PRELOAD=$VALGRIND/$skin_so:$VALGRIND/valgrind.so:$LD_PRELOAD |
sewardj | de4a1d0 | 2002-03-22 01:27:54 +0000 | [diff] [blame] | 105 | export LD_PRELOAD |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 106 | #LD_DEBUG=files |
sewardj | 5716dbb | 2002-04-26 03:28:18 +0000 | [diff] [blame] | 107 | #LD_DEBUG=symbols |
sewardj | 2e93c50 | 2002-04-12 11:12:52 +0000 | [diff] [blame] | 108 | #export LD_DEBUG |
njn25 | e49d8e7 | 2002-09-23 09:36:25 +0000 | [diff] [blame] | 109 | |
| 110 | exec $VG_CMD |
| 111 | |
| 112 | ##--------------------------------------------------------------------## |
| 113 | ##--- end valgrind ---## |
| 114 | ##--------------------------------------------------------------------## |
| 115 | |