LLVM 17.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
14
15#include <algorithm>
16#include <cassert>
17#include <functional>
18#include <vector>
19
20using namespace llvm;
21using namespace gsym;
22
24 : StrTab(StringTableBuilder::ELF), Quiet(Quiet) {
26}
27
29 llvm::StringRef directory = llvm::sys::path::parent_path(Path, Style);
30 llvm::StringRef filename = llvm::sys::path::filename(Path, Style);
31 // We must insert the strings first, then call the FileEntry constructor.
32 // If we inline the insertString() function call into the constructor, the
33 // call order is undefined due to parameter lists not having any ordering
34 // requirements.
35 const uint32_t Dir = insertString(directory);
36 const uint32_t Base = insertString(filename);
37 return insertFileEntry(FileEntry(Dir, Base));
38}
39
40uint32_t GsymCreator::insertFileEntry(FileEntry FE) {
41 std::lock_guard<std::mutex> Guard(Mutex);
42 const auto NextIndex = Files.size();
43 // Find FE in hash map and insert if not present.
44 auto R = FileEntryToIndex.insert(std::make_pair(FE, NextIndex));
45 if (R.second)
46 Files.emplace_back(FE);
47 return R.first->second;
48}
49
50uint32_t GsymCreator::copyFile(const GsymCreator &SrcGC, uint32_t FileIdx) {
51 // File index zero is reserved for a FileEntry with no directory and no
52 // filename. Any other file and we need to copy the strings for the directory
53 // and filename.
54 if (FileIdx == 0)
55 return 0;
56 const FileEntry SrcFE = SrcGC.Files[FileIdx];
57 // Copy the strings for the file and then add the newly converted file entry.
58 uint32_t Dir = StrTab.add(SrcGC.StringOffsetMap.find(SrcFE.Dir)->second);
59 uint32_t Base = StrTab.add(SrcGC.StringOffsetMap.find(SrcFE.Base)->second);
60 FileEntry DstFE(Dir, Base);
61 return insertFileEntry(DstFE);
62}
63
64
67 std::optional<uint64_t> SegmentSize) const {
68 if (SegmentSize)
69 return saveSegments(Path, ByteOrder, *SegmentSize);
70 std::error_code EC;
71 raw_fd_ostream OutStrm(Path, EC);
72 if (EC)
73 return llvm::errorCodeToError(EC);
74 FileWriter O(OutStrm, ByteOrder);
75 return encode(O);
76}
77
79 std::lock_guard<std::mutex> Guard(Mutex);
80 if (Funcs.empty())
81 return createStringError(std::errc::invalid_argument,
82 "no functions to encode");
83 if (!Finalized)
84 return createStringError(std::errc::invalid_argument,
85 "GsymCreator wasn't finalized prior to encoding");
86
87 if (Funcs.size() > UINT32_MAX)
88 return createStringError(std::errc::invalid_argument,
89 "too many FunctionInfos");
90
91 std::optional<uint64_t> BaseAddress = getBaseAddress();
92 // Base address should be valid if we have any functions.
93 if (!BaseAddress)
94 return createStringError(std::errc::invalid_argument,
95 "invalid base address");
96 Header Hdr;
97 Hdr.Magic = GSYM_MAGIC;
99 Hdr.AddrOffSize = getAddressOffsetSize();
100 Hdr.UUIDSize = static_cast<uint8_t>(UUID.size());
101 Hdr.BaseAddress = *BaseAddress;
102 Hdr.NumAddresses = static_cast<uint32_t>(Funcs.size());
103 Hdr.StrtabOffset = 0; // We will fix this up later.
104 Hdr.StrtabSize = 0; // We will fix this up later.
105 memset(Hdr.UUID, 0, sizeof(Hdr.UUID));
106 if (UUID.size() > sizeof(Hdr.UUID))
107 return createStringError(std::errc::invalid_argument,
108 "invalid UUID size %u", (uint32_t)UUID.size());
109 // Copy the UUID value if we have one.
110 if (UUID.size() > 0)
111 memcpy(Hdr.UUID, UUID.data(), UUID.size());
112 // Write out the header.
113 llvm::Error Err = Hdr.encode(O);
114 if (Err)
115 return Err;
116
117 const uint64_t MaxAddressOffset = getMaxAddressOffset();
118 // Write out the address offsets.
119 O.alignTo(Hdr.AddrOffSize);
120 for (const auto &FuncInfo : Funcs) {
121 uint64_t AddrOffset = FuncInfo.startAddress() - Hdr.BaseAddress;
122 // Make sure we calculated the address offsets byte size correctly by
123 // verifying the current address offset is within ranges. We have seen bugs
124 // introduced when the code changes that can cause problems here so it is
125 // good to catch this during testing.
126 assert(AddrOffset <= MaxAddressOffset);
127 (void)MaxAddressOffset;
128 switch (Hdr.AddrOffSize) {
129 case 1:
130 O.writeU8(static_cast<uint8_t>(AddrOffset));
131 break;
132 case 2:
133 O.writeU16(static_cast<uint16_t>(AddrOffset));
134 break;
135 case 4:
136 O.writeU32(static_cast<uint32_t>(AddrOffset));
137 break;
138 case 8:
139 O.writeU64(AddrOffset);
140 break;
141 }
142 }
143
144 // Write out all zeros for the AddrInfoOffsets.
145 O.alignTo(4);
146 const off_t AddrInfoOffsetsOffset = O.tell();
147 for (size_t i = 0, n = Funcs.size(); i < n; ++i)
148 O.writeU32(0);
149
150 // Write out the file table
151 O.alignTo(4);
152 assert(!Files.empty());
153 assert(Files[0].Dir == 0);
154 assert(Files[0].Base == 0);
155 size_t NumFiles = Files.size();
156 if (NumFiles > UINT32_MAX)
157 return createStringError(std::errc::invalid_argument, "too many files");
158 O.writeU32(static_cast<uint32_t>(NumFiles));
159 for (auto File : Files) {
160 O.writeU32(File.Dir);
161 O.writeU32(File.Base);
162 }
163
164 // Write out the string table.
165 const off_t StrtabOffset = O.tell();
166 StrTab.write(O.get_stream());
167 const off_t StrtabSize = O.tell() - StrtabOffset;
168 std::vector<uint32_t> AddrInfoOffsets;
169
170 // Write out the address infos for each function info.
171 for (const auto &FuncInfo : Funcs) {
172 if (Expected<uint64_t> OffsetOrErr = FuncInfo.encode(O))
173 AddrInfoOffsets.push_back(OffsetOrErr.get());
174 else
175 return OffsetOrErr.takeError();
176 }
177 // Fixup the string table offset and size in the header
178 O.fixup32((uint32_t)StrtabOffset, offsetof(Header, StrtabOffset));
179 O.fixup32((uint32_t)StrtabSize, offsetof(Header, StrtabSize));
180
181 // Fixup all address info offsets
182 uint64_t Offset = 0;
183 for (auto AddrInfoOffset : AddrInfoOffsets) {
184 O.fixup32(AddrInfoOffset, AddrInfoOffsetsOffset + Offset);
185 Offset += 4;
186 }
187 return ErrorSuccess();
188}
189
190// Similar to std::remove_if, but the predicate is binary and it is passed both
191// the previous and the current element.
192template <class ForwardIt, class BinaryPredicate>
193static ForwardIt removeIfBinary(ForwardIt FirstIt, ForwardIt LastIt,
194 BinaryPredicate Pred) {
195 if (FirstIt != LastIt) {
196 auto PrevIt = FirstIt++;
197 FirstIt = std::find_if(FirstIt, LastIt, [&](const auto &Curr) {
198 return Pred(*PrevIt++, Curr);
199 });
200 if (FirstIt != LastIt)
201 for (ForwardIt CurrIt = FirstIt; ++CurrIt != LastIt;)
202 if (!Pred(*PrevIt, *CurrIt)) {
203 PrevIt = FirstIt;
204 *FirstIt++ = std::move(*CurrIt);
205 }
206 }
207 return FirstIt;
208}
209
211 std::lock_guard<std::mutex> Guard(Mutex);
212 if (Finalized)
213 return createStringError(std::errc::invalid_argument, "already finalized");
214 Finalized = true;
215
216 // Sort function infos so we can emit sorted functions.
217 llvm::sort(Funcs);
218
219 // Don't let the string table indexes change by finalizing in order.
220 StrTab.finalizeInOrder();
221
222 // Remove duplicates function infos that have both entries from debug info
223 // (DWARF or Breakpad) and entries from the SymbolTable.
224 //
225 // Also handle overlapping function. Usually there shouldn't be any, but they
226 // can and do happen in some rare cases.
227 //
228 // (a) (b) (c)
229 // ^ ^ ^ ^
230 // |X |Y |X ^ |X
231 // | | | |Y | ^
232 // | | | v v |Y
233 // v v v v
234 //
235 // In (a) and (b), Y is ignored and X will be reported for the full range.
236 // In (c), both functions will be included in the result and lookups for an
237 // address in the intersection will return Y because of binary search.
238 //
239 // Note that in case of (b), we cannot include Y in the result because then
240 // we wouldn't find any function for range (end of Y, end of X)
241 // with binary search
242 auto NumBefore = Funcs.size();
243 Funcs.erase(
244 removeIfBinary(Funcs.begin(), Funcs.end(),
245 [&](const auto &Prev, const auto &Curr) {
246 // Empty ranges won't intersect, but we still need to
247 // catch the case where we have multiple symbols at the
248 // same address and coalesce them.
249 const bool ranges_equal = Prev.Range == Curr.Range;
250 if (ranges_equal || Prev.Range.intersects(Curr.Range)) {
251 // Overlapping ranges or empty identical ranges.
252 if (ranges_equal) {
253 // Same address range. Check if one is from debug
254 // info and the other is from a symbol table. If
255 // so, then keep the one with debug info. Our
256 // sorting guarantees that entries with matching
257 // address ranges that have debug info are last in
258 // the sort.
259 if (Prev == Curr) {
260 // FunctionInfo entries match exactly (range,
261 // lines, inlines)
262
263 // We used to output a warning here, but this was
264 // so frequent on some binaries, in particular
265 // when those were built with GCC, that it slowed
266 // down processing extremely.
267 return true;
268 } else {
269 if (!Prev.hasRichInfo() && Curr.hasRichInfo()) {
270 // Same address range, one with no debug info
271 // (symbol) and the next with debug info. Keep
272 // the latter.
273 return true;
274 } else {
275 if (!Quiet) {
276 OS << "warning: same address range contains "
277 "different debug "
278 << "info. Removing:\n"
279 << Prev << "\nIn favor of this one:\n"
280 << Curr << "\n";
281 }
282 return true;
283 }
284 }
285 } else {
286 if (!Quiet) { // print warnings about overlaps
287 OS << "warning: function ranges overlap:\n"
288 << Prev << "\n"
289 << Curr << "\n";
290 }
291 }
292 } else if (Prev.Range.size() == 0 &&
293 Curr.Range.contains(Prev.Range.start())) {
294 if (!Quiet) {
295 OS << "warning: removing symbol:\n"
296 << Prev << "\nKeeping:\n"
297 << Curr << "\n";
298 }
299 return true;
300 }
301
302 return false;
303 }),
304 Funcs.end());
305
306 // If our last function info entry doesn't have a size and if we have valid
307 // text ranges, we should set the size of the last entry since any search for
308 // a high address might match our last entry. By fixing up this size, we can
309 // help ensure we don't cause lookups to always return the last symbol that
310 // has no size when doing lookups.
311 if (!Funcs.empty() && Funcs.back().Range.size() == 0 && ValidTextRanges) {
312 if (auto Range =
313 ValidTextRanges->getRangeThatContains(Funcs.back().Range.start())) {
314 Funcs.back().Range = {Funcs.back().Range.start(), Range->end()};
315 }
316 }
317 OS << "Pruned " << NumBefore - Funcs.size() << " functions, ended with "
318 << Funcs.size() << " total\n";
319 return Error::success();
320}
321
322uint32_t GsymCreator::copyString(const GsymCreator &SrcGC, uint32_t StrOff) {
323 // String offset at zero is always the empty string, no copying needed.
324 if (StrOff == 0)
325 return 0;
326 return StrTab.add(SrcGC.StringOffsetMap.find(StrOff)->second);
327}
328
330 if (S.empty())
331 return 0;
332
333 // The hash can be calculated outside the lock.
334 CachedHashStringRef CHStr(S);
335 std::lock_guard<std::mutex> Guard(Mutex);
336 if (Copy) {
337 // We need to provide backing storage for the string if requested
338 // since StringTableBuilder stores references to strings. Any string
339 // that comes from a section in an object file doesn't need to be
340 // copied, but any string created by code will need to be copied.
341 // This allows GsymCreator to be really fast when parsing DWARF and
342 // other object files as most strings don't need to be copied.
343 if (!StrTab.contains(CHStr))
344 CHStr = CachedHashStringRef{StringStorage.insert(S).first->getKey(),
345 CHStr.hash()};
346 }
347 const uint32_t StrOff = StrTab.add(CHStr);
348 // Save a mapping of string offsets to the cached string reference in case
349 // we need to segment the GSYM file and copy string from one string table to
350 // another.
351 if (StringOffsetMap.count(StrOff) == 0)
352 StringOffsetMap.insert(std::make_pair(StrOff, CHStr));
353 return StrOff;
354}
355
357 std::lock_guard<std::mutex> Guard(Mutex);
358 Ranges.insert(FI.Range);
359 Funcs.emplace_back(std::move(FI));
360}
361
363 std::function<bool(FunctionInfo &)> const &Callback) {
364 std::lock_guard<std::mutex> Guard(Mutex);
365 for (auto &FI : Funcs) {
366 if (!Callback(FI))
367 break;
368 }
369}
370
372 std::function<bool(const FunctionInfo &)> const &Callback) const {
373 std::lock_guard<std::mutex> Guard(Mutex);
374 for (const auto &FI : Funcs) {
375 if (!Callback(FI))
376 break;
377 }
378}
379
381 std::lock_guard<std::mutex> Guard(Mutex);
382 return Funcs.size();
383}
384
386 if (ValidTextRanges)
387 return ValidTextRanges->contains(Addr);
388 return true; // No valid text ranges has been set, so accept all ranges.
389}
390
392 std::lock_guard<std::mutex> Guard(Mutex);
393 return Ranges.contains(Addr);
394}
395
396std::optional<uint64_t> GsymCreator::getFirstFunctionAddress() const {
397 if (Finalized && !Funcs.empty())
398 return std::optional<uint64_t>(Funcs.front().startAddress());
399 // This code gets used by the segmentation of GSYM files to help determine the
400 // size of the GSYM header while continually adding new FunctionInfo objects
401 // to this object, so we haven't finalized this object yet.
402 if (Ranges.empty())
403 return std::nullopt;
404 return std::optional<uint64_t>(Ranges.begin()->start());
405}
406
407std::optional<uint64_t> GsymCreator::getLastFunctionAddress() const {
408 if (Finalized && !Funcs.empty())
409 return std::optional<uint64_t>(Funcs.back().startAddress());
410 // This code gets used by the segmentation of GSYM files to help determine the
411 // size of the GSYM header while continually adding new FunctionInfo objects
412 // to this object, so we haven't finalized this object yet.
413 if (Ranges.empty())
414 return std::nullopt;
415 return std::optional<uint64_t>((Ranges.end() - 1)->end());
416}
417
418std::optional<uint64_t> GsymCreator::getBaseAddress() const {
419 if (BaseAddress)
420 return BaseAddress;
421 return getFirstFunctionAddress();
422}
423
424uint64_t GsymCreator::getMaxAddressOffset() const {
425 switch (getAddressOffsetSize()) {
426 case 1: return UINT8_MAX;
427 case 2: return UINT16_MAX;
428 case 4: return UINT32_MAX;
429 case 8: return UINT64_MAX;
430 }
431 llvm_unreachable("invalid address offset");
432}
433
434uint8_t GsymCreator::getAddressOffsetSize() const {
435 const std::optional<uint64_t> BaseAddress = getBaseAddress();
436 const std::optional<uint64_t> LastFuncAddr = getLastFunctionAddress();
437 if (BaseAddress && LastFuncAddr) {
438 const uint64_t AddrDelta = *LastFuncAddr - *BaseAddress;
439 if (AddrDelta <= UINT8_MAX)
440 return 1;
441 else if (AddrDelta <= UINT16_MAX)
442 return 2;
443 else if (AddrDelta <= UINT32_MAX)
444 return 4;
445 return 8;
446 }
447 return 1;
448}
449
450uint64_t GsymCreator::calculateHeaderAndTableSize() const {
451 uint64_t Size = sizeof(Header);
452 const size_t NumFuncs = Funcs.size();
453 // Add size of address offset table
454 Size += NumFuncs * getAddressOffsetSize();
455 // Add size of address info offsets which are 32 bit integers in version 1.
456 Size += NumFuncs * sizeof(uint32_t);
457 // Add file table size
458 Size += Files.size() * sizeof(FileEntry);
459 // Add string table size
460 Size += StrTab.getSize();
461
462 return Size;
463}
464
465// This function takes a InlineInfo class that was copy constructed from an
466// InlineInfo from the \a SrcGC and updates all members that point to strings
467// and files to point to strings and files from this GsymCreator.
468void GsymCreator::fixupInlineInfo(const GsymCreator &SrcGC, InlineInfo &II) {
469 II.Name = copyString(SrcGC, II.Name);
470 II.CallFile = copyFile(SrcGC, II.CallFile);
471 for (auto &ChildII: II.Children)
472 fixupInlineInfo(SrcGC, ChildII);
473}
474
475uint64_t GsymCreator::copyFunctionInfo(const GsymCreator &SrcGC, size_t FuncIdx) {
476 // To copy a function info we need to copy any files and strings over into
477 // this GsymCreator and then copy the function info and update the string
478 // table offsets to match the new offsets.
479 const FunctionInfo &SrcFI = SrcGC.Funcs[FuncIdx];
480 Ranges.insert(SrcFI.Range);
481
482 FunctionInfo DstFI;
483 DstFI.Range = SrcFI.Range;
484 DstFI.Name = copyString(SrcGC, SrcFI.Name);
485 // Copy the line table if there is one.
486 if (SrcFI.OptLineTable) {
487 // Copy the entire line table.
488 DstFI.OptLineTable = LineTable(SrcFI.OptLineTable.value());
489 // Fixup all LineEntry::File entries which are indexes in the the file table
490 // from SrcGC and must be converted to file indexes from this GsymCreator.
491 LineTable &DstLT = DstFI.OptLineTable.value();
492 const size_t NumLines = DstLT.size();
493 for (size_t I=0; I<NumLines; ++I) {
494 LineEntry &LE = DstLT.get(I);
495 LE.File = copyFile(SrcGC, LE.File);
496 }
497 }
498 // Copy the inline information if needed.
499 if (SrcFI.Inline) {
500 // Make a copy of the source inline information.
501 DstFI.Inline = SrcFI.Inline.value();
502 // Fixup all strings and files in the copied inline information.
503 fixupInlineInfo(SrcGC, *DstFI.Inline);
504 }
505 std::lock_guard<std::mutex> Guard(Mutex);
506 Funcs.push_back(DstFI);
507 return Funcs.back().cacheEncoding();
508}
509
510llvm::Error GsymCreator::saveSegments(StringRef Path,
512 uint64_t SegmentSize) const {
513 if (SegmentSize == 0)
514 return createStringError(std::errc::invalid_argument,
515 "invalid segment size zero");
516
517 size_t FuncIdx = 0;
518 const size_t NumFuncs = Funcs.size();
519 while (FuncIdx < NumFuncs) {
521 createSegment(SegmentSize, FuncIdx);
522 if (ExpectedGC) {
523 GsymCreator *GC = ExpectedGC->get();
524 if (GC == NULL)
525 break; // We had not more functions to encode.
526 raw_null_ostream ErrorStrm;
527 llvm::Error Err = GC->finalize(ErrorStrm);
528 if (Err)
529 return Err;
530 std::string SegmentedGsymPath;
531 raw_string_ostream SGP(SegmentedGsymPath);
532 std::optional<uint64_t> FirstFuncAddr = GC->getFirstFunctionAddress();
533 if (FirstFuncAddr) {
534 SGP << Path << "-" << llvm::format_hex(*FirstFuncAddr, 1);
535 SGP.flush();
536 Err = GC->save(SegmentedGsymPath, ByteOrder, std::nullopt);
537 if (Err)
538 return Err;
539 }
540 } else {
541 return ExpectedGC.takeError();
542 }
543 }
544 return Error::success();
545}
546
548GsymCreator::createSegment(uint64_t SegmentSize, size_t &FuncIdx) const {
549 // No function entries, return empty unique pointer
550 if (FuncIdx >= Funcs.size())
551 return std::unique_ptr<GsymCreator>();
552
553 std::unique_ptr<GsymCreator> GC(new GsymCreator(/*Quiet=*/true));
554 // Set the base address if there is one.
555 if (BaseAddress)
556 GC->setBaseAddress(*BaseAddress);
557 // Copy the UUID value from this object into the new creator.
558 GC->setUUID(UUID);
559 const size_t NumFuncs = Funcs.size();
560 // Track how big the function infos are for the current segment so we can
561 // emit segments that are close to the requested size. It is quick math to
562 // determine the current header and tables sizes, so we can do that each loop.
563 uint64_t SegmentFuncInfosSize = 0;
564 for (; FuncIdx < NumFuncs; ++FuncIdx) {
565 const uint64_t HeaderAndTableSize = GC->calculateHeaderAndTableSize();
566 if (HeaderAndTableSize + SegmentFuncInfosSize >= SegmentSize) {
567 if (SegmentFuncInfosSize == 0)
568 return createStringError(std::errc::invalid_argument,
569 "a segment size of %" PRIu64 " is to small to "
570 "fit any function infos, specify a larger value",
571 SegmentSize);
572
573 break;
574 }
575 SegmentFuncInfosSize += alignTo(GC->copyFunctionInfo(*this, FuncIdx), 4);
576 }
577 return std::move(GC);
578}
#define offsetof(TYPE, MEMBER)
uint64_t Addr
uint64_t Size
static ForwardIt removeIfBinary(ForwardIt FirstIt, ForwardIt LastIt, BinaryPredicate Pred)
#define I(x, y, z)
Definition: MD5.cpp:58
typename CallsiteContextGraph< DerivedCCG, FuncTy, CallTy >::FuncInfo FuncInfo
if(VerifyEach)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
raw_pwrite_stream & OS
std::pair< llvm::MachO::Target, std::string > UUID
bool contains(uint64_t Addr) const
Definition: AddressRanges.h:66
Collection::const_iterator end() const
Definition: AddressRanges.h:84
Collection::const_iterator begin() const
Definition: AddressRanges.h:83
Collection::const_iterator insert(AddressRange Range)
A container which contains a StringRef plus a precomputed hash.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:220
Subclass of Error for the sole purpose of identifying the success path in the type system.
Definition: Error.h:328
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
static ErrorSuccess success()
Create a success value.
Definition: Error.h:330
Tagged union holding either a T or a Error.
Definition: Error.h:470
Error takeError()
Take ownership of the stored error.
Definition: Error.h:597
reference get()
Returns a reference to the stored T value.
Definition: Error.h:567
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
std::pair< typename Base::iterator, bool > insert(StringRef key)
Definition: StringSet.h:34
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.
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:133
void addFunctionInfo(FunctionInfo &&FI)
Add a function info to this GSYM creator.
bool hasFunctionInfoForAddress(uint64_t Addr) const
Check if an address has already been added as a function info.
uint32_t insertString(StringRef S, bool Copy=true)
Insert a string into the GSYM string table.
llvm::Error finalize(llvm::raw_ostream &OS)
Finalize the data in the GSYM creator prior to saving the data out.
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 encode(FileWriter &O) const
Encode a GSYM into the file writer stream at the current position.
Definition: GsymCreator.cpp:78
llvm::Error save(StringRef Path, llvm::support::endianness ByteOrder, std::optional< uint64_t > SegmentSize=std::nullopt) const
Save a GSYM file to a stand alone file.
Definition: GsymCreator.cpp:65
uint32_t insertFile(StringRef Path, sys::path::Style Style=sys::path::Style::native)
Insert a file into this GSYM creator.
Definition: GsymCreator.cpp:28
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:23
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
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:454
A raw_ostream that discards all output.
Definition: raw_ostream.h:705
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:642
#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:406
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1246
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1744
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
Definition: Format.h:186
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:92
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:88
std::optional< InlineInfo > Inline
Definition: FunctionInfo.h:92
uint32_t Name
String table offset in the string table.
Definition: FunctionInfo.h:90
std::optional< LineTable > OptLineTable
Definition: FunctionInfo.h:91
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
std::vector< InlineInfo > Children
Definition: InlineInfo.h:65
uint32_t CallFile
1 based file index in the file table.
Definition: InlineInfo.h:62
uint32_t Name
String table offset in the string table.
Definition: InlineInfo.h:61
Line entries are used to encode the line tables in FunctionInfo objects.
Definition: LineEntry.h:22