]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Darwin regtest: add traces to apple-main-arg test
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 8 Mar 2026 19:41:25 +0000 (20:41 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 8 Mar 2026 19:41:25 +0000 (20:41 +0100)
Traces turned off by default as they will be system dependent.
Useful for debugging env and apple pointer issues.

none/tests/darwin/apple-main-arg.c

index d7f275aee57d09b5bb640d5aeba927ee0ded29fc..fe4912dd338cf8a2ac3388c9d02c600f374e431b 100644 (file)
@@ -6,9 +6,13 @@
 #include <sys/syslimits.h>
 #include "../../../config.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().
+// used for debugging apple pointer issues, see
+// https://bugs.kde.org/show_bug.cgi?id=517304
+//#define DEBUG_ENV
+
+// On Darwin there's this secret fourth argument, 'apple'.
+// That's kind of like a cut down obfuscated version of auxv.
+// For the moment we only support the first entry, executable_path=
 
 int main(int argc, char *argv[], char *envp[], char *apple[])
 {
@@ -16,8 +20,26 @@ int main(int argc, char *argv[], char *envp[], char *apple[])
         *pappl = calloc((PATH_MAX+1), sizeof(char));
    int i;
 
-   for (i = 0; envp[i]; i++)
-      ;
+   for (i = 0; envp[i]; i++) {
+#if defined(DEBUG_ENV)
+      fprintf(stderr, "i %d &envp[i] %p envp[i] %s\n", i, &envp[i], envp[i]);
+#endif
+   }
+
+#if defined(DEBUG_ENV)
+   fprintf(stderr, "2 slots after envp\n");
+   fprintf(stderr, "i %d &envp[i] %p envp[i] %s\n", i, &envp[i], envp[i]);
+   fprintf(stderr, "i %d &envp[i] %p envp[i] %s\n", i+1, &envp[i+1], envp[i+1]);
+   fprintf(stderr, "i %d &envp[i] %p envp[i] %s\n", i+2, &envp[i+2], envp[i+2]);
+   fprintf(stderr, "apple %p\n", apple);
+   int j = 0;
+   while (apple[j]) {
+      fprintf(stderr, "j %d &apple[j] %p apple[j] %s\n", j, &apple[j], apple[j]);
+      ++j;
+   }
+   fprintf(stderr, "1 slot after apple\n");
+   fprintf(stderr, "j %d &apple[j] %p apple[j] %s\n", j, &apple[j], apple[j]);
+#endif
 
    // envp[i]==NULL; envp[i+1]==apple[0]==executable_path
    assert(envp[i+1] == apple[0]);