From 70176fecd1ff04f7b8957f3110497d758310b569 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Tue, 26 Aug 2014 10:13:45 -0400 Subject: base: Replace the internal varargs stuff with C++11 constructs We currently use our own home-baked support for type-safe variadic functions. This is confusing and somewhat limited (e.g., cprintf only supports a limited number of arguments). This changeset converts all uses of our internal varargs support to use C++11 variadic macros. --- src/base/trace.cc | 53 ++++++++++++++--------------------------------------- 1 file changed, 14 insertions(+), 39 deletions(-) (limited to 'src/base/trace.cc') diff --git a/src/base/trace.cc b/src/base/trace.cc index fa55e42a9..00a4c3e6b 100644 --- a/src/base/trace.cc +++ b/src/base/trace.cc @@ -38,7 +38,6 @@ #include "base/output.hh" #include "base/str.hh" #include "base/trace.hh" -#include "base/varargs.hh" using namespace std; @@ -70,59 +69,35 @@ setOutput(const string &filename) ObjectMatch ignore; -void -dprintf(Tick when, const std::string &name, const char *format, - CPRINTF_DEFINITION) + +bool +__dprintf_prologue(Tick when, const std::string &name) { if (!name.empty() && ignore.match(name)) - return; + return false; std::ostream &os = *dprintf_stream; - string fmt = ""; - CPrintfArgsList args(VARARGS_ALLARGS); + if (when != MaxTick) + ccprintf(os, "%7d: ", when); - if (!name.empty()) { - fmt = "%s: " + fmt; - args.push_front(name); - } - - if (when != (Tick)-1) { - fmt = "%7d: " + fmt; - args.push_front(when); - } + if (!name.empty()) + os << name << ": "; - fmt += format; - - ccprintf(os, fmt.c_str(), args); - os.flush(); + return true; } void dump(Tick when, const std::string &name, const void *d, int len) { - if (!name.empty() && ignore.match(name)) - return; - - std::ostream &os = *dprintf_stream; - - string fmt = ""; - CPrintfArgsList args; - - if (!name.empty()) { - fmt = "%s: " + fmt; - args.push_front(name); - } - - if (when != (Tick)-1) { - fmt = "%7d: " + fmt; - args.push_front(when); - } - const char *data = static_cast(d); + std::ostream &os = *dprintf_stream; int c, i, j; + for (i = 0; i < len; i += 16) { - ccprintf(os, fmt, args); + if (!__dprintf_prologue(when, name)) + return; + ccprintf(os, "%08x ", i); c = len - i; if (c > 16) c = 16; -- cgit v1.2.3