#include "llvm/Support/Debug.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/circular_raw_ostream.h"
cl::Hidden,
cl::init(0));
-static std::string CurrentDebugType;
+static ManagedStatic<std::vector<std::string> > CurrentDebugType;
namespace {
struct DebugOnlyOpt {
void operator=(const std::string &Val) const {
- DebugFlag |= !Val.empty();
- CurrentDebugType = Val;
+ if (Val.empty())
+ return;
+ DebugFlag = true;
+ CurrentDebugType->push_back(Val);
}
};
static cl::opt<DebugOnlyOpt, true, cl::parser<std::string> >
DebugOnly("debug-only", cl::desc("Enable a specific type of debug output"),
- cl::Hidden, cl::value_desc("debug string"),
+ cl::Hidden, cl::ZeroOrMore, cl::value_desc("debug string"),
cl::location(DebugOnlyOptLoc), cl::ValueRequired);
// Signal handlers - dump debug output on termination.
// with the -debug-only=X option.
//
bool llvm::isCurrentDebugType(const char *DebugType) {
- return CurrentDebugType.empty() || DebugType == CurrentDebugType;
+ if (CurrentDebugType->empty())
+ return true;
+ // see if DebugType is in list. Note: do not use find() as that forces us to
+ // unnecessarily create an std::string instance.
+ for (auto d : *CurrentDebugType) {
+ if (d == DebugType)
+ return true;
+ }
+ return false;
}
/// setCurrentDebugType - Set the current debug type, as if the -debug-only=X
/// debug output to be produced.
///
void llvm::setCurrentDebugType(const char *Type) {
- CurrentDebugType = Type;
+ CurrentDebugType->clear();
+ CurrentDebugType->push_back(Type);
}
/// dbgs - Return a circular-buffered debug stream.
if (EnableDebugBuffering && DebugFlag && DebugBufferSize != 0)
// TODO: Add a handler for SIGUSER1-type signals so the user can
// force a debug dump.
- sys::AddSignalHandler(&debug_user_sig_handler, 0);
+ sys::AddSignalHandler(&debug_user_sig_handler, nullptr);
// Otherwise we've already set the debug stream buffer size to
// zero, disabling buffering so it will output directly to errs().
}