llvm.org GIT mirror llvm / 70197a3
add a new 'SetCurrentDebugType' API (requested by Andrew Haley for JIT stuff) to programmatically control the current debug flavor. While I'm at it, doxygenate Debug.h and clean it up. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85395 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
2 changed file(s) with 46 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
2727
2828 namespace llvm {
2929
30 // DebugFlag - This boolean is set to true if the '-debug' command line option
31 // is specified. This should probably not be referenced directly, instead, use
32 // the DEBUG macro below.
33 //
30 /// DEBUG_TYPE macro - Files can specify a DEBUG_TYPE as a string, which causes
31 /// all of their DEBUG statements to be activatable with -debug-only=thatstring.
32 #ifndef DEBUG_TYPE
33 #define DEBUG_TYPE ""
34 #endif
35
3436 #ifndef NDEBUG
37 /// DebugFlag - This boolean is set to true if the '-debug' command line option
38 /// is specified. This should probably not be referenced directly, instead, use
39 /// the DEBUG macro below.
40 ///
3541 extern bool DebugFlag;
36 #endif
42
43 /// isCurrentDebugType - Return true if the specified string is the debug type
44 /// specified on the command line, or if none was specified on the command line
45 /// with the -debug-only=X option.
46 ///
47 bool isCurrentDebugType(const char *Type);
3748
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 //
42 #ifndef NDEBUG
43 bool isCurrentDebugType(const char *Type);
49 /// SetCurrentDebugType - Set the current debug type, as if the -debug-only=X
50 /// option were specified. Note that DebugFlag also needs to be set to true for
51 /// debug output to be produced.
52 ///
53 void SetCurrentDebugType(const char *Type);
54
55 /// DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug
56 /// information. In the '-debug' option is specified on the commandline, and if
57 /// this is a debug build, then the code specified as the option to the macro
58 /// will be executed. Otherwise it will not be. Example:
59 ///
60 /// DEBUG_WITH_TYPE("bitset", errs() << "Bitset contains: " << Bitset << "\n");
61 ///
62 /// This will emit the debug information if -debug is present, and -debug-only
63 /// is not specified, or is specified as "bitset".
64 #define DEBUG_WITH_TYPE(TYPE, X) \
65 do { if (DebugFlag && isCurrentDebugType(TYPE)) { X; } } while (0)
66
4467 #else
4568 #define isCurrentDebugType(X) (false)
46 #endif
47
48 // DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug
49 // information. In the '-debug' option is specified on the commandline, and if
50 // this is a debug build, then the code specified as the option to the macro
51 // will be executed. Otherwise it will not be. Example:
52 //
53 // DEBUG_WITH_TYPE("bitset", errs() << "Bitset contains: " << Bitset << "\n");
54 //
55 // This will emit the debug information if -debug is present, and -debug-only is
56 // not specified, or is specified as "bitset".
57
58 #ifdef NDEBUG
69 #define SetCurrentDebugType(X)
5970 #define DEBUG_WITH_TYPE(TYPE, X) do { } while (0)
60 #else
61 #define DEBUG_WITH_TYPE(TYPE, X) \
62 do { if (DebugFlag && isCurrentDebugType(TYPE)) { X; } } while (0)
6371 #endif
6472
6573 // DEBUG macro - This macro should be used by passes to emit debug information.
6977 //
7078 // DEBUG(errs() << "Bitset contains: " << Bitset << "\n");
7179 //
72
73 #ifndef DEBUG_TYPE
74 #define DEBUG_TYPE ""
75 #endif
76
7780 #define DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)
7881
7982 } // End llvm namespace
5656 bool llvm::isCurrentDebugType(const char *DebugType) {
5757 return CurrentDebugType.empty() || DebugType == CurrentDebugType;
5858 }
59
60 /// SetCurrentDebugType - Set the current debug type, as if the -debug-only=X
61 /// option were specified. Note that DebugFlag also needs to be set to true for
62 /// debug output to be produced.
63 ///
64 void SetCurrentDebugType(const char *Type) {
65 CurrentDebugType = Type;
66 }
67
5968 #else
6069 // Avoid "has no symbols" warning.
70 namespace llvm {
6171 int Debug_dummy = 0;
72 }
6273 #endif