|
From: <sv...@va...> - 2005-09-20 23:09:02
|
Author: sewardj
Date: 2005-09-21 00:09:00 +0100 (Wed, 21 Sep 2005)
New Revision: 4714
Log:
The static linking scheme broke --trace-children=3Dyes, because there
was no way to convey to the stage2's the identity of stage1 (the
launcher) for the recursive process starts.
Therefore do this by passing the name of the launcher in
VALGRINDSTAGE1.
This makes it possible to run OOo on memcheck again.
Modified:
branches/ASPACEM/coregrind/m_launcher.c
branches/ASPACEM/coregrind/m_libcproc.c
branches/ASPACEM/coregrind/m_main.c
branches/ASPACEM/coregrind/pub_core_libcproc.h
Modified: branches/ASPACEM/coregrind/m_launcher.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_launcher.c 2005-09-20 23:06:34 UTC (rev =
4713)
+++ branches/ASPACEM/coregrind/m_launcher.c 2005-09-20 23:09:00 UTC (rev =
4714)
@@ -48,20 +48,33 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <assert.h>
=20
=20
+#define PATH_MAX 4096 /* POSIX refers to this a lot but I dunno
+ where it is defined */
+
+static void barf ( char* str )
+{
+ fprintf(stderr, "valgrind: Cannot continue: %s\n", str );
+ exit(1);
+}
+
/* Where we expect to find all our aux files */
static const char *valgrind_lib =3D VG_LIBDIR;
=20
int main(int argc, char** argv, char** envp)
{
- int i, loglevel;
+ int i, j, loglevel, r;
Int vg_argc;
Char **vg_argv;
char **cl_argv;
const char *toolname =3D NULL;
const char *cp;
char *toolfile;
+ char stage1_name[PATH_MAX+1];
+ char* new_line;
+ char** new_env;
=20
/* Start the debugging-log system ASAP. First find out how many=20
"-d"s were specified. This is a pre-scan of the command line. */
@@ -96,19 +109,53 @@
toolname =3D "memcheck";
}
=20
+ /* Figure out the name of this executable, so we can tell
+ stage2. */
+ memset(stage1_name, 0, PATH_MAX+1);
+ r =3D readlink("/proc/self/exe", stage1_name, PATH_MAX);
+ if (r =3D=3D -1)
+ barf("readlink(\"/proc/self/exe\") failed.");
+
+ r =3D setenv(VALGRINDSTAGE1, stage1_name, 1/*overwrite*/);
+ if (r !=3D 0)
+ barf("setenv(VALGRINDSTAGE1) failed.");
+
+ /* tediously augment the env: VALGRINDSTAGE1=3Dstage1_name */
+ new_line =3D malloc(strlen(VALGRINDSTAGE1) + 1=20
+ + strlen(stage1_name) + 1);
+ if (new_line =3D=3D NULL)
+ barf("malloc of new_line failed.");
+ strcpy(new_line, VALGRINDSTAGE1);
+ strcat(new_line, "=3D");
+ strcat(new_line, stage1_name);
+
+ for (j =3D 0; envp[j]; j++)
+ ;
+ new_env =3D malloc((j+2) * sizeof(char*));
+ if (new_env =3D=3D NULL)
+ barf("malloc of new_env failed.");
+ for (i =3D 0; i < j; i++)
+ new_env[i] =3D envp[i];
+ new_env[i++] =3D new_line;
+ new_env[i++] =3D NULL;
+ assert(i =3D=3D j+2);
+
+
cp =3D getenv(VALGRINDLIB);
=20
if (cp !=3D NULL)
valgrind_lib =3D cp;
=20
toolfile =3D malloc(strlen(valgrind_lib) + strlen(toolname) + 2);
+ if (toolfile =3D=3D NULL)
+ barf("malloc of toolfile failed.");
sprintf(toolfile, "%s/%s", valgrind_lib, toolname);
=20
VG_(debugLog)(1, "stage1", "launching %s\n", toolfile);
=20
- execve(toolfile, argv, envp);
+ execve(toolfile, argv, new_env);
=20
- fprintf(stderr, "valgrind: failed to start %s: %s\n",
+ fprintf(stderr, "valgrind: failed to start tool '%s': %s\n",
toolname, strerror(errno));
=20
exit(1);
Modified: branches/ASPACEM/coregrind/m_libcproc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_libcproc.c 2005-09-20 23:06:34 UTC (rev =
4713)
+++ branches/ASPACEM/coregrind/m_libcproc.c 2005-09-20 23:09:00 UTC (rev =
4714)
@@ -216,6 +216,9 @@
// Remove VALGRIND_CLO variable.
VG_(env_unsetenv)(envp, VALGRINDCLO);
=20
+ // Remove VALGRIND_STAGE1 variable.
+ VG_(env_unsetenv)(envp, VALGRINDSTAGE1);
+
// XXX if variable becomes empty, remove it completely?
=20
VG_(arena_free)(VG_AR_CORE, buf);
Modified: branches/ASPACEM/coregrind/m_main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_main.c 2005-09-20 23:06:34 UTC (rev 4713=
)
+++ branches/ASPACEM/coregrind/m_main.c 2005-09-20 23:09:00 UTC (rev 4714=
)
@@ -90,15 +90,6 @@
#define AT_SECURE 23 /* secure mode boolean */
#endif /* AT_SECURE */
=20
-/* redzone gap between client address space and shadow */
-#define REDZONE_SIZE (1 * 1024*1024)
-
-/* size multiple for client address space */
-#define CLIENT_SIZE_MULTIPLE (1 * 1024*1024)
-
-/* Proportion of client space for its heap (rest is for mmaps + stack) *=
/
-#define CLIENT_HEAP_PROPORTION 0.333
-
/* Number of file descriptors that Valgrind tries to reserve for
it's own use - just a small constant. */
#define N_RESERVED_FDS (10)
@@ -113,8 +104,8 @@
Startup stuff =20
------------------------------------------------------------------ */
=20
-/* stage1 (main) executable */
-static Int vgexecfd =3D -1;
+/* The name of the stage1 (main) executable */
+static HChar* name_of_stage1 =3D NULL;
=20
/* our argc/argv */
static Int vg_argc;
@@ -1672,10 +1663,8 @@
// Build "/proc/self/fd/<execfd>".
Char* VG_(build_child_exename)( void )
{
- Char* exename =3D VG_(arena_malloc)(VG_AR_CORE, 64);
- vg_assert(NULL !=3D exename);
- VG_(sprintf)(exename, "/proc/self/fd/%d", vgexecfd);
- return exename;
+ vg_assert(name_of_stage1);
+ return VG_(arena_strdup)(VG_AR_CORE, name_of_stage1);
}
=20
=20
@@ -1707,8 +1696,6 @@
/* Update the soft limit. */
VG_(setrlimit)(VKI_RLIMIT_NOFILE, &rl);
=20
- if (vgexecfd !=3D -1)
- vgexecfd =3D VG_(safe_fd)( vgexecfd );
if (VG_(clexecfd) !=3D -1)
VG_(clexecfd) =3D VG_(safe_fd)( VG_(clexecfd) );
}
@@ -2055,6 +2042,16 @@
}
VG_(debugLog)(1, "main", "Dynamic memory manager is running\n");
=20
+ //--------------------------------------------------------------
+ // Extract the stage1 name from the environment.
+ VG_(debugLog)(1, "main", "Getting stage1's name\n");
+ name_of_stage1 =3D VG_(getenv)(VALGRINDSTAGE1);
+ if (name_of_stage1 =3D=3D NULL) {
+ VG_(printf)("valgrind: You cannot run the tool binary directly.\n"=
);
+ VG_(printf)("valgrind: You should use $prefix/bin/valgrind.\n");
+ VG_(exit)(1);
+ }
+
//=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
// Command line argument handling order:
// * If --help/--help-debug are present, show usage message=20
Modified: branches/ASPACEM/coregrind/pub_core_libcproc.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/pub_core_libcproc.h 2005-09-20 23:06:34 UT=
C (rev 4713)
+++ branches/ASPACEM/coregrind/pub_core_libcproc.h 2005-09-20 23:09:00 UT=
C (rev 4714)
@@ -39,7 +39,8 @@
#include "pub_tool_libcproc.h"
=20
/* The directory we look for all our auxillary files in. Useful for
- running Valgrind out of a build tree without having to do "make insta=
ll". */
+ running Valgrind out of a build tree without having to do "make
+ install". */
#define VALGRINDLIB "VALGRINDLIB"
=20
/* Additional command-line arguments; they are overridden by actual
@@ -47,6 +48,12 @@
is no quoting mechanism. */
#define VALGRINDOPTS "VALGRIND_OPTS"
=20
+/* The full name of Valgrind's stage1 (launcher) executable. This is
+ set by stage1 and read by stage2, and is used for recursive
+ invokations of Valgrind on child processes. */
+#define VALGRINDSTAGE1 "VALGRIND_STAGE1"
+
+
/* If this variable is present in the environment, then valgrind will
not parse the command line for options at all; all options come
from this variable. Arguments are terminated by ^A (\001). There
|