LLVM 20.0.0git
GsymCreator.cpp
Go to the documentation of this file.
1//===- GsymCreator.cpp ----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//===----------------------------------------------------------------------===//
7
15
16#include <algorithm>
17#include <cassert>
18#include <functional>
19#include <vector>
20
21using namespace llvm;
22using namespace gsym;
23
25 : StrTab(StringTableBuilder::ELF), Quiet(Quiet) {
27}
28
30 llvm::StringRef directory = llvm::sys::path::parent_path(Path, Style);
31 llvm::StringRef filename = llvm::sys::path::filename(Path, Style);
32 // We must insert the strings first, then call the FileEntry constructor.
33 // If we inline the insertString() function call into the constructor, the
34 // call order is undefined due to parameter lists not having any ordering
35 // requirements.
36 const uint32_t Dir = insertString(directory);
37 const uint32_t Base = insertString(filename);
38 return insertFileEntry(FileEntry(Dir, Base));
39}
40
41uint32_t GsymCreator::insertFileEntry(FileEntry FE) {
42 std::lock_guard<std::mutex> Guard(Mutex);
43 const auto NextIndex = Files.size();
44 // Find FE in hash map and insert if not present.
45 auto R = FileEntryToIndex.insert(std::make_pair(FE, NextIndex));
46 if (R.second)
47 Files.emplace_back(FE);
48 return R.first->second;
49}
50
51uint32_t GsymCreator::copyFile(const GsymCreator &SrcGC, uint32_t FileIdx) {
52 // File index zero is reserved for a FileEntry with no directory and no
53 // filename. Any other file and we need to copy the strings for the directory
54 // and filename.
55 if (FileIdx == 0)
56 return 0;
57 const FileEntry SrcFE = SrcGC.Files[FileIdx];
58 // Copy the strings for the file and then add the newly converted file entry.
59 uint32_t Dir =
60 SrcFE.Dir == 0
61 ? 0
62 : StrTab.add(SrcGC.StringOffsetMap.find(SrcFE.Dir)->second);
63 uint32_t Base = StrTab.add(SrcGC.StringOffsetMap.find(SrcFE.Base)->second);
64 FileEntry DstFE(Dir, Base);
65 return insertFileEntry(DstFE);
66}
67
69 std::optional<uint64_t> SegmentSize) const {
70 if (SegmentSize)
71 return saveSegments(Path, ByteOrder, *SegmentSize);
72 std::error_code EC;
73 raw_fd_ostream OutStrm(Path, EC);
74 if (EC)
75 return llvm::errorCodeToError(EC);
76 FileWriter O(OutStrm, ByteOrder);
77 return encode(O);
78}
79
81 std::lock_guard<std::mutex> Guard(Mutex);
82 if (Funcs.empty())
83 return createStringError(std::errc::invalid_argument,
84 "no functions to encode");
85 if (!Finalized)
86 return createStringError(std::errc::invalid_argument,
87 "GsymCreator wasn't finalized prior to encoding");
88
89 if (Funcs.size() > UINT32_MAX)
90 return createStringError(std::errc::invalid_argument,
91 "too many FunctionInfos");
92
93 std::optional<uint64_t> BaseAddress = getBaseAddress();
94 // Base address should be valid if we have any functions.
95 if (!BaseAddress)
96 return createStringError(std::errc::invalid_argument,
97 "invalid base address");
98 Header Hdr;
99 Hdr.Magic = GSYM_MAGIC;
100 Hdr.Version = GSYM_VERSION;
101 Hdr.AddrOffSize = getAddressOffsetSize();
102 Hdr.UUIDSize = static_cast<uint8_t>(UUID.size());
103 Hdr.BaseAddress = *BaseAddress;
104 Hdr.NumAddresses = static_cast<uint32_t>(Funcs.size());
105 Hdr.StrtabOffset = 0; // We will fix this up later.
106 Hdr.StrtabSize = 0; // We will fix this up later.
107 memset(Hdr.UUID, 0, sizeof(Hdr.UUID));
108 if (UUID.size() > sizeof(Hdr.UUID))
109 return createStringError(std::errc::invalid_argument,
110 "invalid UUID size %u", (uint32_t)UUID.size());
111 // Copy the UUID value if we have one.
112 if (UUID.size() > 0)
113 memcpy(Hdr.UUID, UUID.data(), UUID.size());
114 // Write out the header.
115 llvm::Error Err = Hdr.encode(O);
116 if (Err)
117 return Err;
118
119 const uint64_t MaxAddressOffset = getMaxAddressOffset();
120 // Write out the address offsets.
121 O.alignTo(Hdr.AddrOffSize);
122 for (const auto &FuncInfo : Funcs) {
123 uint64_t AddrOffset = FuncInfo.startAddress() - Hdr.BaseAddress;
124 // Make sure we calculated the address offsets byte size correctly by
125 // verifying the current address offset is within ranges. We have seen bugs
126 // introduced when the code changes that can cause problems here so it is
127 // good to catch this during testing.
128 assert(AddrOffset <= MaxAddressOffset);
129 (void)MaxAddressOffset;
130 switch (Hdr.AddrOffSize) {
131 case 1:
132 O.writeU8(static_cast<uint8_t>(AddrOffset));
133 break;
134 case 2:
135 O.writeU16(static_cast<uint16_t>(AddrOffset));
136 break;
137 case 4:
138 O.writeU32(static_cast<uint32_t>(AddrOffset));
139 break;
140 case 8:
141 O.writeU64(AddrOffset);
142 break;
143 }
144 }
145
146 // Write out all zeros for the AddrInfoOffsets.
147 O.alignTo(4);
148 const off_t AddrInfoOffsetsOffset = O.tell();
149 for (size_t i = 0, n = Funcs.size(); i < n; ++i)
150 O.writeU32(0);
151
152 // Write out the file table
153 O.alignTo(4);
154 assert(!Files.empty());
155 assert(Files[0].Dir == 0);
156 assert(Files[0].Base == 0);
157 size_t NumFiles = Files.size();
158 if (NumFiles > UINT32_MAX)
159 return createStringError(std::errc::invalid_argument, "too many files");
160 O.writeU32(static_cast<uint32_t>(NumFiles));
161 for (auto File : Files) {
162 O.writeU32(File.Dir);
163 O.writeU32(File.Base);
164 }
165
166 // Write out the string table.
167 const off_t StrtabOffset = O.tell();
168 StrTab.write(O.get_stream());
169 const off_t StrtabSize = O.tell() - StrtabOffset;
170 std::vector<uint32_t> AddrInfoOffsets;
171
172 // Write out the address infos for each function info.
173 for (const auto &FuncInfo : Funcs) {
174 if (Expected<uint64_t> OffsetOrErr = FuncInfo.encode(O))
175 AddrInfoOffsets.push_back(OffsetOrErr.get());
176 else
177 return OffsetOrErr.takeError();
178 }
179 // Fixup the string table offset and size in the header
180 O.fixup32((uint32_t)StrtabOffset, offsetof(Header, StrtabOffset));
181 O.fixup32((uint32_t)StrtabSize, offsetof(Header, StrtabSize));
182
183 // Fixup all address info offsets
184 uint64_t Offset = 0;
185 for (auto AddrInfoOffset : AddrInfoOffsets) {
186 O.fixup32(AddrInfoOffset, AddrInfoOffsetsOffset + Offset);
187 Offset += 4;
188 }
189 return ErrorSuccess();
190}
191
193 // Use the loader to load call site information from the YAML file.
194 CallSiteInfoLoader Loader(*this, Funcs);
195 return Loader.loadYAML(YAMLFile);
196}
197
199 // Nothing to do if we have less than 2 functions.
200 if (Funcs.size() < 2)
201 return;
202
203 // Sort the function infos by address range first
204 llvm::sort(Funcs);
205 std::vector<FunctionInfo> TopLevelFuncs;
206
207 // Add the first function info to the top level functions
208 TopLevelFuncs.emplace_back(std::move(Funcs.front()));
209
210 // Now if the next function info has the same address range as the top level,
211 // then merge it into the top level function, otherwise add it to the top
212 // level.
213 for (size_t Idx = 1; Idx < Funcs.size(); ++Idx) {
214 FunctionInfo &TopFunc = TopLevelFuncs.back();
215 FunctionInfo &MatchFunc = Funcs[Idx];
216 if (TopFunc.Range == MatchFunc.Range) {
217 // Both have the same range - add the 2nd func as a child of the 1st func
218 if (!TopFunc.MergedFunctions)
220 // Avoid adding duplicate functions to MergedFunctions. Since functions
221 // are already ordered within the Funcs array, we can just check equality
222 // against the last function in the merged array.
223 else if (TopFunc.MergedFunctions->MergedFunctions.back() == MatchFunc)
224 continue;
225 TopFunc.MergedFunctions->MergedFunctions.emplace_back(
226 std::move(MatchFunc));
227 } else
228 // No match, add the function as a top-level function
229 TopLevelFuncs.emplace_back(std::move(MatchFunc));
230 }
231
232 uint32_t mergedCount = Funcs.size() - TopLevelFuncs.size();
233 // If any functions were merged, print a message about it.
234 if (mergedCount != 0)
235 Out << "Have " << mergedCount
236 << " merged functions as children of other functions\n";
237
238 std::swap(Funcs, TopLevelFuncs);
239}
240
242 std::lock_guard<std::mutex> Guard(Mutex);
243 if (Finalized)
244 return createStringError(std::errc::invalid_argument, "already finalized");
245 Finalized = true;
246
247 // Don't let the string table indexes change by finalizing in order.
248 StrTab.finalizeInOrder();
249
250 // Remove duplicates function infos that have both entries from debug info
251 // (DWARF or Breakpad) and entries from the SymbolTable.
252 //
253 // Also handle overlapping function. Usually there shouldn't be any, but they
254 // can and do happen in some rare cases.
255 //
256 // (a) (b) (c)
257 // ^ ^ ^ ^
258 // |X |Y |X ^ |X
259 // | | | |Y | ^
260 // | | | v v |Y
261 // v v v v
262 //
263 // In (a) and (b), Y is ignored and X will be reported for the full range.
264 // In (c), both functions will be included in the result and lookups for an
265 // address in the intersection will return Y because of binary search.
266 //
267 // Note that in case of (b), we cannot include Y in the result because then
268 // we wouldn't find any function for range (end of Y, end of X)
269 // with binary search
270
271 const auto NumBefore = Funcs.size();
272 // Only sort and unique if this isn't a segment. If this is a segment we
273 // already finalized the main GsymCreator with all of the function infos
274 // and then the already sorted and uniqued function infos were added to this
275 // object.
276 if (!IsSegment) {
277 if (NumBefore > 1) {
278 // Sort function infos so we can emit sorted functions.
279 llvm::sort(Funcs);
280 std::vector<FunctionInfo> FinalizedFuncs;
281 FinalizedFuncs.reserve(Funcs.size());
282 FinalizedFuncs.emplace_back(std::move(Funcs.front()));
283 for (size_t Idx=1; Idx < NumBefore; ++Idx) {
284 FunctionInfo &Prev = FinalizedFuncs.back();
285 FunctionInfo &Curr = Funcs[Idx];
286 // Empty ranges won't intersect, but we still need to
287 // catch the case where we have multiple symbols at the
288 // same address and coalesce them.
289 const bool ranges_equal = Prev.Range == Curr.Range;
290 if (ranges_equal || Prev.Range.intersects(Curr.Range)) {
291 // Overlapping ranges or empty identical ranges.
292 if (ranges_equal) {
293 // Same address range. Check if one is from debug
294 // info and the other is from a symbol table. If
295 // so, then keep the one with debug info. Our
296 // sorting guarantees that entries with matching
297 // address ranges that have debug info are last in
298 // the sort.
299 if (!(Prev == Curr)) {
300 if (Prev.hasRichInfo() && Curr.hasRichInfo())
301 Out.Report(
302 "Duplicate address ranges with different debug info.",
303 [&](raw_ostream &OS) {
304 OS << "warning: same address range contains "
305 "different debug "
306 << "info. Removing:\n"
307 << Prev << "\nIn favor of this one:\n"
308 << Curr << "\n";
309 });
310
311 // We want to swap the current entry with the previous since
312 // later entries with the same range always have more debug info
313 // or different debug info.
314 std::swap(Prev, Curr);
315 }
316 } else {
317 Out.Report("Overlapping function ranges", [&](raw_ostream &OS) {
318 // print warnings about overlaps
319 OS << "warning: function ranges overlap:\n"
320 << Prev << "\n"
321 << Curr << "\n";
322 });
323 FinalizedFuncs.emplace_back(std::move(Curr));
324 }
325 } else {
326 if (Prev.Range.size() == 0 && Curr.Range.contains(Prev.Range.start())) {
327 // Symbols on macOS don't have address ranges, so if the range
328 // doesn't match and the size is zero, then we replace the empty
329 // symbol function info with the current one.
330 std::swap(Prev, Curr);
331 } else {
332 FinalizedFuncs.emplace_back(std::move(Curr));
333 }
334 }
335 }
336 std::swap(Funcs, FinalizedFuncs);
337 }
338 // If our last function info entry doesn't have a size and if we have valid
339 // text ranges, we should set the size of the last entry since any search for
340 // a high address might match our last entry. By fixing up this size, we can
341 // help ensure we don't cause lookups to always return the last symbol that
342 // has no size when doing lookups.
343 if (!Funcs.empty() && Funcs.back().Range.size() == 0 && ValidTextRanges) {
344 if (auto Range =
345 ValidTextRanges->getRangeThatContains(Funcs.back().Range.start())) {
346 Funcs.back().Range = {Funcs.back().Range.start(), Range->end()};
347 }
348 }
349 Out << "Pruned " << NumBefore - Funcs.size() << " functions, ended with "
350 << Funcs.size() << " total\n";
351 }
352 return Error::success();
353}
354
355uint32_t GsymCreator::copyString(const GsymCreator &SrcGC, uint32_t StrOff) {
356 // String offset at zero is always the empty string, no copying needed.
357 if (StrOff == 0)
358 return 0;
359 return StrTab.add(SrcGC.StringOffsetMap.find(StrOff)->second);
360}
361
363 if (S.empty())
364 return 0;
365
366 // The hash can be calculated outside the lock.
367 CachedHashStringRef CHStr(S);
368 std::lock_guard<std::mutex> Guard(Mutex);
369 if (Copy) {
370 // We need to provide backing storage for the string if requested
371 // since StringTableBuilder stores references to strings. Any string
372 // that comes from a section in an object file doesn't need to be
373 // copied, but any string created by code will need to be copied.
374 // This allows GsymCreator to be really fast when parsing DWARF and
375 // other object files as most strings don't need to be copied.
376 if (!StrTab.contains(CHStr))
377 CHStr = CachedHashStringRef{StringStorage.insert(S).first->getKey(),
378 CHStr.hash()};
379 }
380 const uint32_t StrOff = StrTab.add(CHStr);
381 // Save a mapping of string offsets to the cached string reference in case
382 // we need to segment the GSYM file and copy string from one string table to
383 // another.
384 StringOffsetMap.try_emplace(StrOff, CHStr);
385 return StrOff;
386}
387
389 auto I = StringOffsetMap.find(Offset);
390 assert(I != StringOffsetMap.end() &&
391 "GsymCreator::getString expects a valid offset as parameter.");
392 return I->second.val();
393}
394
396 std::lock_guard<std::mutex> Guard(Mutex);
397 Funcs.emplace_back(std::move(FI));
398}
399
401 std::function<bool(FunctionInfo &)> const &Callback) {
402 std::lock_guard<std::mutex> Guard(Mutex);
403 for (auto &FI : Funcs) {
404 if (!Callback(FI))
405 break;
406 }
407}
408
410 std::function<bool(const FunctionInfo &)> const &Callback) const {
411 std::lock_guard<std::mutex> Guard(Mutex);
412 for (const auto &FI : Funcs) {
413 if (!Callback(FI))
414 break;
415 }
416}
417
419 std::lock_guard<std::mutex> Guard(Mutex);
420 return Funcs.size();
421}
422
424 if (ValidTextRanges)
425 return ValidTextRanges->contains(Addr);
426 return true; // No valid text ranges has been set, so accept all ranges.
427}
428
429std::optional<uint64_t> GsymCreator::getFirstFunctionAddress() const {
430 // If we have finalized then Funcs are sorted. If we are a segment then
431 // Funcs will be sorted as well since function infos get added from an
432 // already finalized GsymCreator object where its functions were sorted and
433 // uniqued.
434 if ((Finalized || IsSegment) && !Funcs.empty())
435 return std::optional<uint64_t>(Funcs.front().startAddress());
436 return std::nullopt;
437}
438
439std::optional<uint64_t> GsymCreator::getLastFunctionAddress() const {
440 // If we have finalized then Funcs are sorted. If we are a segment then
441 // Funcs will be sorted as well since function infos get added from an
442 // already finalized GsymCreator object where its functions were sorted and
443 // uniqued.
444 if ((Finalized || IsSegment) && !Funcs.empty())
445 return std::optional<uint64_t>(Funcs.back().startAddress());
446 return std::nullopt;
447}
448
449std::optional<uint64_t> GsymCreator::getBaseAddress() const {
450 if (BaseAddress)
451 return BaseAddress;
452 return getFirstFunctionAddress();
453}
454
455uint64_t GsymCreator::getMaxAddressOffset() const {
456 switch (getAddressOffsetSize()) {
457 case 1: return UINT8_MAX;
458 case 2: return UINT16_MAX;
459 case 4: return UINT32_MAX;
460 case 8: return UINT64_MAX;
461 }
462 llvm_unreachable("invalid address offset");
463}
464
465uint8_t GsymCreator::getAddressOffsetSize() const {
466 const std::optional<uint64_t> BaseAddress = getBaseAddress();
467 const std::optional<uint64_t> LastFuncAddr = getLastFunctionAddress();
468 if (BaseAddress && LastFuncAddr) {
469 const uint64_t AddrDelta = *LastFuncAddr - *BaseAddress;
470 if (AddrDelta <= UINT8_MAX)
471 return 1;
472 else if (AddrDelta <= UINT16_MAX)
473 return 2;
474 else if (AddrDelta <= UINT32_MAX)
475 return 4;
476 return 8;
477 }
478 return 1;
479}
480
481uint64_t GsymCreator::calculateHeaderAndTableSize() const {
482 uint64_t Size = sizeof(Header);
483 const size_t NumFuncs = Funcs.size();
484 // Add size of address offset table
485 Size += NumFuncs * getAddressOffsetSize();
486 // Add size of address info offsets which are 32 bit integers in version 1.
487 Size += NumFuncs * sizeof(uint32_t);
488 // Add file table size
489 Size += Files.size() * sizeof(FileEntry);
490 // Add string table size
491 Size += StrTab.getSize();
492
493 return Size;
494}
495
496// This function takes a InlineInfo class that was copy constructed from an
497// InlineInfo from the \a SrcGC and updates all members that point to strings
498// and files to point to strings and files from this GsymCreator.
499void GsymCreator::fixupInlineInfo(const GsymCreator &SrcGC, InlineInfo &II) {
500 II.Name = copyString(SrcGC, II.Name);
501 II.CallFile = copyFile(SrcGC, II.CallFile);
502 for (auto &ChildII: II.Children)
503 fixupInlineInfo(SrcGC, ChildII);
504}
505
506uint64_t GsymCreator::copyFunctionInfo(const GsymCreator &SrcGC, size_t FuncIdx) {
507 // To copy a function info we need to copy any files and strings over into
508 // this GsymCreator and then copy the function info and update the string
509 // table offsets to match the new offsets.
510 const FunctionInfo &SrcFI = SrcGC.Funcs[FuncIdx];
511
512 FunctionInfo DstFI;
513 DstFI.Range = SrcFI.Range;
514 DstFI.Name = copyString(SrcGC, SrcFI.Name);
515 // Copy the line table if there is one.
516 if (SrcFI.OptLineTable) {
517 // Copy the entire line table.
518 DstFI.OptLineTable = LineTable(SrcFI.OptLineTable.value());
519 // Fixup all LineEntry::File entries which are indexes in the the file table
520 // from SrcGC and must be converted to file indexes from this GsymCreator.
521 LineTable &DstLT = DstFI.OptLineTable.value();
522 const size_t NumLines = DstLT.size();
523 for (size_t I=0; I<NumLines; ++I) {
524 LineEntry &LE = DstLT.get(I);
525 LE.File = copyFile(SrcGC, LE.File);
526 }
527 }
528 // Copy the inline information if needed.
529 if (SrcFI.Inline) {
530 // Make a copy of the source inline information.
531 DstFI.Inline = SrcFI.Inline.value();
532 // Fixup all strings and files in the copied inline information.
533 fixupInlineInfo(SrcGC, *DstFI.Inline);
534 }
535 std::lock_guard<std::mutex> Guard(Mutex);
536 Funcs.emplace_back(DstFI);
537 return Funcs.back().cacheEncoding();
538}
539
540llvm::Error GsymCreator::saveSegments(StringRef Path,
541 llvm::endianness ByteOrder,
542 uint64_t SegmentSize) const {
543 if (SegmentSize == 0)
544 return createStringError(std::errc::invalid_argument,
545 "invalid segment size zero");
546
547 size_t FuncIdx = 0;
548 const size_t NumFuncs = Funcs.size();
549 while (FuncIdx < NumFuncs) {
551 createSegment(SegmentSize, FuncIdx);
552 if (ExpectedGC) {
553 GsymCreator *GC = ExpectedGC->get();
554 if (GC == NULL)
555 break; // We had not more functions to encode.
556 // Don't collect any messages at all
557 OutputAggregator Out(nullptr);
558 llvm::Error Err = GC->finalize(Out);
559 if (Err)
560 return Err;
561 std::string SegmentedGsymPath;
562 raw_string_ostream SGP(SegmentedGsymPath);
563 std::optional<uint64_t> FirstFuncAddr = GC->getFirstFunctionAddress();
564 if (FirstFuncAddr) {
565 SGP << Path << "-" << llvm::format_hex(*FirstFuncAddr, 1);
566 SGP.flush();
567 Err = GC->save(SegmentedGsymPath, ByteOrder, std::nullopt);
568 if (Err)
569 return Err;
570 }
571 } else {
572 return ExpectedGC.takeError();
573 }
574 }
575 return Error::success();
576}
577
579GsymCreator::createSegment(uint64_t SegmentSize, size_t &FuncIdx) const {
580 // No function entries, return empty unique pointer
581 if (FuncIdx >= Funcs.size())
582 return std::unique_ptr<GsymCreator>();
583
584 std::unique_ptr<GsymCreator> GC(new GsymCreator(/*Quiet=*/true));
585
586 // Tell the creator that this is a segment.
587 GC->setIsSegment();
588
589 // Set the base address if there is one.
590 if (BaseAddress)
591 GC->setBaseAddress(*BaseAddress);
592 // Copy the UUID value from this object into the new creator.
593 GC->setUUID(UUID);
594 const size_t NumFuncs = Funcs.size();
595 // Track how big the function infos are for the current segment so we can
596 // emit segments that are close to the requested size. It is quick math to
597 // determine the current header and tables sizes, so we can do that each loop.
598 uint64_t SegmentFuncInfosSize = 0;
599 for (; FuncIdx < NumFuncs; ++FuncIdx) {
600 const uint64_t HeaderAndTableSize = GC->calculateHeaderAndTableSize();
601 if (HeaderAndTableSize + SegmentFuncInfosSize >= SegmentSize) {
602 if (SegmentFuncInfosSize == 0)
603 return createStringError(std::errc::invalid_argument,
604 "a segment size of %" PRIu64 " is to small to "
605 "fit any function infos, specify a larger value",
606 SegmentSize);
607
608 break;
609 }
610 SegmentFuncInfosSize += alignTo(GC->copyFunctionInfo(*this, FuncIdx), 4);
611 }
612 return std::move(GC);
613}
#define offsetof(TYPE, MEMBER)
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint64_t Addr
uint64_t Size
#define I(x, y, z)
Definition: MD5.cpp:58
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
std::pair< llvm::MachO::Target, std::string > UUID
uint64_t start() const
Definition: AddressRanges.h:28
bool intersects(const AddressRange &R) const
Definition: AddressRanges.h:36
bool contains(uint64_t Addr) const
Definition: AddressRanges.h:32
uint64_t size() const
Definition: AddressRanges.h:30
A container which contains a StringRef plus a precomputed hash.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:211
Subclass of Error for the sole purpose of identifying the success path in the type system.
Definition: Error.h:335
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:337
Tagged union holding either a T or a Error.
Definition: Error.h:481
Error takeError()
Take ownership of the stored error.
Definition: Error.h:608
reference get()
Returns a reference to the stored T value.
Definition: Error.h:578
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:38
Utility for building string tables with deduplicated suffixes.
void finalizeInOrder()
Finalize the string table without reording it.
bool contains(StringRef S) const
Check if a string is contained in the string table.
void write(raw_ostream &OS) const
size_t add(CachedHashStringRef S)
Add a string to the builder.
llvm::Error loadYAML(StringRef YAMLFile)
This method reads the specified YAML file, parses its content, and updates the Funcs vector with call...
A simplified binary data writer class that doesn't require targets, target definitions,...
Definition: FileWriter.h:29
GsymCreator is used to emit GSYM data to a stand alone file or section within a file.
Definition: GsymCreator.h:134
void addFunctionInfo(FunctionInfo &&FI)
Add a function info to this GSYM creator.
uint32_t insertString(StringRef S, bool Copy=true)
Insert a string into the GSYM string table.
llvm::Expected< std::unique_ptr< GsymCreator > > createSegment(uint64_t SegmentSize, size_t &FuncIdx) const
Create a segmented GSYM creator starting with function info index FuncIdx.
llvm::Error save(StringRef Path, llvm::endianness ByteOrder, std::optional< uint64_t > SegmentSize=std::nullopt) const
Save a GSYM file to a stand alone file.
Definition: GsymCreator.cpp:68
void prepareMergedFunctions(OutputAggregator &Out)
Organize merged FunctionInfo's.
StringRef getString(uint32_t Offset)
Retrieve a string from the GSYM string table given its offset.
llvm::Error loadCallSitesFromYAML(StringRef YAMLFile)
Load call site information from a YAML file.
llvm::Error encode(FileWriter &O) const
Encode a GSYM into the file writer stream at the current position.
Definition: GsymCreator.cpp:80
llvm::Error finalize(OutputAggregator &OS)
Finalize the data in the GSYM creator prior to saving the data out.
uint32_t insertFile(StringRef Path, sys::path::Style Style=sys::path::Style::native)
Insert a file into this GSYM creator.
Definition: GsymCreator.cpp:29
size_t getNumFunctionInfos() const
Get the current number of FunctionInfo objects contained in this object.
bool IsValidTextAddress(uint64_t Addr) const
Check if an address is a valid code address.
void forEachFunctionInfo(std::function< bool(FunctionInfo &)> const &Callback)
Thread safe iteration over all function infos.
GsymCreator(bool Quiet=false)
Definition: GsymCreator.cpp:24
LineTable class contains deserialized versions of line tables for each function's address ranges.
Definition: LineTable.h:118
size_t size() const
Definition: LineTable.h:193
LineEntry & get(size_t i)
Definition: LineTable.h:196
void Report(StringRef s, std::function< void(raw_ostream &o)> detailCallback)
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:460
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:661
#define UINT64_MAX
Definition: DataTypes.h:77
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr uint32_t GSYM_MAGIC
Definition: Header.h:24
constexpr uint32_t GSYM_VERSION
Definition: Header.h:26
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Definition: Path.cpp:577
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
Definition: Path.cpp:467
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1291
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1664
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition: Format.h:187
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:111
endianness
Definition: bit.h:70
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:860
Files in GSYM are contained in FileEntry structs where we split the directory and basename into two d...
Definition: FileEntry.h:24
uint32_t Dir
Offsets in the string table.
Definition: FileEntry.h:28
Function information in GSYM files encodes information for one contiguous address range.
Definition: FunctionInfo.h:92
std::optional< InlineInfo > Inline
Definition: FunctionInfo.h:96
std::optional< MergedFunctionsInfo > MergedFunctions
Definition: FunctionInfo.h:97
bool hasRichInfo() const
Query if a FunctionInfo has rich debug info.
Definition: FunctionInfo.h:114
uint32_t Name
String table offset in the string table.
Definition: FunctionInfo.h:94
std::optional< LineTable > OptLineTable
Definition: FunctionInfo.h:95
The GSYM header.
Definition: Header.h:45
uint16_t Version
The version can number determines how the header is decoded and how each InfoType in FunctionInfo is ...
Definition: Header.h:54
uint8_t AddrOffSize
The size in bytes of each address offset in the address offsets table.
Definition: Header.h:56
uint32_t Magic
The magic bytes should be set to GSYM_MAGIC.
Definition: Header.h:49
llvm::Error encode(FileWriter &O) const
Encode this object into FileWriter stream.
Definition: Header.cpp:85
uint32_t StrtabOffset
The file relative offset of the start of the string table for strings contained in the GSYM file.
Definition: Header.h:72
uint8_t UUID[GSYM_MAX_UUID_SIZE]
The UUID of the original executable file.
Definition: Header.h:86
uint32_t StrtabSize
The size in bytes of the string table.
Definition: Header.h:80
uint8_t UUIDSize
The size in bytes of the UUID encoded in the "UUID" member.
Definition: Header.h:58
uint32_t NumAddresses
The number of addresses stored in the address offsets table.
Definition: Header.h:64
uint64_t BaseAddress
The 64 bit base address that all address offsets in the address offsets table are relative to.
Definition: Header.h:62
Inline information stores the name of the inline function along with an array of address ranges.
Definition: InlineInfo.h:59
Line entries are used to encode the line tables in FunctionInfo objects.
Definition: LineEntry.h:22