|
[Valgrind-developers] valgrind: r9773 - in branches/DARWIN: .
coregrind none/tests none/tests/darwin
From: <sv...@va...> - 2009-05-04 23:44:19
|
Author: njn
Date: 2009-05-05 00:44:12 +0100 (Tue, 05 May 2009)
New Revision: 9773
Log:
Handle the secret 4th 'apple' argument to main. Based on a patch from
Filipe Cabecinhas.
Added:
branches/DARWIN/none/tests/darwin/
branches/DARWIN/none/tests/darwin/Makefile.am
branches/DARWIN/none/tests/darwin/apple-main-arg.c
branches/DARWIN/none/tests/darwin/apple-main-arg.stderr.exp
branches/DARWIN/none/tests/darwin/apple-main-arg.vgtest
branches/DARWIN/none/tests/darwin/filter_stderr
Modified:
branches/DARWIN/configure.in
branches/DARWIN/coregrind/launcher-darwin.c
branches/DARWIN/coregrind/vg_preloaded.c
branches/DARWIN/none/tests/Makefile.am
Modified: branches/DARWIN/configure.in
===================================================================
--- branches/DARWIN/configure.in 2009-05-04 07:29:48 UTC (rev 9772)
+++ branches/DARWIN/configure.in 2009-05-04 23:44:12 UTC (rev 9773)
@@ -1874,6 +1874,7 @@
none/tests/ppc64/Makefile
none/tests/x86/Makefile
none/tests/linux/Makefile
+ none/tests/darwin/Makefile
none/tests/x86-linux/Makefile
none/docs/Makefile
exp-omega/Makefile
Modified: branches/DARWIN/coregrind/launcher-darwin.c
===================================================================
--- branches/DARWIN/coregrind/launcher-darwin.c 2009-05-04 07:29:48 UTC (rev 9772)
+++ branches/DARWIN/coregrind/launcher-darwin.c 2009-05-04 23:44:12 UTC (rev 9773)
@@ -371,9 +371,11 @@
/* tediously augment the env: VALGRIND_STARTUP_PWD_%PID_XYZZY=current_working_dir */
asprintf(&set_cwd, "VALGRIND_STARTUP_PWD_%u_XYZZY=%s", getppid(), cwd);
+ // Note that Apple binaries get a secret fourth arg, "char* apple", which
+ // contains the executable path. Don't forget about it.
for (j = 0; envp[j]; j++)
;
- new_env = malloc((j+3) * sizeof(char*));
+ new_env = malloc((j+4) * sizeof(char*));
if (new_env == NULL)
barf("malloc of new_env failed.");
for (i = 0; i < j; i++)
@@ -381,6 +383,7 @@
new_env[i++] = new_line;
new_env[i++] = set_cwd;
new_env[i++] = NULL;
+ new_env[i ] = envp[i-2]; // the 'apple' arg == the executable_path
assert(i == j+3);
/* tediously edit env: hide dyld options from valgrind's captive dyld */
Modified: branches/DARWIN/coregrind/vg_preloaded.c
===================================================================
--- branches/DARWIN/coregrind/vg_preloaded.c 2009-05-04 07:29:48 UTC (rev 9772)
+++ branches/DARWIN/coregrind/vg_preloaded.c 2009-05-04 23:44:12 UTC (rev 9773)
@@ -107,7 +107,10 @@
to++;
}
}
- *to = *from;
+ *(to++) = *(from++);
+ /* fix the 4th "char* apple" pointer (aka. executable path pointer) */
+ *(to++) = *(from++);
+ *to = NULL;
}
static void vg_cleanup_env(void) __attribute__((constructor));
Modified: branches/DARWIN/none/tests/Makefile.am
===================================================================
--- branches/DARWIN/none/tests/Makefile.am 2009-05-04 07:29:48 UTC (rev 9772)
+++ branches/DARWIN/none/tests/Makefile.am 2009-05-04 23:44:12 UTC (rev 9773)
@@ -21,6 +21,9 @@
if VGCONF_OS_IS_LINUX
SUBDIRS += linux
endif
+if VGCONF_OS_IS_DARWIN
+SUBDIRS += darwin
+endif
# Platform-specific tests
if VGCONF_PLATFORMS_INCLUDE_X86_LINUX
Added: branches/DARWIN/none/tests/darwin/Makefile.am
===================================================================
--- branches/DARWIN/none/tests/darwin/Makefile.am (rev 0)
+++ branches/DARWIN/none/tests/darwin/Makefile.am 2009-05-04 23:44:12 UTC (rev 9773)
@@ -0,0 +1,15 @@
+
+include $(top_srcdir)/Makefile.tool-tests.am
+
+noinst_SCRIPTS = filter_stderr
+
+EXTRA_DIST = $(noinst_SCRIPTS) \
+ apple-main-arg.stderr.exp apple-main-arg.vgtest
+
+check_PROGRAMS = \
+ apple-main-arg
+
+
+AM_CFLAGS += $(AM_FLAG_M3264_PRI)
+AM_CXXFLAGS += $(AM_FLAG_M3264_PRI)
+
Added: branches/DARWIN/none/tests/darwin/apple-main-arg.c
===================================================================
--- branches/DARWIN/none/tests/darwin/apple-main-arg.c (rev 0)
+++ branches/DARWIN/none/tests/darwin/apple-main-arg.c 2009-05-04 23:44:12 UTC (rev 9773)
@@ -0,0 +1,32 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <unistd.h>
+#include <sys/syslimits.h>
+
+// On Darwin there's this secret fourth argument, 'apple', which is a pointer
+// to a string that contains the executable path, like argv[0], but unlike
+// argv[0] it can't be changed using exec().
+
+int main(int argc, char *argv[], char *envp[], char *apple[])
+{
+ char *pargv = calloc((PATH_MAX+1), sizeof(char)),
+ *pappl = calloc((PATH_MAX+1), sizeof(char));
+ int i;
+
+ for (i = 0; envp[i]; i++)
+ ;
+
+ // envp[i]==NULL; envp[i+1]==apple[0]==executable_path
+ assert(envp[i+1] == apple[0]);
+
+ // Make sure realpath(argv[0]) == realpath(apple[0]). (realpath resolves
+ // symlinks.)
+ realpath(argv[0], pargv);
+ realpath(apple[0], pappl);
+ assert(0 == strcmp(pargv, pappl));
+
+ return 0;
+}
+
Added: branches/DARWIN/none/tests/darwin/apple-main-arg.stderr.exp
===================================================================
Added: branches/DARWIN/none/tests/darwin/apple-main-arg.vgtest
===================================================================
--- branches/DARWIN/none/tests/darwin/apple-main-arg.vgtest (rev 0)
+++ branches/DARWIN/none/tests/darwin/apple-main-arg.vgtest 2009-05-04 23:44:12 UTC (rev 9773)
@@ -0,0 +1,2 @@
+prog: apple-main-arg
+vgopts: -q
Added: branches/DARWIN/none/tests/darwin/filter_stderr
===================================================================
--- branches/DARWIN/none/tests/darwin/filter_stderr (rev 0)
+++ branches/DARWIN/none/tests/darwin/filter_stderr 2009-05-04 23:44:12 UTC (rev 9773)
@@ -0,0 +1,3 @@
+#! /bin/sh
+
+../filter_stderr
Property changes on: branches/DARWIN/none/tests/darwin/filter_stderr
___________________________________________________________________
Name: svn:executable
+ *
|