Fix #3439: -debug implies -ticky, and -ticky code links with any RTS
[ghc-hetmet.git] / rts / Trace.c
index 7194651..8991033 100644 (file)
 #include "Threads.h"
 #include "Printer.h"
 
-StgWord32 classes_enabled; // not static due to inline funcs
+#ifdef DEBUG
+// debugging flags, set with +RTS -D<something>
+int DEBUG_sched;
+int DEBUG_interp;
+int DEBUG_weak;
+int DEBUG_gccafs;
+int DEBUG_gc;
+int DEBUG_block_alloc;
+int DEBUG_sanity;
+int DEBUG_stable;
+int DEBUG_stm;
+int DEBUG_prof;
+int DEBUG_gran;
+int DEBUG_par;
+int DEBUG_linker;
+int DEBUG_squeeze;
+int DEBUG_hpc;
+int DEBUG_sparks;
+#endif
+
+// events
+int TRACE_sched;
 
 #ifdef THREADED_RTS
 static Mutex trace_utx;
 #endif
 
+static rtsBool eventlog_enabled;
+
 /* ---------------------------------------------------------------------------
    Starting up / shuttting down the tracing facilities
  --------------------------------------------------------------------------- */
@@ -37,7 +60,7 @@ void initTracing (void)
 
 #ifdef DEBUG
 #define DEBUG_FLAG(name, class) \
-    if (RtsFlags.DebugFlags.name) classes_enabled |= class;
+    class = RtsFlags.DebugFlags.name ? 1 : 0;
 
     DEBUG_FLAG(scheduler,    DEBUG_sched);
     DEBUG_FLAG(scheduler,    TRACE_sched); // -Ds enabled all sched events
@@ -58,21 +81,46 @@ void initTracing (void)
 #endif
 
 #define TRACE_FLAG(name, class) \
-    if (RtsFlags.TraceFlags.name) classes_enabled |= class;
+    class = RtsFlags.TraceFlags.name ? 1 : 0;
 
     TRACE_FLAG(scheduler, TRACE_sched);
 
-    initEventLogging();
+    eventlog_enabled = !RtsFlags.TraceFlags.trace_stderr && (
+                       TRACE_sched
+#ifdef DEBUG
+                       | DEBUG_sched
+                       | DEBUG_interp
+                       | DEBUG_weak
+                       | DEBUG_gccafs
+                       | DEBUG_gc
+                       | DEBUG_block_alloc
+                       | DEBUG_sanity
+                       | DEBUG_stable
+                       | DEBUG_stm
+                       | DEBUG_prof
+                       | DEBUG_linker
+                       | DEBUG_squeeze
+                       | DEBUG_hpc
+#endif
+        );
+
+    if (eventlog_enabled) {
+        initEventLogging();
+    }
 }
 
 void endTracing (void)
 {
-    endEventLogging();
+    if (eventlog_enabled) {
+        endEventLogging();
+    }
 }
 
 void freeTracing (void)
 {
-    freeEventLogging();
+    if (eventlog_enabled) {
+        freeEventLogging();
+    }
 }
 
 /* ---------------------------------------------------------------------------
@@ -200,8 +248,11 @@ static void traceCap_stderr(Capability *cap, char *msg, va_list ap)
 }
 #endif
 
-void traceCap_(Capability *cap, char *msg, va_list ap)
+void traceCap_(Capability *cap, char *msg, ...)
 {
+    va_list ap;
+    va_start(ap,msg);
+    
 #ifdef DEBUG
     if (RtsFlags.TraceFlags.trace_stderr) {
         traceCap_stderr(cap, msg, ap);
@@ -210,6 +261,8 @@ void traceCap_(Capability *cap, char *msg, va_list ap)
     {
         postCapMsg(cap, msg, ap);
     }
+
+    va_end(ap);
 }
 
 #ifdef DEBUG
@@ -225,8 +278,11 @@ static void trace_stderr(char *msg, va_list ap)
 }
 #endif
 
-void trace_(char *msg, va_list ap)
+void trace_(char *msg, ...)
 {
+    va_list ap;
+    va_start(ap,msg);
+
 #ifdef DEBUG
     if (RtsFlags.TraceFlags.trace_stderr) {
         trace_stderr(msg, ap);
@@ -235,6 +291,8 @@ void trace_(char *msg, va_list ap)
     {
         postMsg(msg, ap);
     }
+
+    va_end(ap);
 }
 
 void traceThreadStatus_ (StgTSO *tso USED_IF_DEBUG)