[llvm-commits] [llvm] r78435 - in /llvm/trunk: docs/ProgrammersManual.html include/llvm/Support/Debug.h
Daniel Dunbar
daniel at zuster.org
Fri Aug 7 16:49:00 PDT 2009
Author: ddunbar
Date: Fri Aug 7 18:48:59 2009
New Revision: 78435
URL: http://llvm.org/viewvc/llvm-project?rev=78435&view=rev
Log:
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", ...)
--
Modified:
llvm/trunk/docs/ProgrammersManual.html
llvm/trunk/include/llvm/Support/Debug.h
Modified: llvm/trunk/docs/ProgrammersManual.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ProgrammersManual.html?rev=78435&r1=78434&r2=78435&view=diff
==============================================================================
--- llvm/trunk/docs/ProgrammersManual.html (original)
+++ llvm/trunk/docs/ProgrammersManual.html Fri Aug 7 18:48:59 2009
@@ -646,6 +646,21 @@
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() << "No debug type\n");
+DEBUG_WITH_TYPE("foo", errs() << "'foo' debug type\n");
+DEBUG_WITH_TYPE("bar", errs() << "'bar' debug type\n"));
+DEBUG_WITH_TYPE("", errs() << "No debug type (2)\n");
+</pre>
+</div>
+
</div>
<!-- ======================================================================= -->
Modified: llvm/trunk/include/llvm/Support/Debug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Debug.h?rev=78435&r1=78434&r2=78435&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Debug.h (original)
+++ llvm/trunk/include/llvm/Support/Debug.h Fri Aug 7 18:48:59 2009
@@ -42,24 +42,36 @@
//
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.
More information about the llvm-commits
mailing list