1 //===- llvm/Support/Debug.h - Easy way to add debug output ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements a handy way of adding debugging information to your
11 // code, without it being enabled all of the time, and without having to add
12 // command line options to enable it.
14 // In particular, just wrap your code with the LLVM_DEBUG() macro, and it will
15 // be enabled automatically if you specify '-debug' on the command-line.
16 // LLVM_DEBUG() requires the DEBUG_TYPE macro to be defined. Set it to "foo"
17 // specify that your debug code belongs to class "foo". Be careful that you only
18 // do this after including Debug.h and not around any #include of headers.
19 // Headers should define and undef the macro acround the code that needs to use
20 // the LLVM_DEBUG() macro. Then, on the command line, you can specify
21 // '-debug-only=foo' to enable JUST the debug information for the foo class.
23 // When compiling without assertions, the -debug-* options and all code in
24 // LLVM_DEBUG() statements disappears, so it does not affect the runtime of the
27 //===----------------------------------------------------------------------===//
29 #ifndef LLVM_SUPPORT_DEBUG_H
30 #define LLVM_SUPPORT_DEBUG_H
38 /// isCurrentDebugType - Return true if the specified string is the debug type
39 /// specified on the command line, or if none was specified on the command line
40 /// with the -debug-only=X option.
42 bool isCurrentDebugType(const char *Type);
44 /// setCurrentDebugType - Set the current debug type, as if the -debug-only=X
45 /// option were specified. Note that DebugFlag also needs to be set to true for
46 /// debug output to be produced.
48 void setCurrentDebugType(const char *Type);
50 /// setCurrentDebugTypes - Set the current debug type, as if the
51 /// -debug-only=X,Y,Z option were specified. Note that DebugFlag
52 /// also needs to be set to true for debug output to be produced.
54 void setCurrentDebugTypes(const char **Types, unsigned Count);
56 /// DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug
57 /// information. In the '-debug' option is specified on the commandline, and if
58 /// this is a debug build, then the code specified as the option to the macro
59 /// will be executed. Otherwise it will not be. Example:
61 /// DEBUG_WITH_TYPE("bitset", dbgs() << "Bitset contains: " << Bitset << "\n");
63 /// This will emit the debug information if -debug is present, and -debug-only
64 /// is not specified, or is specified as "bitset".
65 #define DEBUG_WITH_TYPE(TYPE, X) \
66 do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)) { X; } \
70 #define isCurrentDebugType(X) (false)
71 #define setCurrentDebugType(X)
72 #define setCurrentDebugTypes(X, N)
73 #define DEBUG_WITH_TYPE(TYPE, X) do { } while (false)
76 /// This boolean is set to true if the '-debug' command line option
77 /// is specified. This should probably not be referenced directly, instead, use
78 /// the DEBUG macro below.
80 extern bool DebugFlag;
82 /// \name Verification flags.
84 /// These flags turns on/off that are expensive and are turned off by default,
85 /// unless macro EXPENSIVE_CHECKS is defined. The flags allow selectively
86 /// turning the checks on without need to recompile.
89 /// Enables verification of dominator trees.
91 extern bool VerifyDomInfo;
93 /// Enables verification of loop info.
95 extern bool VerifyLoopInfo;
99 /// EnableDebugBuffering - This defaults to false. If true, the debug
100 /// stream will install signal handlers to dump any buffered debug
101 /// output. It allows clients to selectively allow the debug stream
102 /// to install signal handlers if they are certain there will be no
105 extern bool EnableDebugBuffering;
107 /// dbgs() - This returns a reference to a raw_ostream for debugging
108 /// messages. If debugging is disabled it returns errs(). Use it
109 /// like: dbgs() << "foo" << "bar";
112 // DEBUG macro - This macro should be used by passes to emit debug information.
113 // In the '-debug' option is specified on the commandline, and if this is a
114 // debug build, then the code specified as the option to the macro will be
115 // executed. Otherwise it will not be. Example:
117 // LLVM_DEBUG(dbgs() << "Bitset contains: " << Bitset << "\n");
119 #define LLVM_DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)
121 } // end namespace llvm
123 #endif // LLVM_SUPPORT_DEBUG_H