aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-07 23:48:59 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-07 23:48:59 +0000
commitc3c9239d76e2acb01dac8c72323a0b28fadebe4b (patch)
tree9aa7c034cf40476365e7a8028beff6c7bd7c2317
parente9ce5d5ef94c04a6316a5368a4927f9a34ae2a2f (diff)
Add DEBUG_WITH_TYPE as a clean alternative to tweaking DEBUG_TYPE.
This: -- #undef DEBUG_TYPE #define DEBUG_TYPE "foo" DEBUG(...) #undef DEBUG_TYPE #define DEBUG_TYPE "" -- becomes this: -- DEBUG_WITH_TYPE("foo", ...) -- git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78435 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--docs/ProgrammersManual.html15
-rw-r--r--include/llvm/Support/Debug.h26
2 files changed, 34 insertions, 7 deletions
diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html
index e3f91a2af6..e920cbbc64 100644
--- a/docs/ProgrammersManual.html
+++ b/docs/ProgrammersManual.html
@@ -646,6 +646,21 @@ on when the name is specified. This allows, for example, all debug information
for instruction scheduling to be enabled with <tt>-debug-type=InstrSched</tt>,
even if the source lives in multiple files.</p>
+<p>The <tt>DEBUG_WITH_TYPE</tt> macro is also available for situations where you
+would like to set <tt>DEBUG_TYPE</tt>, but only for one specific <tt>DEBUG</tt>
+statement. It takes an additional first parameter, which is the type to use. For
+example, the preceeding example could be written as:</p>
+
+
+<div class="doc_code">
+<pre>
+DEBUG_WITH_TYPE("", errs() &lt;&lt; "No debug type\n");
+DEBUG_WITH_TYPE("foo", errs() &lt;&lt; "'foo' debug type\n");
+DEBUG_WITH_TYPE("bar", errs() &lt;&lt; "'bar' debug type\n"));
+DEBUG_WITH_TYPE("", errs() &lt;&lt; "No debug type (2)\n");
+</pre>
+</div>
+
</div>
<!-- ======================================================================= -->
diff --git a/include/llvm/Support/Debug.h b/include/llvm/Support/Debug.h
index 69544de911..17dca21609 100644
--- a/include/llvm/Support/Debug.h
+++ b/include/llvm/Support/Debug.h
@@ -42,24 +42,36 @@ extern bool DebugFlag;
//
bool isCurrentDebugType(const char *Type);
+// DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug
+// information. In the '-debug' option is specified on the commandline, and if
+// this is a debug build, then the code specified as the option to the macro
+// will be executed. Otherwise it will not be. Example:
+//
+// DEBUG_WITH_TYPE("bitset", errs() << "Bitset contains: " << Bitset << "\n");
+//
+// This will emit the debug information if -debug is present, and -debug-only is
+// not specified, or is specified as "bitset".
+
+#ifdef NDEBUG
+#define DEBUG_WITH_TYPE(TYPE, X) do { } while (0)
+#else
+#define DEBUG_WITH_TYPE(TYPE, X) \
+ do { if (DebugFlag && isCurrentDebugType(TYPE)) { X; } } while (0)
+#endif
+
// DEBUG macro - This macro should be used by passes to emit debug information.
// In the '-debug' option is specified on the commandline, and if this is a
// debug build, then the code specified as the option to the macro will be
// executed. Otherwise it will not be. Example:
//
-// DEBUG(cerr << "Bitset contains: " << Bitset << "\n");
+// DEBUG(errs() << "Bitset contains: " << Bitset << "\n");
//
#ifndef DEBUG_TYPE
#define DEBUG_TYPE ""
#endif
-#ifdef NDEBUG
-#define DEBUG(X)
-#else
-#define DEBUG(X) \
- do { if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { X; } } while (0)
-#endif
+#define DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)
/// getNullOutputStream - Return a null string that does not output
/// anything. This hides the static variable from other modules.