summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
Diffstat (limited to 'src/base')
-rw-r--r--src/base/trace.cc123
-rw-r--r--src/base/trace.hh17
2 files changed, 10 insertions, 130 deletions
diff --git a/src/base/trace.cc b/src/base/trace.cc
index 6e9838456..efa76b044 100644
--- a/src/base/trace.cc
+++ b/src/base/trace.cc
@@ -46,6 +46,7 @@ using namespace std;
namespace Trace {
const string DefaultName("global");
FlagVec flags(NumFlags, false);
+bool enabled = true;
//
// This variable holds the output stream for debug information. Other
@@ -223,125 +224,3 @@ DataRecord::dump(ostream &os)
}
}
} // namespace Trace
-
-//
-// Returns the current output stream for debug information. As a
-// wrapper around Trace::dprintf_stream, this handles cases where debug
-// information is generated in the process of parsing .ini options,
-// before we process the option that sets up the debug output stream
-// itself.
-//
-std::ostream &
-DebugOut()
-{
- return *Trace::dprintf_stream;
-}
-
-/////////////////////////////////////////////
-//
-// C-linkage functions for invoking from gdb
-//
-/////////////////////////////////////////////
-
-//
-// Dump trace buffer to specified file (cout if NULL)
-//
-void
-dumpTrace(const char *filename)
-{
- if (filename != NULL) {
- ofstream out(filename);
- Trace::theLog.dump(out);
- out.close();
- }
- else {
- Trace::theLog.dump(cout);
- }
-}
-
-
-//
-// Turn on/off trace output to cerr. Typically used when trace output
-// is only going to circular buffer, but you want to see what's being
-// sent there as you step through some code in gdb. This uses the
-// same facility as the "trace to file" feature, and will print error
-// messages rather than clobbering an existing ostream pointer.
-//
-void
-echoTrace(bool on)
-{
- if (on) {
- if (Trace::dprintf_stream != NULL) {
- cerr << "Already echoing trace to a file... go do a 'tail -f'"
- << " on that file instead." << endl;
- } else {
- Trace::dprintf_stream = &cerr;
- }
- } else {
- if (Trace::dprintf_stream != &cerr) {
- cerr << "Not echoing trace to cerr." << endl;
- } else {
- Trace::dprintf_stream = NULL;
- }
- }
-}
-
-void
-printTraceFlags()
-{
- using namespace Trace;
- for (int i = 0; i < numFlagStrings; ++i)
- if (flags[i])
- cprintf("%s\n", flagStrings[i]);
-}
-
-void
-tweakTraceFlag(const char *string, bool value)
-{
- using namespace Trace;
- std::string str(string);
-
- for (int i = 0; i < numFlagStrings; ++i) {
- if (str != flagStrings[i])
- continue;
-
- int idx = i;
-
- if (idx < NumFlags) {
- flags[idx] = value;
- } else {
- idx -= NumFlags;
- if (idx >= NumCompoundFlags) {
- ccprintf(cerr, "Invalid compound flag");
- return;
- }
-
- const Flags *flagVec = compoundFlags[idx];
-
- for (int j = 0; flagVec[j] != -1; ++j) {
- if (flagVec[j] >= NumFlags) {
- ccprintf(cerr, "Invalid compound flag");
- return;
- }
- flags[flagVec[j]] = value;
- }
- }
-
- cprintf("flag %s was %s\n", string, value ? "set" : "cleared");
- return;
- }
-
- cprintf("could not find flag %s\n", string);
-}
-
-void
-setTraceFlag(const char *string)
-{
- tweakTraceFlag(string, true);
-}
-
-void
-clearTraceFlag(const char *string)
-{
- tweakTraceFlag(string, false);
-}
diff --git a/src/base/trace.hh b/src/base/trace.hh
index 739f7fe03..dbe98a11b 100644
--- a/src/base/trace.hh
+++ b/src/base/trace.hh
@@ -47,19 +47,16 @@ namespace Trace {
extern FlagVec flags;
-#if TRACING_ON
- const bool On = true;
-#else
- const bool On = false;
-#endif
+ extern std::ostream *dprintf_stream;
inline bool
IsOn(int t)
{
return flags[t];
-
}
+ extern bool enabled;
+
void dump(const uint8_t *data, int count);
class Record
@@ -156,7 +153,11 @@ namespace Trace {
};
-std::ostream &DebugOut();
+inline std::ostream &
+DebugOut()
+{
+ return *Trace::dprintf_stream;
+}
// 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
@@ -181,7 +182,7 @@ inline const std::string &name() { return Trace::DefaultName; }
#if TRACING_ON
-#define DTRACE(x) (Trace::IsOn(Trace::x))
+#define DTRACE(x) (Trace::IsOn(Trace::x) && Trace::enabled)
#define DDUMP(x, data, count) do { \
if (DTRACE(x)) \