]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Darwin: add printing function for env and apple pointer area
authorPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 10 Mar 2026 08:41:01 +0000 (09:41 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Tue, 10 Mar 2026 08:41:01 +0000 (09:41 +0100)
Change DEBUG_ENV_APPLE to use it. It will print env and the
apple pointer area at the start of setup_client_stack
(what we get from 'valgrind' and the OS) and at the end
of the same function (what we give tot he client).

coregrind/m_initimg/initimg-darwin.c

index d0c6c464acf9300487bdaaad1c490211deb6117b..e09cdf7bc0a890ad2def56fe0cc9c4b69c996c14 100644 (file)
 #include "pub_core_pathscan.h"        /* find_executable */
 #include "pub_core_initimg.h"         /* self */
 
+// change this to one to see the env/apple pointer area that Darwin gives us
+// and also the env and apple pointer area that we pass on to the guest
+#define DEBUG_ENV_APPLE 0
+
+#if (DEBUG_ENV_APPLE)
+static void print_env_apple(HChar** envp, const HChar* where)
+{
+   int i;
+   int j;
+   HChar** apple;
+   VG_(printf)("Start env and apple pointer strings at %s\n", where);
+
+   for (i = 0; envp[i]; ++i) {
+      VG_(printf)("i %d &envp[i] %p envp[i] %s\n", i, &envp[i], envp[i]);
+   }
+   // should be NULL
+   VG_(printf)("i %d &envp[i] %p envp[i] %s\n", i, &envp[i], envp[i]);
+
+   apple = &envp[i];
+   ++apple;
+
+   for (j = 0; apple[j]; ++j) {
+      VG_(printf)("j %d &apple[j] %p apple[j] %s\n", j, &apple[j], apple[j]);
+   }
+   VG_(printf)("j %d &apple[j] %p apple[j] %s\n", j, &apple[j], apple[j]);
+   VG_(printf)("End env and apple pointer strings at %s\n", where);
+}
+#endif
+
 
 /*====================================================================*/
 /*=== Loading the client                                           ===*/
@@ -514,6 +543,10 @@ Addr setup_client_stack( void*  init_sp,
       }
    }
 
+#if (DEBUG_ENV_APPLE)
+   print_env_apple(VG_(client_envp), "final envp");
+#endif
+
    /* client_SP is pointing at client's argc/argv */
 
    if (0) VG_(printf)("startup SP = %#lx\n", client_SP);
@@ -615,6 +648,10 @@ IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii,
 
    load_client(&info, &iifii.initial_client_IP);
 
+#if (DEBUG_ENV_APPLE)
+   print_env_apple(iicii.envp, "original envp");
+#endif
+
    //--------------------------------------------------------------
    // Set up client's environment
    //   p: set-libdir                   [for VG_(libdir)]