blob: 14c140963d3782eb2508108b3f19efc0e45e970a [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#
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
sewardjde4a1d02002-03-22 01:27:54 +000029
30# Should point to the installation directory
31prefix="@prefix@"
32exec_prefix="@exec_prefix@"
33VALGRIND="@libdir@/valgrind"
34
sewardjde4a1d02002-03-22 01:27:54 +000035# Other stuff ...
36version="@VERSION@"
37emailto="jseward@acm.org"
38
39# The default name of the suppressions file
40vgsupp="--suppressions=$VALGRIND/default.supp"
41
sewardjde4a1d02002-03-22 01:27:54 +000042# Valgrind options
43vgopts=
44
njn25e49d8e72002-09-23 09:36:25 +000045# --skin=<foo> arg, specifying skin used
46skin_arg=
sewardjde4a1d02002-03-22 01:27:54 +000047
njn25e49d8e72002-09-23 09:36:25 +000048# Collect up args for Valgrind. Only --version and --skin are intercepted
49# here; the rest are passed to vg_main.c.
sewardj5dcde042003-02-24 21:42:53 +000050while [ $# != 0 ]
sewardjde4a1d02002-03-22 01:27:54 +000051do
sewardj557fb852002-04-22 22:26:51 +000052 arg=$1
sewardjde4a1d02002-03-22 01:27:54 +000053 case "$arg" in
njn25e49d8e72002-09-23 09:36:25 +000054 --version) echo "valgrind-$version"; exit 1 ;;
55 --skin=*) skin_arg=$arg; shift;;
56 -*) vgopts="$vgopts $arg"; shift;;
sewardjde4a1d02002-03-22 01:27:54 +000057 *) break;;
58 esac
59done
60
njn25e49d8e72002-09-23 09:36:25 +000061
62# Decide on the skin. Default to memory checking if not specified.
63if [ z"$skin_arg" = z ]; then
64 skin=memcheck
65else
66 # Hack off the "--skin=" prefix.
67 skin=`echo $skin_arg | sed 's/--skin=//'`
68fi
69
70# Setup skin shared object.
71skin_so="vgskin_${skin}.so"
72if [ ! -r $VALGRIND/$skin_so ] ; then
73 echo
njn25cac76cb2002-09-23 11:21:57 +000074 echo "Skin error:"
njn25e49d8e72002-09-23 09:36:25 +000075 echo " The shared library \`$skin_so' for the chosen"
76 echo " skin \`$skin' could not be found in"
77 echo " $VALGRIND"
78 echo
sewardjde4a1d02002-03-22 01:27:54 +000079 exit 1
80fi
81
njn25e49d8e72002-09-23 09:36:25 +000082VG_ARGS="$VALGRIND_OPTS $vgsupp $vgopts"
83
njn25e49d8e72002-09-23 09:36:25 +000084export VG_ARGS
sewardjde4a1d02002-03-22 01:27:54 +000085
sewardj3e1eb1f2002-05-18 13:14:17 +000086# A bit subtle. The LD_PRELOAD added entry must be absolute
87# and not depend on LD_LIBRARY_PATH. This is so that we can
88# mess with LD_LIBRARY_PATH for child processes, which makes
89# libpthread.so fall out of visibility, independently of
90# whether valgrind.so is visible.
sewardjde4a1d02002-03-22 01:27:54 +000091
sewardj2e93c502002-04-12 11:12:52 +000092LD_LIBRARY_PATH=$VALGRIND:$LD_LIBRARY_PATH
93export LD_LIBRARY_PATH
njn25e49d8e72002-09-23 09:36:25 +000094
95# Insert skin .so before valgrind.so to override template functions.
96LD_PRELOAD=$VALGRIND/$skin_so:$VALGRIND/valgrind.so:$LD_PRELOAD
sewardjde4a1d02002-03-22 01:27:54 +000097export LD_PRELOAD
sewardj2e93c502002-04-12 11:12:52 +000098#LD_DEBUG=files
sewardj5716dbb2002-04-26 03:28:18 +000099#LD_DEBUG=symbols
sewardj2e93c502002-04-12 11:12:52 +0000100#export LD_DEBUG
sewardj5dcde042003-02-24 21:42:53 +0000101
102# If no command given, act like -h was given so vg_main.c prints out
103# the usage string. And pass to 'exec' tha name of any program -- it doesn't
104# which -- because it won't be run anyway (we use 'true').
105if [ $# != 0 ] ; then
106 exec "$@"
107else
108 VG_ARGS="$VG_ARGS -h"
109 exec true
110fi
njn25e49d8e72002-09-23 09:36:25 +0000111
112##--------------------------------------------------------------------##
113##--- end valgrind ---##
114##--------------------------------------------------------------------##