LLVM API Documentation

Debug.h

Go to the documentation of this file.
00001 //===- llvm/Support/Debug.h - Easy way to add debug output ------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements a handle way of adding debugging information to your
00011 // code, without it being enabled all of the time, and without having to add
00012 // command line options to enable it.
00013 //
00014 // In particular, just wrap your code with the DEBUG() macro, and it will be
00015 // enabled automatically if you specify '-debug' on the command-line.
00016 // Alternatively, you can also use the SET_DEBUG_TYPE("foo") macro to specify
00017 // that your debug code belongs to class "foo".  Then, on the command line, you
00018 // can specify '-debug-only=foo' to enable JUST the debug information for the
00019 // foo class.
00020 //
00021 // When compiling in release mode, the -debug-* options and all code in DEBUG()
00022 // statements disappears, so it does not effect the runtime of the code.
00023 //
00024 //===----------------------------------------------------------------------===//
00025 
00026 #ifndef LLVM_SUPPORT_DEBUG_H
00027 #define LLVM_SUPPORT_DEBUG_H
00028 
00029 namespace llvm {
00030 
00031 // DebugFlag - This boolean is set to true if the '-debug' command line option
00032 // is specified.  This should probably not be referenced directly, instead, use
00033 // the DEBUG macro below.
00034 //
00035 extern bool DebugFlag;
00036 
00037 // isCurrentDebugType - Return true if the specified string is the debug type
00038 // specified on the command line, or if none was specified on the command line
00039 // with the -debug-only=X option.
00040 //
00041 bool isCurrentDebugType(const char *Type);
00042 
00043 // DEBUG macro - This macro should be used by passes to emit debug information.
00044 // In the '-debug' option is specified on the commandline, and if this is a
00045 // debug build, then the code specified as the option to the macro will be
00046 // executed.  Otherwise it will not be.  Example:
00047 //
00048 // DEBUG(cerr << "Bitset contains: " << Bitset << "\n");
00049 //
00050 
00051 #ifndef DEBUG_TYPE
00052 #define DEBUG_TYPE ""
00053 #endif
00054 
00055 #ifdef NDEBUG
00056 #define DEBUG(X)
00057 #else
00058 #define DEBUG(X) \
00059   do { if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { X; } } while (0)
00060 #endif
00061 
00062 } // End llvm namespace
00063 
00064 #endif