5,13d4
< * The license below extends only to copyright in the software and shall
< * not be construed as granting a license to any other intellectual
< * property including but not limited to intellectual property relating
< * to a hardware implementation of the functionality of the software
< * licensed hereunder. You may use the software subject to the license
< * terms below provided that you ensure that this notice is replicated
< * unmodified and in its entirety in all distributions of the software,
< * modified or unmodified, in source code or in binary form.
< *
41a33
> * Andrew Bardsley
57,58c49,55
< using Debug::SimpleFlag;
< using Debug::CompoundFlag;
---
> /** Debug logging base class. Handles formatting and outputting
> * time/name/message messages */
> class Logger
> {
> protected:
> /** Name match for objects to ignore */
> ObjectMatch ignore;
60,61c57,64
< std::ostream &output();
< void setOutput(const std::string &filename);
---
> public:
> /** Log a single message */
> template <typename ...Args>
> void dprintf(Tick when, const std::string &name, const char *fmt,
> const Args &...args)
> {
> if (!name.empty() && ignore.match(name))
> return;
63,65c66,69
< extern bool enabled;
< bool changeFlag(const char *str, bool value);
< void dumpStatus();
---
> std::ostringstream line;
> ccprintf(line, fmt, args...);
> logMessage(when, name, line.str());
> }
67,68c71,73
< extern ObjectMatch ignore;
< extern const std::string DefaultName;
---
> /** Dump a block of data of length len */
> virtual void dump(Tick when, const std::string &name,
> const void *d, int len);
70c75,77
< bool __dprintf_prologue(Tick when, const std::string &name);
---
> /** Log formatted message */
> virtual void logMessage(Tick when, const std::string &name,
> const std::string &message) = 0;
72,74c79,94
< template<typename ...Args> void
< dprintf(Tick when, const std::string &name, const char *format,
< const Args &...args)
---
> /** Return an ostream that can be used to send messages to
> * the 'same place' as formatted logMessage messages. This
> * can be implemented to use a logger's underlying ostream,
> * to provide an ostream which formats the output in some
> * way, or just set to one of std::cout, std::cerr */
> virtual std::ostream &getOstream() = 0;
>
> /** Set objects to ignore */
> void setIgnore(ObjectMatch &ignore_) { ignore = ignore_; }
>
> virtual ~Logger() { }
> };
>
> /** Logging wrapper for ostreams with the format:
> * <when>: <name>: <message-body> */
> class OstreamLogger : public Logger
76,77c96,97
< if (!__dprintf_prologue(when, name))
< return;
---
> protected:
> std::ostream &stream;
79,82c99,101
< std::ostream &os(output());
< ccprintf(os, format, args...);
< os.flush();
< }
---
> public:
> OstreamLogger(std::ostream &stream_) : stream(stream_)
> { }
84c103,104
< void dump(Tick when, const std::string &name, const void *data, int len);
---
> void logMessage(Tick when, const std::string &name,
> const std::string &message) M5_ATTR_OVERRIDE;
85a106,121
> std::ostream &getOstream() M5_ATTR_OVERRIDE { return stream; }
> };
>
> /** Get the current global debug logger. This takes ownership of the given
> * logger which should be allocated using 'new' */
> Logger *getDebugLogger();
>
> /** Get the ostream from the current global logger */
> std::ostream &output();
>
> /** Delete the current global logger and assign a new one */
> void setDebugLogger(Logger *logger);
>
> /** Enable debug logging */
> extern bool enabled;
>
97c133,135
< inline const std::string &name() { return Trace::DefaultName; }
---
> // Return the global context name "global". This function gets called when
> // the DPRINTF macros are used in a context without a visible name() function
> const std::string &name();
127,130c165,168
< #define DDUMP(x, data, count) do { \
< using namespace Debug; \
< if (DTRACE(x)) \
< Trace::dump(curTick(), name(), data, count); \
---
> #define DDUMP(x, data, count) do { \
> using namespace Debug; \
> if (DTRACE(x)) \
> Trace::getDebugLogger()->dump(curTick(), name(), data, count); \
133,136c171,176
< #define DPRINTF(x, ...) do { \
< using namespace Debug; \
< if (DTRACE(x)) \
< Trace::dprintf(curTick(), name(), __VA_ARGS__); \
---
> #define DPRINTF(x, ...) do { \
> using namespace Debug; \
> if (DTRACE(x)) { \
> Trace::getDebugLogger()->dprintf(curTick(), name(), \
> __VA_ARGS__); \
> } \
139,142c179,184
< #define DPRINTFS(x, s, ...) do { \
< using namespace Debug; \
< if (DTRACE(x)) \
< Trace::dprintf(curTick(), s->name(), __VA_ARGS__); \
---
> #define DPRINTFS(x, s, ...) do { \
> using namespace Debug; \
> if (DTRACE(x)) { \
> Trace::getDebugLogger()->dprintf(curTick(), s->name(), \
> __VA_ARGS__); \
> } \
145,148c187,192
< #define DPRINTFR(x, ...) do { \
< using namespace Debug; \
< if (DTRACE(x)) \
< Trace::dprintf((Tick)-1, std::string(), __VA_ARGS__); \
---
> #define DPRINTFR(x, ...) do { \
> using namespace Debug; \
> if (DTRACE(x)) { \
> Trace::getDebugLogger()->dprintf((Tick)-1, std::string(), \
> __VA_ARGS__); \
> } \
151,152c195,196
< #define DDUMPN(data, count) do { \
< Trace::dump(curTick(), name(), data, count); \
---
> #define DDUMPN(data, count) do { \
> Trace::getDebugLogger()->dump(curTick(), name(), data, count); \
155,156c199,200
< #define DPRINTFN(...) do { \
< Trace::dprintf(curTick(), name(), __VA_ARGS__); \
---
> #define DPRINTFN(...) do { \
> Trace::getDebugLogger()->dprintf(curTick(), name(), __VA_ARGS__); \
159,160c203,204
< #define DPRINTFNR(...) do { \
< Trace::dprintf((Tick)-1, string(), __VA_ARGS__); \
---
> #define DPRINTFNR(...) do { \
> Trace::getDebugLogger()->dprintf((Tick)-1, string(), __VA_ARGS__); \