blob: 789bc3f703da14b89505c50e48737f1f78ec8242 [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001#!/bin/sh
njn25e49d8e72002-09-23 09:36:25 +00002##--------------------------------------------------------------------##
3##--- The startup script. valgrind ---##
4##--------------------------------------------------------------------##
5
njnc9539842002-10-02 13:26:35 +00006# This file is part of Valgrind, an extensible x86 protected-mode
7# emulator for monitoring program execution on x86-Unixes.
njn25e49d8e72002-09-23 09:36:25 +00008#
njn0e1b5142003-04-15 14:58:06 +00009# Copyright (C) 2002-2003 Julian Seward
njn25e49d8e72002-09-23 09:36:25 +000010# 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
sewardjde4a1d02002-03-22 01:27:54 +000029
30# Should point to the installation directory
31prefix="@prefix@"
32exec_prefix="@exec_prefix@"
33VALGRIND="@libdir@/valgrind"
sewardj2e10a682003-04-07 19:36:41 +000034nptl_threading="@NPTL_THREADING@"
sewardjde4a1d02002-03-22 01:27:54 +000035
sewardjde4a1d02002-03-22 01:27:54 +000036# Other stuff ...
37version="@VERSION@"
38emailto="jseward@acm.org"
39
40# The default name of the suppressions file
41vgsupp="--suppressions=$VALGRIND/default.supp"
42
sewardjde4a1d02002-03-22 01:27:54 +000043# Valgrind options
44vgopts=
45
njn25e49d8e72002-09-23 09:36:25 +000046# --skin=<foo> arg, specifying skin used
47skin_arg=
sewardjde4a1d02002-03-22 01:27:54 +000048
njn42e23f22003-05-05 12:47:25 +000049# --in-place=<dir> arg, for using non-installed version
50in_place_arg=
51
52# Default core+skin to use are the installed ones
53coredir=$VALGRIND
54skindir=$VALGRIND
55
56# Collect up args for Valgrind. Only some are intercepted here;
57# the rest are passed to vg_main.c.
sewardj5dcde042003-02-24 21:42:53 +000058while [ $# != 0 ]
sewardjde4a1d02002-03-22 01:27:54 +000059do
sewardj557fb852002-04-22 22:26:51 +000060 arg=$1
sewardjde4a1d02002-03-22 01:27:54 +000061 case "$arg" in
njn25e49d8e72002-09-23 09:36:25 +000062 --version) echo "valgrind-$version"; exit 1 ;;
63 --skin=*) skin_arg=$arg; shift;;
njn42e23f22003-05-05 12:47:25 +000064 --in-place=*) in_place_arg=$arg; shift;;
njn25e49d8e72002-09-23 09:36:25 +000065 -*) vgopts="$vgopts $arg"; shift;;
sewardjde4a1d02002-03-22 01:27:54 +000066 *) break;;
67 esac
68done
69
njn25e49d8e72002-09-23 09:36:25 +000070
71# Decide on the skin. Default to memory checking if not specified.
72if [ z"$skin_arg" = z ]; then
73 skin=memcheck
74else
75 # Hack off the "--skin=" prefix.
76 skin=`echo $skin_arg | sed 's/--skin=//'`
77fi
78
njn42e23f22003-05-05 12:47:25 +000079# If running uninstalled version in-place...
80if [ z"$in_place_arg" != z ]; then
81 in_place_dir=`echo $in_place_arg | sed 's/--in-place=//'`
82 skindir="$in_place_dir/$skin"
daywalker6672df02003-06-01 19:06:03 +000083 coredir="$in_place_dir/coregrind/.in_place"
njn42e23f22003-05-05 12:47:25 +000084 vgsupp="--suppressions=$in_place_dir/default.supp"
85fi
86
njn25e49d8e72002-09-23 09:36:25 +000087# Setup skin shared object.
88skin_so="vgskin_${skin}.so"
njn42e23f22003-05-05 12:47:25 +000089if [ ! -r "$skindir/$skin_so" ] ; then
njn25e49d8e72002-09-23 09:36:25 +000090 echo
njn25cac76cb2002-09-23 11:21:57 +000091 echo "Skin error:"
njn25e49d8e72002-09-23 09:36:25 +000092 echo " The shared library \`$skin_so' for the chosen"
93 echo " skin \`$skin' could not be found in"
njn42e23f22003-05-05 12:47:25 +000094 echo " $skindir"
njn25e49d8e72002-09-23 09:36:25 +000095 echo
sewardjde4a1d02002-03-22 01:27:54 +000096 exit 1
97fi
98
njn25e49d8e72002-09-23 09:36:25 +000099VG_ARGS="$VALGRIND_OPTS $vgsupp $vgopts"
100
njn25e49d8e72002-09-23 09:36:25 +0000101export VG_ARGS
sewardjde4a1d02002-03-22 01:27:54 +0000102
sewardjd5815ec2003-04-06 12:23:27 +0000103# Red Hat Linux 9 uses NPTL, which has a kernel interface
njne709de42003-04-23 17:49:09 +0000104# unlike the linuxthreads interface valgrind expects. We can
sewardjd5815ec2003-04-06 12:23:27 +0000105# tell the dynamic loader to disable this interface using
106# an environment variable.
107
sewardj2e10a682003-04-07 19:36:41 +0000108if [ z"$nptl_threading" = zyes ]; then
109 LD_ASSUME_KERNEL=2.2.5
110 export LD_ASSUME_KERNEL
111fi
sewardjd5815ec2003-04-06 12:23:27 +0000112
njndc8d5e52003-09-25 18:20:17 +0000113# Ensure the program isn't statically linked.
114if [ $# != 0 ] ; then
115 which_prog="`which $1`"
njnf45a4eb2003-09-28 18:18:47 +0000116 case `file "$which_prog"` in
117 *"statically linked"*)
njndc8d5e52003-09-25 18:20:17 +0000118 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
124fi
125
sewardj3e1eb1f2002-05-18 13:14:17 +0000126# 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.
sewardjde4a1d02002-03-22 01:27:54 +0000131
njn42e23f22003-05-05 12:47:25 +0000132LD_LIBRARY_PATH=$coredir:$LD_LIBRARY_PATH
sewardj2e93c502002-04-12 11:12:52 +0000133export LD_LIBRARY_PATH
njn25e49d8e72002-09-23 09:36:25 +0000134
135# Insert skin .so before valgrind.so to override template functions.
njn42e23f22003-05-05 12:47:25 +0000136LD_PRELOAD=$skindir/$skin_so:$coredir/valgrind.so:$LD_PRELOAD
sewardjde4a1d02002-03-22 01:27:54 +0000137export LD_PRELOAD
sewardj2e93c502002-04-12 11:12:52 +0000138#LD_DEBUG=files
sewardj5716dbb2002-04-26 03:28:18 +0000139#LD_DEBUG=symbols
sewardj2e93c502002-04-12 11:12:52 +0000140#export LD_DEBUG
sewardj5dcde042003-02-24 21:42:53 +0000141
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
njne709de42003-04-23 17:49:09 +0000144# matter which -- because it won't be run anyway (we use 'true').
sewardj5dcde042003-02-24 21:42:53 +0000145if [ $# != 0 ] ; then
146 exec "$@"
147else
148 VG_ARGS="$VG_ARGS -h"
149 exec true
150fi
njn25e49d8e72002-09-23 09:36:25 +0000151
152##--------------------------------------------------------------------##
153##--- end valgrind ---##
154##--------------------------------------------------------------------##