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 is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements a handy 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 #include "llvm/Support/Streams.h"
00030 
00031 namespace llvm {
00032 
00033 // DebugFlag - This boolean is set to true if the '-debug' command line option
00034 // is specified.  This should probably not be referenced directly, instead, use
00035 // the DEBUG macro below.
00036 //
00037 extern bool DebugFlag;
00038 
00039 // isCurrentDebugType - Return true if the specified string is the debug type
00040 // specified on the command line, or if none was specified on the command line
00041 // with the -debug-only=X option.
00042 //
00043 bool isCurrentDebugType(const char *Type);
00044 
00045 // DEBUG macro - This macro should be used by passes to emit debug information.
00046 // In the '-debug' option is specified on the commandline, and if this is a
00047 // debug build, then the code specified as the option to the macro will be
00048 // executed.  Otherwise it will not be.  Example:
00049 //
00050 // DEBUG(cerr << "Bitset contains: " << Bitset << "\n");
00051 //
00052 
00053 #ifndef DEBUG_TYPE
00054 #define DEBUG_TYPE ""
00055 #endif
00056 
00057 #ifdef NDEBUG
00058 #define DEBUG(X)
00059 #else
00060 #define DEBUG(X) \
00061   do { if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { X; } } while (0)
00062 #endif
00063 
00064 /// getErrorOutputStream - Returns the error output stream (std::cerr). This
00065 /// places the std::c* I/O streams into one .cpp file and relieves the whole
00066 /// program from having to have hundreds of static c'tor/d'tors for them.
00067 /// 
00068 OStream &getErrorOutputStream(const char *DebugType);
00069 
00070 #ifdef NDEBUG
00071 #define DOUT llvm::OStream(0)
00072 #else
00073 #define DOUT llvm::getErrorOutputStream(DEBUG_TYPE)
00074 #endif
00075 
00076 } // End llvm namespace
00077 
00078 #endif



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.