diff options
author | Stephen Hines <srhines@google.com> | 2015-04-01 18:49:24 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-04-01 18:49:26 +0000 |
commit | 3fa16bd6062e23bcdb82ed4dd965674792e6b761 (patch) | |
tree | 9348fc507292f7e8715d22d64ce5a32131b4f875 /lib/Support/Debug.cpp | |
parent | beed47390a60f6f0c77532b3d3f76bb47ef49423 (diff) | |
parent | ebe69fe11e48d322045d5949c83283927a0d790b (diff) | |
download | external_llvm-3fa16bd6062e23bcdb82ed4dd965674792e6b761.zip external_llvm-3fa16bd6062e23bcdb82ed4dd965674792e6b761.tar.gz external_llvm-3fa16bd6062e23bcdb82ed4dd965674792e6b761.tar.bz2 |
Merge "Update aosp/master LLVM for rebase to r230699."
Diffstat (limited to 'lib/Support/Debug.cpp')
-rw-r--r-- | lib/Support/Debug.cpp | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/lib/Support/Debug.cpp b/lib/Support/Debug.cpp index 8246542..9c58ae8 100644 --- a/lib/Support/Debug.cpp +++ b/lib/Support/Debug.cpp @@ -25,15 +25,51 @@ #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" -#include "llvm/Support/ManagedStatic.h" + +#undef isCurrentDebugType +#undef setCurrentDebugType using namespace llvm; +// Even though LLVM might be built with NDEBUG, define symbols that the code +// built without NDEBUG can depend on via the llvm/Support/Debug.h header. +namespace llvm { +/// Exported boolean set by the -debug option. +bool DebugFlag = false; + +static ManagedStatic<std::vector<std::string>> CurrentDebugType; + +/// Return true if the specified string is the debug type +/// specified on the command line, or if none was specified on the command line +/// with the -debug-only=X option. +bool isCurrentDebugType(const char *DebugType) { + 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; +} + +/// Set the current debug type, as if the -debug-only=X +/// option were specified. Note that DebugFlag also needs to be set to true for +/// debug output to be produced. +/// +void setCurrentDebugType(const char *Type) { + CurrentDebugType->clear(); + CurrentDebugType->push_back(Type); +} + +} // namespace llvm + // All Debug.h functionality is a no-op in NDEBUG mode. #ifndef NDEBUG -bool llvm::DebugFlag; // DebugFlag - Exported boolean set by the -debug option // -debug - Command line option to enable the DEBUG statements in the passes. // This flag may only be enabled in debug builds. @@ -51,14 +87,14 @@ DebugBufferSize("debug-buffer-size", cl::Hidden, cl::init(0)); -static ManagedStatic<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); } }; @@ -68,7 +104,7 @@ static DebugOnlyOpt DebugOnlyOptLoc; 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. @@ -82,22 +118,6 @@ static void debug_user_sig_handler(void *Cookie) { dbgout->flushBufferWithBanner(); } -// isCurrentDebugType - Return true if the specified string is the debug type -// specified on the command line, or if none was specified on the command line -// with the -debug-only=X option. -// -bool llvm::isCurrentDebugType(const char *DebugType) { - return CurrentDebugType->empty() || DebugType == *CurrentDebugType; -} - -/// setCurrentDebugType - Set the current debug type, as if the -debug-only=X -/// option were specified. Note that DebugFlag also needs to be set to true for -/// debug output to be produced. -/// -void llvm::setCurrentDebugType(const char *Type) { - *CurrentDebugType = Type; -} - /// dbgs - Return a circular-buffered debug stream. raw_ostream &llvm::dbgs() { // Do one-time initialization in a thread-safe way. |