aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Debug.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support/Debug.cpp')
-rw-r--r--llvm/lib/Support/Debug.cpp73
1 files changed, 52 insertions, 21 deletions
diff --git a/llvm/lib/Support/Debug.cpp b/llvm/lib/Support/Debug.cpp
index 19b40ab..b48045c 100644
--- a/llvm/lib/Support/Debug.cpp
+++ b/llvm/lib/Support/Debug.cpp
@@ -30,6 +30,8 @@
#include "llvm/Support/circular_raw_ostream.h"
#include "llvm/Support/raw_ostream.h"
+#include "DebugOptions.h"
+
#undef isCurrentDebugType
#undef setCurrentDebugType
#undef setCurrentDebugTypes
@@ -79,21 +81,32 @@ void setCurrentDebugTypes(const char **Types, unsigned Count) {
// All Debug.h functionality is a no-op in NDEBUG mode.
#ifndef NDEBUG
-// -debug - Command line option to enable the DEBUG statements in the passes.
-// This flag may only be enabled in debug builds.
-static cl::opt<bool, true>
-Debug("debug", cl::desc("Enable debug output"), cl::Hidden,
- cl::location(DebugFlag));
+namespace {
+struct CreateDebug {
+ static void *call() {
+ return new cl::opt<bool, true>("debug", cl::desc("Enable debug output"),
+ cl::Hidden, cl::location(DebugFlag));
+ }
+};
// -debug-buffer-size - Buffer the last N characters of debug output
//until program termination.
-static cl::opt<unsigned>
-DebugBufferSize("debug-buffer-size",
- cl::desc("Buffer the last N characters of debug output "
- "until program termination. "
- "[default 0 -- immediate print-out]"),
- cl::Hidden,
- cl::init(0));
+struct CreateDebugBufferSize {
+ static void *call() {
+ return new cl::opt<unsigned>(
+ "debug-buffer-size",
+ cl::desc("Buffer the last N characters of debug output "
+ "until program termination. "
+ "[default 0 -- immediate print-out]"),
+ cl::Hidden, cl::init(0));
+ }
+};
+} // namespace
+
+// -debug - Command line option to enable the DEBUG statements in the passes.
+// This flag may only be enabled in debug builds.
+static ManagedStatic<cl::opt<bool, true>, CreateDebug> Debug;
+static ManagedStatic<cl::opt<unsigned>, CreateDebugBufferSize> DebugBufferSize;
namespace {
@@ -108,15 +121,33 @@ struct DebugOnlyOpt {
CurrentDebugType->push_back(std::string(dbgType));
}
};
-
} // namespace
static DebugOnlyOpt DebugOnlyOptLoc;
-static cl::opt<DebugOnlyOpt, true, cl::parser<std::string> >
-DebugOnly("debug-only", cl::desc("Enable a specific type of debug output (comma separated list of types)"),
- cl::Hidden, cl::ZeroOrMore, cl::value_desc("debug string"),
- cl::location(DebugOnlyOptLoc), cl::ValueRequired);
+namespace {
+struct CreateDebugOnly {
+ static void *call() {
+ return new cl::opt<DebugOnlyOpt, true, cl::parser<std::string>>(
+ "debug-only",
+ cl::desc("Enable a specific type of debug output (comma separated list "
+ "of types)"),
+ cl::Hidden, cl::ZeroOrMore, cl::value_desc("debug string"),
+ cl::location(DebugOnlyOptLoc), cl::ValueRequired);
+ }
+};
+} // namespace
+
+static ManagedStatic<cl::opt<DebugOnlyOpt, true, cl::parser<std::string>>,
+ CreateDebugOnly>
+ DebugOnly;
+
+void llvm::initDebugOptions() {
+ *Debug;
+ *DebugBufferSize;
+ *DebugOnly;
+}
+
// Signal handlers - dump debug output on termination.
static void debug_user_sig_handler(void *Cookie) {
// This is a bit sneaky. Since this is under #ifndef NDEBUG, we
@@ -134,10 +165,10 @@ raw_ostream &llvm::dbgs() {
static struct dbgstream {
circular_raw_ostream strm;
- dbgstream() :
- strm(errs(), "*** Debug Log Output ***\n",
- (!EnableDebugBuffering || !DebugFlag) ? 0 : DebugBufferSize) {
- if (EnableDebugBuffering && DebugFlag && DebugBufferSize != 0)
+ dbgstream()
+ : strm(errs(), "*** Debug Log Output ***\n",
+ (!EnableDebugBuffering || !DebugFlag) ? 0 : *DebugBufferSize) {
+ 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, nullptr);