LLVM: lib/Support/Debug.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

33#include

34

36

37#undef isCurrentDebugType

38#undef setCurrentDebugType

39#undef setCurrentDebugTypes

40

41using namespace llvm;

42

43

44

45

46static std::pair<std::string, std::optional>

48 std::optional Level;

49 size_t ColonPos = DbgType.find(':');

52 DbgType = DbgType.take_front(ColonPos);

53 if (LevelStr.empty())

54 Level = 0;

55 else {

56 int parsedLevel;

57 if (to_integer(LevelStr, parsedLevel, 10))

58 Level = parsedLevel;

59 }

60 }

61 return std::make_pair(DbgType.str(), Level);

62}

63

64

65

66namespace llvm {

67

69

70

71

72

73

74

77

78

79

80

83 return true;

84

85

86 bool HasEnabledDebugType = false;

87

88

90 HasEnabledDebugType =

91 HasEnabledDebugType || (D.second.has_value() || D.second.value() > 0);

92 if (D.first != DebugType)

93 continue;

94 if (D.second.has_value())

95 return true;

96 return D.second >= Level;

97 }

98 return !HasEnabledDebugType;

99}

100

101

102

103

104

106

110

117

118}

119

120

121#ifndef NDEBUG

122

123namespace {

124struct CreateDebug {

125 static void *call() {

126 return new cl::opt<bool, true>("debug", cl::desc("Enable debug output"),

128 }

129};

130

131

132

133struct CreateDebugBufferSize {

134 static void *call() {

136 "debug-buffer-size",

137 cl::desc("Buffer the last N characters of debug output "

138 "until program termination. "

139 "[default 0 -- immediate print-out]"),

141 }

142};

143}

144

145

146

149

150namespace {

151

152struct DebugOnlyOpt {

153 void operator=(const std::string &Val) const {

154 if (Val.empty())

155 return;

159 for (auto DbgType : DbgTypes)

161 }

162};

163}

164

166

167namespace {

168struct CreateDebugOnly {

169 static void *call() {

171 "debug-only",

173 "Enable a specific type of debug output (comma separated list "

174 "of types using the format \"type[:level]\", where the level "

175 "is an optional integer. The level can be set to 1, 2, 3, etc. to "

176 "control the verbosity of the output. Setting a debug-type level "

177 "to zero acts as an opt-out for this specific debug-type without "

178 "affecting the others."),

181 }

182};

183}

184

186 CreateDebugOnly>

188

194

195

205

206

208

209 static struct dbgstream {

211

212 dbgstream()

213 : strm(errs(), "*** Debug Log Output ***\n",

216

217

219

220

221 }

222 } thestrm;

223

224 return thestrm.strm;

225}

226

227#else

228

229namespace llvm {

230

232 return errs();

233 }

234}

236#endif

237

238

239

static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")

static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug

Definition Debug.cpp:147

static void debug_user_sig_handler(void *Cookie)

Definition Debug.cpp:196

static ManagedStatic< cl::opt< unsigned >, CreateDebugBufferSize > DebugBufferSize

Definition Debug.cpp:148

static std::pair< std::string, std::optional< int > > parseDebugType(StringRef DbgType)

Parse a debug type string into a pair of the debug type and the debug level.

Definition Debug.cpp:47

static ManagedStatic< cl::opt< DebugOnlyOpt, true, cl::parser< std::string > >, CreateDebugOnly > DebugOnly

Definition Debug.cpp:187

static DebugOnlyOpt DebugOnlyOptLoc

Definition Debug.cpp:165

ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringRef - Represent a constant reference to a string, i.e.

std::pair< StringRef, StringRef > split(char Separator) const

Split into two substrings around the first occurrence of a separator character.

static constexpr size_t npos

std::string str() const

str - Get the contents as an std::string.

constexpr StringRef substr(size_t Start, size_t N=npos) const

Return a reference to the substring from [Start, Start + N).

constexpr bool empty() const

empty - Check if the string is empty.

StringRef take_front(size_t N=1) const

Return a StringRef equal to 'this' but with only the first N elements remaining.

size_t find(char C, size_t From=0) const

Search for the first character C in the string.

The instances of the Type class are immutable: once they are created, they are never changed.

circular_raw_ostream - A raw_ostream which can save its data to a circular buffer,...

void flushBufferWithBanner()

flushBufferWithBanner - Force output of the buffer along with a small header.

This class implements an extremely fast bulk output stream that can only output to a stream.

template class LLVM_TEMPLATE_ABI opt< unsigned >

initializer< Ty > init(const Ty &Val)

LocationClass< Ty > location(Ty &L)

LLVM_ABI void AddSignalHandler(SignalHandlerCallback FnPtr, void *Cookie)

Add a function to be called when an abort/kill signal is delivered to the process.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI bool EnableDebugBuffering

EnableDebugBuffering - This defaults to false.

Definition Debug.cpp:240

LLVM_ABI bool isCurrentDebugType(const char *Type, int Level=0)

isCurrentDebugType - Return true if the specified string is the debug type specified on the command l...

Definition Debug.cpp:81

void initDebugOptions()

Definition Debug.cpp:189

LLVM_ABI bool DebugFlag

This boolean is set to true if the '-debug' command line option is specified.

Definition Debug.cpp:68

LLVM_ABI void setCurrentDebugTypes(const char **Types, unsigned Count)

setCurrentDebugTypes - Set the current debug type, as if the -debug-only=X,Y,Z option were specified.

Definition Debug.cpp:111

static ManagedStatic< std::vector< std::pair< std::string, std::optional< int > > > > CurrentDebugType

The current debug type and an optional debug level.

Definition Debug.cpp:76

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

Definition Debug.cpp:207

LLVM_ABI void setCurrentDebugType(const char *Type)

setCurrentDebugType - Set the current debug type, as if the -debug-only=X option were specified.

Definition Debug.cpp:107

FunctionAddr VTableAddr Count

LLVM_ABI raw_fd_ostream & errs()

This returns a reference to a raw_ostream for standard error.

ArrayRef(const T &OneElt) -> ArrayRef< T >

bool to_integer(StringRef S, N &Num, unsigned Base=0)

Convert the string S to an integer of the specified type using the radix Base. If Base is 0,...