don't make -ddump-if-trace imply -no-recomp
[ghc-hetmet.git] / rts / RtsUtils.c
index a2a2919..0123531 100644 (file)
 #include <time.h>
 #endif
 
+/* HACK: On Mac OS X 10.4 (at least), time.h doesn't declare ctime_r with
+ *       _POSIX_C_SOURCE. If this is the case, we declare it ourselves.
+ */
+#if HAVE_CTIME_R && !HAVE_DECL_CTIME_R
+extern char *ctime_r(const time_t *, char *);
+#endif
+
 #ifdef HAVE_FCNTL_H
 #include <fcntl.h>
 #endif
@@ -136,7 +143,7 @@ static void addAllocation(void *addr, size_t len) {
     }
 }
 
-static void removeAllocation(void *addr) {
+static void removeAllocation(void *addr, int overwrite_with_aa) {
     Allocated *prev, *a;
 
     if (addr == NULL) {
@@ -150,7 +157,9 @@ static void removeAllocation(void *addr) {
         while (a != NULL) {
             if (a->addr == addr) {
                 prev->next = a->next;
-                memset(addr, 0xaa, a->len);
+                if (overwrite_with_aa) {
+                    memset(addr, 0xaa, a->len);
+                }
                 free(a);
                 RELEASE_LOCK(&allocator_mutex);
                 return;
@@ -210,7 +219,7 @@ stgReallocBytes (void *p, int n, char *msg)
       stg_exit(EXIT_INTERNAL_ERROR);
     }
 #if defined(DEBUG)
-    removeAllocation(p);
+    removeAllocation(p, 0);
     addAllocation(space, n2);
 #endif
     return space;
@@ -239,7 +248,7 @@ void
 stgFree(void* p)
 {
 #if defined(DEBUG)
-  removeAllocation(p);
+  removeAllocation(p, 1);
 #endif
   free(p);
 }
@@ -296,14 +305,14 @@ nat stg_strlen(char *s)
    ToDo: put this somewhere sensible.
    -------------------------------------------------------------------------  */
 
-static I_ __GenSymCounter = 0;
+static HsInt __GenSymCounter = 0;
 
-I_
+HsInt
 genSymZh(void)
 {
     return(__GenSymCounter++);
 }
-I_
+HsInt
 resetGenSymZh(void) /* it's your funeral */
 {
     __GenSymCounter=0;
@@ -314,7 +323,6 @@ resetGenSymZh(void) /* it's your funeral */
    Get the current time as a string.  Used in profiling reports.
    -------------------------------------------------------------------------- */
 
-#if defined(PROFILING) || defined(DEBUG) || defined(PAR) || defined(GRAN)
 char *
 time_str(void)
 {
@@ -333,7 +341,6 @@ time_str(void)
     }
     return nowstr;
 }
-#endif
 
 /* -----------------------------------------------------------------------------
  * Reset a file handle to blocking mode.  We do this for the standard
@@ -460,3 +467,23 @@ int genericRaise(int sig) {
         return raise(sig);
 #endif
 }
+
+static void mkRtsInfoPair(char *key, char *val) {
+    /* XXX should check for "s, \s etc in key and val */
+    printf(" ,(\"%s\", \"%s\")\n", key, val);
+}
+
+void printRtsInfo(void) {
+    /* The first entry is just a hack to make it easy to get the
+     * commas right */
+    printf(" [(\"GHC RTS\", \"Yes\")\n");
+    mkRtsInfoPair("GHC version",             ProjectVersion);
+    mkRtsInfoPair("RTS way",                 RtsWay);
+    mkRtsInfoPair("Host platform",           HostPlatform);
+    mkRtsInfoPair("Build platform",          BuildPlatform);
+    mkRtsInfoPair("Target platform",         TargetPlatform);
+    mkRtsInfoPair("Compiler unregisterised", GhcUnregisterised);
+    mkRtsInfoPair("Tables next to code",     GhcEnableTablesNextToCode);
+    printf(" ]\n");
+}
+