blob: 8b86e5d349893af024d184da4d0014595a37ebcd [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.
sewardj557fb852002-04-22 22:26:51 +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_CMD="$@"
83VG_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').
88if [ z"$VG_CMD" = z ] ; then
89 VG_ARGS="$VG_ARGS -h"
90 VG_CMD=true
sewardjde4a1d02002-03-22 01:27:54 +000091fi
njn25e49d8e72002-09-23 09:36:25 +000092export VG_ARGS
sewardjde4a1d02002-03-22 01:27:54 +000093
sewardj3e1eb1f2002-05-18 13:14:17 +000094# 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.
sewardjde4a1d02002-03-22 01:27:54 +000099
sewardj2e93c502002-04-12 11:12:52 +0000100LD_LIBRARY_PATH=$VALGRIND:$LD_LIBRARY_PATH
101export LD_LIBRARY_PATH
njn25e49d8e72002-09-23 09:36:25 +0000102
103# Insert skin .so before valgrind.so to override template functions.
104LD_PRELOAD=$VALGRIND/$skin_so:$VALGRIND/valgrind.so:$LD_PRELOAD
sewardjde4a1d02002-03-22 01:27:54 +0000105export LD_PRELOAD
sewardj2e93c502002-04-12 11:12:52 +0000106#LD_DEBUG=files
sewardj5716dbb2002-04-26 03:28:18 +0000107#LD_DEBUG=symbols
sewardj2e93c502002-04-12 11:12:52 +0000108#export LD_DEBUG
njn25e49d8e72002-09-23 09:36:25 +0000109
110exec $VG_CMD
111
112##--------------------------------------------------------------------##
113##--- end valgrind ---##
114##--------------------------------------------------------------------##
115