Merge with head.
[gem5.git] / src / base / trace.hh
index 8df5dd893e988a2b0c25dbffd0f7529fc9242750..c1b5061870dfb53fef61dd022fa128b720289627 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001-2005 The Regents of The University of Michigan
+ * Copyright (c) 2001-2006 The Regents of The University of Michigan
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
 #ifndef __BASE_TRACE_HH__
 #define __BASE_TRACE_HH__
 
+#include <string>
 #include <vector>
 
 #include "base/cprintf.hh"
 #include "base/match.hh"
+#include "base/traceflags.hh"
 #include "sim/host.hh"
-#include "sim/root.hh"
+#include "sim/core.hh"
 
-#ifndef TRACING_ON
-#ifndef NDEBUG
-#define TRACING_ON     1
-#else
-#define TRACING_ON     0
-#endif
-#endif
+namespace Trace {
 
-#include "base/traceflags.hh"
+std::ostream &output();
+void setOutput(const std::string &filename);
 
-namespace Trace {
+extern bool enabled;
+typedef std::vector<bool> FlagVec;
+extern FlagVec flags;
+inline bool IsOn(int t) { return flags[t]; }
+bool changeFlag(const char *str, bool value);
+void dumpStatus();
 
-    typedef std::vector<bool> FlagVec;
+extern ObjectMatch ignore;
+extern const std::string DefaultName;
 
-    extern FlagVec flags;
+void dprintf(Tick when, const std::string &name, const char *format,
+             CPRINTF_DECLARATION);
+void dump(Tick when, const std::string &name, const void *data, int len);
 
-#if TRACING_ON
-    const bool On                              = true;
-#else
-    const bool On                              = false;
-#endif
-
-    inline bool
-    IsOn(int t)
-    {
-        return flags[t];
-
-    }
-
-    void dump(const uint8_t *data, int count);
-
-    class Record
-    {
-      protected:
-        Tick cycle;
-
-        Record(Tick _cycle)
-            : cycle(_cycle)
-        {
-        }
-
-      public:
-        virtual ~Record() {}
-
-        virtual void dump(std::ostream &) = 0;
-    };
-
-    class PrintfRecord : public Record
-    {
-      private:
-        const char *format;
-        const std::string &name;
-        cp::ArgList &args;
-
-      public:
-        PrintfRecord(const char *_format, cp::ArgList &_args,
-                     Tick cycle, const std::string &_name)
-            : Record(cycle), format(_format), name(_name), args(_args)
-        {
-        }
-
-        virtual ~PrintfRecord();
-
-        virtual void dump(std::ostream &);
-    };
-
-    class DataRecord : public Record
-    {
-      private:
-        const std::string &name;
-        uint8_t *data;
-        int len;
-
-      public:
-        DataRecord(Tick cycle, const std::string &name,
-                   const void *_data, int _len);
-        virtual ~DataRecord();
-
-        virtual void dump(std::ostream &);
-    };
-
-    class Log
-    {
-      private:
-        int     size;          // number of records in log
-        Record **buffer;       // array of 'size' Record ptrs (circular buf)
-        Record **nextRecPtr;   // next slot to use in buffer
-        Record **wrapRecPtr;   // &buffer[size], for quick wrap check
-
-      public:
-
-        Log();
-        ~Log();
-
-        void init(int _size);
-
-        void append(Record *); // append trace record to log
-        void dump(std::ostream &);     // dump contents to stream
-    };
-
-    extern Log theLog;
-
-    extern ObjectMatch ignore;
-
-    inline void
-    dprintf(const char *format, cp::ArgList &args, Tick cycle,
-            const std::string &name)
-    {
-        if (name.empty() || !ignore.match(name))
-            theLog.append(new Trace::PrintfRecord(format, args, cycle, name));
-    }
-
-    inline void
-    dataDump(Tick cycle, const std::string &name, const void *data, int len)
-    {
-        theLog.append(new Trace::DataRecord(cycle, name, data, len));
-    }
-
-    extern const std::string DefaultName;
-};
+/* namespace Trace */ }
 
 // This silly little class allows us to wrap a string in a functor
 // object so that we can give a name() that DPRINTF will like
@@ -170,7 +72,6 @@ struct StringWrap
 };
 
 inline const std::string &name() { return Trace::DefaultName; }
-std::ostream &DebugOut();
 
 //
 // DPRINTF is a debugging trace facility that allows one to
@@ -184,50 +85,44 @@ std::ostream &DebugOut();
 
 #if TRACING_ON
 
-#define DTRACE(x) (Trace::IsOn(Trace::x))
+#define DTRACE(x) (Trace::IsOn(Trace::x) && Trace::enabled)
 
-#define DCOUT(x) if (Trace::IsOn(Trace::x)) DebugOut()
-
-#define DDUMP(x, data, count) \
-do { \
-    if (Trace::IsOn(Trace::x)) \
-        Trace::dataDump(curTick, name(), data, count); \
+#define DDUMP(x, data, count) do {                              \
+    if (DTRACE(x))                                              \
+        Trace::dump(curTick, name(), data, count);              \
 } while (0)
 
-#define __dprintf(cycle, name, format, args...) \
-    Trace::dprintf(format, (*(new cp::ArgList), args), cycle, name)
+#define DPRINTF(x, ...) do {                                    \
+    if (DTRACE(x))                                              \
+        Trace::dprintf(curTick, name(), __VA_ARGS__);           \
+} while (0)
 
-#define DPRINTF(x, args...) \
-do { \
-    if (Trace::IsOn(Trace::x)) \
-        __dprintf(curTick, name(), args, cp::ArgListNull()); \
+#define DPRINTFR(x, ...) do {                                   \
+    if (DTRACE(x))                                              \
+        Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__);   \
 } while (0)
 
-#define DPRINTFR(x, args...) \
-do { \
-    if (Trace::IsOn(Trace::x)) \
-        __dprintf((Tick)-1, std::string(), args, cp::ArgListNull());   \
+#define DDUMPN(data, count) do {                                \
+    Trace::dump(curTick, name(), data, count);                  \
 } while (0)
 
-#define DPRINTFN(args...) \
-do { \
-    __dprintf(curTick, name(), args, cp::ArgListNull()); \
+#define DPRINTFN(...) do {                                      \
+    Trace::dprintf(curTick, name(), __VA_ARGS__);               \
 } while (0)
 
-#define DPRINTFNR(args...) \
-do { \
-    __dprintf((Tick)-1, string(), args, cp::ArgListNull()); \
+#define DPRINTFNR(...) do {                                     \
+    Trace::dprintf((Tick)-1, string(), __VA_ARGS__);            \
 } while (0)
 
 #else // !TRACING_ON
 
 #define DTRACE(x) (false)
-#define DCOUT(x) if (0) DebugOut()
-#define DPRINTF(x, args...) do {} while (0)
-#define DPRINTFR(args...) do {} while (0)
-#define DPRINTFN(args...) do {} while (0)
-#define DPRINTFNR(args...) do {} while (0)
 #define DDUMP(x, data, count) do {} while (0)
+#define DPRINTF(x, ...) do {} while (0)
+#define DPRINTFR(...) do {} while (0)
+#define DDUMPN(data, count) do {} while (0)
+#define DPRINTFN(...) do {} while (0)
+#define DPRINTFNR(...) do {} while (0)
 
 #endif // TRACING_ON