1//===- llvm/Support/Debug.h - Easy way to add debug output ------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
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.
13//
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.
22//
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
25// code.
26//
27//===----------------------------------------------------------------------===//
28
29#ifndef LLVM_SUPPORT_DEBUG_H
30#define LLVM_SUPPORT_DEBUG_H
31
32namespace llvm {
33
34class raw_ostream;
35
36#ifndef NDEBUG
37
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.
41///
42bool isCurrentDebugType(const char *Type);
43
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.
47///
48void setCurrentDebugType(const char *Type);
49
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.
53///
54void setCurrentDebugTypes(const char **Types, unsigned Count);
55
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:
60///
61/// DEBUG_WITH_TYPE("bitset", dbgs() << "Bitset contains: " << Bitset << "\n");
62///
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; } \
67 } while (false)
68
69#else
70#define isCurrentDebugType(X) (false)
71#define setCurrentDebugType(X)
72#define setCurrentDebugTypes(X, N)
73#define DEBUG_WITH_TYPE(TYPE, X) do { } while (false)
74#endif
75
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.
79///
80extern bool DebugFlag;
81
82/// \name Verification flags.
83///
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.
87/// \{
88
89/// Enables verification of dominator trees.
90///
91extern bool VerifyDomInfo;
92
93/// Enables verification of loop info.
94///
95extern bool VerifyLoopInfo;
96
97/// Enables verification of MemorySSA.
98///
99extern bool VerifyMemorySSA;
100
101///\}
102
103/// EnableDebugBuffering - This defaults to false. If true, the debug
104/// stream will install signal handlers to dump any buffered debug
105/// output. It allows clients to selectively allow the debug stream
106/// to install signal handlers if they are certain there will be no
107/// conflict.
108///
109extern bool EnableDebugBuffering;
110
111/// dbgs() - This returns a reference to a raw_ostream for debugging
112/// messages. If debugging is disabled it returns errs(). Use it
113/// like: dbgs() << "foo" << "bar";
114raw_ostream &dbgs();
115
116// DEBUG macro - This macro should be used by passes to emit debug information.
117// In the '-debug' option is specified on the commandline, and if this is a
118// debug build, then the code specified as the option to the macro will be
119// executed. Otherwise it will not be. Example:
120//
121// LLVM_DEBUG(dbgs() << "Bitset contains: " << Bitset << "\n");
122//
123#define LLVM_DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)
124
125} // end namespace llvm
126
127#endif // LLVM_SUPPORT_DEBUG_H
128