LLVM API Documentation
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 // Unsurprisingly, most users of this macro use std::cerr too. 00030 #include <iostream> 00031 00032 namespace llvm { 00033 00034 // DebugFlag - This boolean is set to true if the '-debug' command line option 00035 // is specified. This should probably not be referenced directly, instead, use 00036 // the DEBUG macro below. 00037 // 00038 extern bool DebugFlag; 00039 00040 // isCurrentDebugType - Return true if the specified string is the debug type 00041 // specified on the command line, or if none was specified on the command line 00042 // with the -debug-only=X option. 00043 // 00044 bool isCurrentDebugType(const char *Type); 00045 00046 // DEBUG macro - This macro should be used by passes to emit debug information. 00047 // In the '-debug' option is specified on the commandline, and if this is a 00048 // debug build, then the code specified as the option to the macro will be 00049 // executed. Otherwise it will not be. Example: 00050 // 00051 // DEBUG(cerr << "Bitset contains: " << Bitset << "\n"); 00052 // 00053 00054 #ifndef DEBUG_TYPE 00055 #define DEBUG_TYPE "" 00056 #endif 00057 00058 #ifdef NDEBUG 00059 #define DEBUG(X) 00060 #else 00061 #define DEBUG(X) \ 00062 do { if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { X; } } while (0) 00063 #endif 00064 00065 } // End llvm namespace 00066 00067 #endif