LLVM: lib/DebugInfo/Symbolize/DIPrinter.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

21#include

22#include

23#include

24#include

25#include

26#include

27

28namespace llvm {

29namespace symbolize {

30

32 std::unique_ptr MemBuf;

33

34 std::optional

35 load(StringRef FileName, const std::optional &EmbeddedSource) {

37 return std::nullopt;

38

39 if (EmbeddedSource)

40 return EmbeddedSource;

41 else {

44 if (!BufOrErr)

45 return std::nullopt;

46 MemBuf = std::move(*BufOrErr);

47 return MemBuf->getBuffer();

48 }

49 }

50

51 std::optional pruneSource(const std::optional &Source) {

52 if (!Source)

53 return std::nullopt;

55 for (int64_t L = 1; L <= LastLine; ++L, ++Pos) {

57 FirstLinePos = Pos;

58 Pos = Source->find('\n', Pos);

60 break;

61 }

63 return std::nullopt;

64 return Source->substr(FirstLinePos, (Pos == StringRef::npos)

66 : Pos - FirstLinePos);

67 }

68

69public:

75

77 const std::optional &EmbeddedSource =

78 std::optional())

83

86 return;

87 size_t MaxLineNumberWidth = std::ceil(std::log10(LastLine));

89 for (size_t Pos = 0; Pos < PrunedSource->size(); ++L) {

90 size_t PosEnd = PrunedSource->find('\n', Pos);

93 if (String.ends_with("\r"))

96 if (L == Line)

97 OS << " >: ";

98 else

99 OS << " : ";

102 break;

103 Pos = PosEnd + 1;

104 }

105 }

106};

107

108void PlainPrinterBase::printHeader(std::optional<uint64_t> Address) {

110 OS << "0x";

113 OS << Delimiter;

114 }

115}

116

117

120}

121

128 OS << Prefix << FunctionName << Delimiter;

129 }

130}

131

132void LLVMPrinter::printSimpleLocation(StringRef Filename,

134 OS << Filename << ':' << Info.Line << ':' << Info.Column;

135 if (Info.IsApproximateLine)

136 OS << " " << Info.ApproxString;

137 OS << "\n";

140}

141

142void GNUPrinter::printSimpleLocation(StringRef Filename,

144 OS << Filename << ':' << Info.Line;

145 if (Info.IsApproximateLine)

146 OS << " " << Info.ApproxString;

147 if (Info.Discriminator)

148 OS << " (discriminator " << Info.Discriminator << ')';

149 OS << '\n';

152}

153

156 OS << " Filename: " << Filename << '\n';

157 if (Info.StartLine) {

158 OS << " Function start filename: " << Info.StartFileName << '\n';

159 OS << " Function start line: " << Info.StartLine << '\n';

160 }

162 OS << " Line: " << Info.Line << '\n';

163 OS << " Column: " << Info.Column << '\n';

164 if (Info.Discriminator)

165 OS << " Discriminator: " << Info.Discriminator << '\n';

166 if (Info.IsApproximateLine)

167 OS << " Approximate: true" << '\n';

168}

169

170void LLVMPrinter::printStartAddress(const DILineInfo &Info) {

171 if (Info.StartAddress) {

172 OS << " Function start address: 0x";

174 OS << '\n';

175 }

176}

177

178void LLVMPrinter::printFooter() { OS << '\n'; }

179

187 else

189}

190

195}

196

200 uint32_t FramesNum = Info.getNumberOfFrames();

201 if (FramesNum == 0)

203 else

207}

208

216 if (Global.DeclFile.empty())

217 OS << "??:?\n";

218 else

219 OS << Global.DeclFile << ":" << Global.DeclLine << "\n";

221}

222

224 const std::vector &Locals) {

226 if (Locals.empty())

228 else

229 for (const DILocal &L : Locals) {

230 if (L.FunctionName.empty())

232 else

233 OS << L.FunctionName;

234 OS << '\n';

235

236 if (L.Name.empty())

238 else

239 OS << L.Name;

240 OS << '\n';

241

242 if (L.DeclFile.empty())

244 else

245 OS << L.DeclFile;

246

247 OS << ':' << L.DeclLine << '\n';

248

249 if (L.FrameOffset)

250 OS << *L.FrameOffset;

251 else

253 OS << ' ';

254

255 if (L.Size)

256 OS << *L.Size;

257 else

259 OS << ' ';

260

261 if (L.TagOffset)

262 OS << *L.TagOffset;

263 else

265 OS << '\n';

266 }

268}

269

271 const std::vector &Locations) {

272 if (Locations.empty()) {

274 } else {

275 for (const DILineInfo &L : Locations)

278 }

279}

280

284

285 return true;

286}

287

290}

291

298 if (!ErrorMsg.empty())

299 Json["Error"] = json::Object({{"Message", ErrorMsg.str()}});

300 return Json;

301}

302

307 : ""},

310 : ""},

311 {"StartLine", LineInfo.StartLine},

312 {"StartAddress",

314 {"FileName",

316 {"Line", LineInfo.Line},

317 {"Column", LineInfo.Column},

321 return Obj;

322}

323

328}

329

337 std::string FormattedSource;

340 if (!FormattedSource.empty())

341 Object["Source"] = std::move(FormattedSource);

342 Array.push_back(std::move(Object));

343 }

345 Json["Symbol"] = std::move(Array);

346 if (ObjectList)

347 ObjectList->push_back(std::move(Json));

348 else

349 printJSON(std::move(Json));

350}

351

358 Json["Data"] = std::move(Data);

359 if (ObjectList)

360 ObjectList->push_back(std::move(Json));

361 else

362 printJSON(std::move(Json));

363}

364

366 const std::vector &Locals) {

370 {{"FunctionName", Local.FunctionName},

371 {"Name", Local.Name},

372 {"DeclFile", Local.DeclFile},

373 {"DeclLine", int64_t(Local.DeclLine)},

375 {"TagOffset", Local.TagOffset ? toHex(*Local.TagOffset) : ""}});

376 if (Local.FrameOffset)

377 FrameObject["FrameOffset"] = *Local.FrameOffset;

378 Frame.push_back(std::move(FrameObject));

379 }

381 Json["Frame"] = std::move(Frame);

382 if (ObjectList)

383 ObjectList->push_back(std::move(Json));

384 else

385 printJSON(std::move(Json));

386}

387

389 const std::vector &Locations) {

391 for (const DILineInfo &L : Locations)

394 Json["Loc"] = std::move(Definitions);

395 if (ObjectList)

396 ObjectList->push_back(std::move(Json));

397 else

398 printJSON(std::move(Json));

399}

400

404 if (ObjectList)

405 ObjectList->push_back(std::move(Json));

406 else

407 printJSON(std::move(Json));

408 return false;

409}

410

413 ObjectList = std::make_uniquejson::Array();

414}

415

418 printJSON(std::move(*ObjectList));

419 ObjectList.reset();

420}

421

422}

423}

AMDGPU Mark last scratch load

Analysis containing CSE Info

Provides ErrorOr smart pointer.

assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())

A format-neutral container for inlined code description.

void addFrame(const DILineInfo &Frame)

Base class for error info classes.

virtual std::string message() const

Return the error message as a string.

Base class for user error types.

Represents either an error or a value T.

static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)

Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...

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

std::string str() const

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

constexpr bool empty() const

empty - Check if the string is empty.

static constexpr size_t npos

static Twine utohexstr(const uint64_t &Val)

An Array is a JSON array, which contains heterogeneous JSON values.

void push_back(const Value &E)

An Object is a JSON object, which maps strings to heterogenous JSON values.

std::pair< iterator, bool > insert(KV E)

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

raw_ostream & write_hex(unsigned long long N)

Output N in hexadecimal, without any prefix or padding.

A raw_ostream that writes to an std::string.

void print(const Request &Request, const DILineInfo &Info) override

void listBegin() override

bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo) override

void printContext(SourceCode SourceCode)

virtual void printFooter()

virtual void printStartAddress(const DILineInfo &Info)

bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo) override

virtual void printSimpleLocation(StringRef Filename, const DILineInfo &Info)=0

void printVerbose(StringRef Filename, const DILineInfo &Info)

void printFunctionName(StringRef FunctionName, bool Inlined)

void print(const DILineInfo &Info, bool Inlined)

const std::optional< StringRef > PrunedSource

void format(raw_ostream &OS)

SourceCode(StringRef FileName, int64_t Line, int Lines, const std::optional< StringRef > &EmbeddedSource=std::optional< StringRef >())

static std::string toHex(uint64_t V)

static json::Object toJSON(const Request &Request, StringRef ErrorMsg="")

This is an optimization pass for GlobalISel generic memory operations.

GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)

FormattedNumber format_decimal(int64_t N, unsigned Width)

format_decimal - Output N as a right justified, fixed-width decimal.

@ Global

Append to llvm.global_dtors.

Implement std::hash so that hash_code can be used in STL containers.

Container for description of a global variable.

A format-neutral container for source line information.

static constexpr const char *const BadString

std::optional< uint64_t > StartAddress

static constexpr const char *const Addr2LineBadString

std::optional< StringRef > Source

std::string StartFileName

std::optional< uint64_t > Address