Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:29

0001 //===- llvm/Support/Debug.h - Easy way to add debug output ------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file implements a handy way of adding debugging information to your
0010 // code, without it being enabled all of the time, and without having to add
0011 // command line options to enable it.
0012 //
0013 // In particular, just wrap your code with the LLVM_DEBUG() macro, and it will
0014 // be enabled automatically if you specify '-debug' on the command-line.
0015 // LLVM_DEBUG() requires the DEBUG_TYPE macro to be defined. Set it to "foo"
0016 // specify that your debug code belongs to class "foo". Be careful that you only
0017 // do this after including Debug.h and not around any #include of headers.
0018 // Headers should define and undef the macro acround the code that needs to use
0019 // the LLVM_DEBUG() macro. Then, on the command line, you can specify
0020 // '-debug-only=foo' to enable JUST the debug information for the foo class.
0021 //
0022 // When compiling without assertions, the -debug-* options and all code in
0023 // LLVM_DEBUG() statements disappears, so it does not affect the runtime of the
0024 // code.
0025 //
0026 //===----------------------------------------------------------------------===//
0027 
0028 #ifndef LLVM_SUPPORT_DEBUG_H
0029 #define LLVM_SUPPORT_DEBUG_H
0030 
0031 namespace llvm {
0032 
0033 class raw_ostream;
0034 
0035 #ifndef NDEBUG
0036 
0037 /// isCurrentDebugType - Return true if the specified string is the debug type
0038 /// specified on the command line, or if none was specified on the command line
0039 /// with the -debug-only=X option.
0040 ///
0041 bool isCurrentDebugType(const char *Type);
0042 
0043 /// setCurrentDebugType - Set the current debug type, as if the -debug-only=X
0044 /// option were specified.  Note that DebugFlag also needs to be set to true for
0045 /// debug output to be produced.
0046 ///
0047 void setCurrentDebugType(const char *Type);
0048 
0049 /// setCurrentDebugTypes - Set the current debug type, as if the
0050 /// -debug-only=X,Y,Z option were specified. Note that DebugFlag
0051 /// also needs to be set to true for debug output to be produced.
0052 ///
0053 void setCurrentDebugTypes(const char **Types, unsigned Count);
0054 
0055 /// DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug
0056 /// information.  If the '-debug' option is specified on the commandline, and if
0057 /// this is a debug build, then the code specified as the option to the macro
0058 /// will be executed.  Otherwise it will not be.  Example:
0059 ///
0060 /// DEBUG_WITH_TYPE("bitset", dbgs() << "Bitset contains: " << Bitset << "\n");
0061 ///
0062 /// This will emit the debug information if -debug is present, and -debug-only
0063 /// is not specified, or is specified as "bitset".
0064 #define DEBUG_WITH_TYPE(TYPE, ...)                                             \
0065   do {                                                                         \
0066     if (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)) {               \
0067       __VA_ARGS__;                                                             \
0068     }                                                                          \
0069   } while (false)
0070 
0071 #else
0072 #define isCurrentDebugType(X) (false)
0073 #define setCurrentDebugType(X) do { (void)(X); } while (false)
0074 #define setCurrentDebugTypes(X, N) do { (void)(X); (void)(N); } while (false)
0075 #define DEBUG_WITH_TYPE(TYPE, ...)                                             \
0076   do {                                                                         \
0077   } while (false)
0078 #endif
0079 
0080 /// This boolean is set to true if the '-debug' command line option
0081 /// is specified.  This should probably not be referenced directly, instead, use
0082 /// the DEBUG macro below.
0083 ///
0084 extern bool DebugFlag;
0085 
0086 /// EnableDebugBuffering - This defaults to false.  If true, the debug
0087 /// stream will install signal handlers to dump any buffered debug
0088 /// output.  It allows clients to selectively allow the debug stream
0089 /// to install signal handlers if they are certain there will be no
0090 /// conflict.
0091 ///
0092 extern bool EnableDebugBuffering;
0093 
0094 /// dbgs() - This returns a reference to a raw_ostream for debugging
0095 /// messages.  If debugging is disabled it returns errs().  Use it
0096 /// like: dbgs() << "foo" << "bar";
0097 raw_ostream &dbgs();
0098 
0099 // DEBUG macro - This macro should be used by passes to emit debug information.
0100 // If the '-debug' option is specified on the commandline, and if this is a
0101 // debug build, then the code specified as the option to the macro will be
0102 // executed.  Otherwise it will not be.  Example:
0103 //
0104 // LLVM_DEBUG(dbgs() << "Bitset contains: " << Bitset << "\n");
0105 //
0106 #define LLVM_DEBUG(...) DEBUG_WITH_TYPE(DEBUG_TYPE, __VA_ARGS__)
0107 
0108 } // end namespace llvm
0109 
0110 #endif // LLVM_SUPPORT_DEBUG_H