LLVM 18.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
191 std::lock_guard<std::mutex> Guard(Mutex);
192 if (Finalized)
193 return createStringError(std::errc::invalid_argument, "already finalized");
194 Finalized = true;
195
196 // Don't let the string table indexes change by finalizing in order.
197 StrTab.finalizeInOrder();
198
199 // Remove duplicates function infos that have both entries from debug info
200 // (DWARF or Breakpad) and entries from the SymbolTable.
201 //
202 // Also handle overlapping function. Usually there shouldn't be any, but they
203 // can and do happen in some rare cases.
204 //
205 // (a) (b) (c)
206 // ^ ^ ^ ^
207 // |X |Y |X ^ |X
208 // | | | |Y | ^
209 // | | | v v |Y
210 // v v v v
211 //
212 // In (a) and (b), Y is ignored and X will be reported for the full range.
213 // In (c), both functions will be included in the result and lookups for an
214 // address in the intersection will return Y because of binary search.
215 //
216 // Note that in case of (b), we cannot include Y in the result because then
217 // we wouldn't find any function for range (end of Y, end of X)
218 // with binary search
219
220 const auto NumBefore = Funcs.size();
221 // Only sort and unique if this isn't a segment. If this is a segment we
222 // already finalized the main GsymCreator with all of the function infos
223 // and then the already sorted and uniqued function infos were added to this
224 // object.
225 if (!IsSegment) {
226 if (NumBefore > 1) {
227 // Sort function infos so we can emit sorted functions.
228 llvm::sort(Funcs);
229 std::vector<FunctionInfo> FinalizedFuncs;
230 FinalizedFuncs.reserve(Funcs.size());
231 FinalizedFuncs.emplace_back(std::move(Funcs.front()));
232 for (size_t Idx=1; Idx < NumBefore; ++Idx) {
233 FunctionInfo &Prev = FinalizedFuncs.back();
234 FunctionInfo &Curr = Funcs[Idx];
235 // Empty ranges won't intersect, but we still need to
236 // catch the case where we have multiple symbols at the
237 // same address and coalesce them.
238 const bool ranges_equal = Prev.Range == Curr.Range;
239 if (ranges_equal || Prev.Range.intersects(Curr.Range)) {
240 // Overlapping ranges or empty identical ranges.
241 if (ranges_equal) {
242 // Same address range. Check if one is from debug
243 // info and the other is from a symbol table. If
244 // so, then keep the one with debug info. Our
245 // sorting guarantees that entries with matching
246 // address ranges that have debug info are last in
247 // the sort.
248 if (!(Prev == Curr)) {
249 if (Prev.hasRichInfo() && Curr.hasRichInfo()) {
250 if (!Quiet) {
251 OS << "warning: same address range contains "
252 "different debug "
253 << "info. Removing:\n"
254 << Prev << "\nIn favor of this one:\n"
255 << Curr << "\n";
256 }
257 }
258 // We want to swap the current entry with the previous since
259 // later entries with the same range always have more debug info
260 // or different debug info.
261 std::swap(Prev, Curr);
262 }
263 } else {
264 if (!Quiet) { // print warnings about overlaps
265 OS << "warning: function ranges overlap:\n"
266 << Prev << "\n"
267 << Curr << "\n";
268 }
269 FinalizedFuncs.emplace_back(std::move(Curr));
270 }
271 } else {
272 if (Prev.Range.size() == 0 && Curr.Range.contains(Prev.Range.start())) {
273 // Symbols on macOS don't have address ranges, so if the range
274 // doesn't match and the size is zero, then we replace the empty
275 // symbol function info with the current one.
276 std::swap(Prev, Curr);
277 } else {
278 FinalizedFuncs.emplace_back(std::move(Curr));
279 }
280 }
281 }
282 std::swap(Funcs, FinalizedFuncs);
283 }
284 // If our last function info entry doesn't have a size and if we have valid
285 // text ranges, we should set the size of the last entry since any search for
286 // a high address might match our last entry. By fixing up this size, we can
287 // help ensure we don't cause lookups to always return the last symbol that
288 // has no size when doing lookups.
289 if (!Funcs.empty() && Funcs.back().Range.size() == 0 && ValidTextRanges) {
290 if (auto Range =
291 ValidTextRanges->getRangeThatContains(Funcs.back().Range.start())) {
292 Funcs.back().Range = {Funcs.back().Range.start(), Range->end()};
293 }
294 }
295 OS << "Pruned " << NumBefore - Funcs.size() << " functions, ended with "
296 << Funcs.size() << " total\n";
297 }
298 return Error::success();
299}
300
301uint32_t GsymCreator::copyString(const GsymCreator &SrcGC, uint32_t StrOff) {
302 // String offset at zero is always the empty string, no copying needed.
303 if (StrOff == 0)
304 return 0;
305 return StrTab.add(SrcGC.StringOffsetMap.find(StrOff)->second);
306}
307
309 if (S.empty())
310 return 0;
311
312 // The hash can be calculated outside the lock.
313 CachedHashStringRef CHStr(S);
314 std::lock_guard<std::mutex> Guard(Mutex);
315 if (Copy) {
316 // We need to provide backing storage for the string if requested
317 // since StringTableBuilder stores references to strings. Any string
318 // that comes from a section in an object file doesn't need to be
319 // copied, but any string created by code will need to be copied.
320 // This allows GsymCreator to be really fast when parsing DWARF and
321 // other object files as most strings don't need to be copied.
322 if (!StrTab.contains(CHStr))
323 CHStr = CachedHashStringRef{StringStorage.insert(S).first->getKey(),
324 CHStr.hash()};
325 }
326 const uint32_t StrOff = StrTab.add(CHStr);
327 // Save a mapping of string offsets to the cached string reference in case
328 // we need to segment the GSYM file and copy string from one string table to
329 // another.
330 if (StringOffsetMap.count(StrOff) == 0)
331 StringOffsetMap.insert(std::make_pair(StrOff, CHStr));
332 return StrOff;
333}
334
336 std::lock_guard<std::mutex> Guard(Mutex);
337 Funcs.emplace_back(std::move(FI));
338}
339
341 std::function<bool(FunctionInfo &)> const &Callback) {
342 std::lock_guard<std::mutex> Guard(Mutex);
343 for (auto &FI : Funcs) {
344 if (!Callback(FI))
345 break;
346 }
347}
348
350 std::function<bool(const FunctionInfo &)> const &Callback) const {
351 std::lock_guard<std::mutex> Guard(Mutex);
352 for (const auto &FI : Funcs) {
353 if (!Callback(FI))
354 break;
355 }
356}
357
359 std::lock_guard<std::mutex> Guard(Mutex);
360 return Funcs.size();
361}
362
364 if (ValidTextRanges)
365 return ValidTextRanges->contains(Addr);
366 return true; // No valid text ranges has been set, so accept all ranges.
367}
368
369std::optional<uint64_t> GsymCreator::getFirstFunctionAddress() const {
370 // If we have finalized then Funcs are sorted. If we are a segment then
371 // Funcs will be sorted as well since function infos get added from an
372 // already finalized GsymCreator object where its functions were sorted and
373 // uniqued.
374 if ((Finalized || IsSegment) && !Funcs.empty())
375 return std::optional<uint64_t>(Funcs.front().startAddress());
376 return std::nullopt;
377}
378
379std::optional<uint64_t> GsymCreator::getLastFunctionAddress() const {
380 // If we have finalized then Funcs are sorted. If we are a segment then
381 // Funcs will be sorted as well since function infos get added from an
382 // already finalized GsymCreator object where its functions were sorted and
383 // uniqued.
384 if ((Finalized || IsSegment) && !Funcs.empty())
385 return std::optional<uint64_t>(Funcs.back().startAddress());
386 return std::nullopt;
387}
388
389std::optional<uint64_t> GsymCreator::getBaseAddress() const {
390 if (BaseAddress)
391 return BaseAddress;
392 return getFirstFunctionAddress();
393}
394
395uint64_t GsymCreator::getMaxAddressOffset() const {
396 switch (getAddressOffsetSize()) {
397 case 1: return UINT8_MAX;
398 case 2: return UINT16_MAX;
399 case 4: return UINT32_MAX;
400 case 8: return UINT64_MAX;
401 }
402 llvm_unreachable("invalid address offset");
403}
404
405uint8_t GsymCreator::getAddressOffsetSize() const {
406 const std::optional<uint64_t> BaseAddress = getBaseAddress();
407 const std::optional<uint64_t> LastFuncAddr = getLastFunctionAddress();
408 if (BaseAddress && LastFuncAddr) {
409 const uint64_t AddrDelta = *LastFuncAddr - *BaseAddress;
410 if (AddrDelta <= UINT8_MAX)
411 return 1;
412 else if (AddrDelta <= UINT16_MAX)
413 return 2;
414 else if (AddrDelta <= UINT32_MAX)
415 return 4;
416 return 8;
417 }
418 return 1;
419}
420
421uint64_t GsymCreator::calculateHeaderAndTableSize() const {
422 uint64_t Size = sizeof(Header);
423 const size_t NumFuncs = Funcs.size();
424 // Add size of address offset table
425 Size += NumFuncs * getAddressOffsetSize();
426 // Add size of address info offsets which are 32 bit integers in version 1.
427 Size += NumFuncs * sizeof(uint32_t);
428 // Add file table size
429 Size += Files.size() * sizeof(FileEntry);
430 // Add string table size
431 Size += StrTab.getSize();
432
433 return Size;
434}
435
436// This function takes a InlineInfo class that was copy constructed from an
437// InlineInfo from the \a SrcGC and updates all members that point to strings
438// and files to point to strings and files from this GsymCreator.
439void GsymCreator::fixupInlineInfo(const GsymCreator &SrcGC, InlineInfo &II) {
440 II.Name = copyString(SrcGC, II.Name);
441 II.CallFile = copyFile(SrcGC, II.CallFile);
442 for (auto &ChildII: II.Children)
443 fixupInlineInfo(SrcGC, ChildII);
444}
445
446uint64_t GsymCreator::copyFunctionInfo(const GsymCreator &SrcGC, size_t FuncIdx) {
447 // To copy a function info we need to copy any files and strings over into
448 // this GsymCreator and then copy the function info and update the string
449 // table offsets to match the new offsets.
450 const FunctionInfo &SrcFI = SrcGC.Funcs[FuncIdx];
451
452 FunctionInfo DstFI;
453 DstFI.Range = SrcFI.Range;
454 DstFI.Name = copyString(SrcGC, SrcFI.Name);
455 // Copy the line table if there is one.
456 if (SrcFI.OptLineTable) {
457 // Copy the entire line table.
458 DstFI.OptLineTable = LineTable(SrcFI.OptLineTable.value());
459 // Fixup all LineEntry::File entries which are indexes in the the file table
460 // from SrcGC and must be converted to file indexes from this GsymCreator.
461 LineTable &DstLT = DstFI.OptLineTable.value();
462 const size_t NumLines = DstLT.size();
463 for (size_t I=0; I<NumLines; ++I) {
464 LineEntry &LE = DstLT.get(I);
465 LE.File = copyFile(SrcGC, LE.File);
466 }
467 }
468 // Copy the inline information if needed.
469 if (SrcFI.Inline) {
470 // Make a copy of the source inline information.
471 DstFI.Inline = SrcFI.Inline.value();
472 // Fixup all strings and files in the copied inline information.
473 fixupInlineInfo(SrcGC, *DstFI.Inline);
474 }
475 std::lock_guard<std::mutex> Guard(Mutex);
476 Funcs.emplace_back(DstFI);
477 return Funcs.back().cacheEncoding();
478}
479
480llvm::Error GsymCreator::saveSegments(StringRef Path,
482 uint64_t SegmentSize) const {
483 if (SegmentSize == 0)
484 return createStringError(std::errc::invalid_argument,
485 "invalid segment size zero");
486
487 size_t FuncIdx = 0;
488 const size_t NumFuncs = Funcs.size();
489 while (FuncIdx < NumFuncs) {
491 createSegment(SegmentSize, FuncIdx);
492 if (ExpectedGC) {
493 GsymCreator *GC = ExpectedGC->get();
494 if (GC == NULL)
495 break; // We had not more functions to encode.
496 raw_null_ostream ErrorStrm;
497 llvm::Error Err = GC->finalize(ErrorStrm);
498 if (Err)
499 return Err;
500 std::string SegmentedGsymPath;
501 raw_string_ostream SGP(SegmentedGsymPath);
502 std::optional<uint64_t> FirstFuncAddr = GC->getFirstFunctionAddress();
503 if (FirstFuncAddr) {
504 SGP << Path << "-" << llvm::format_hex(*FirstFuncAddr, 1);
505 SGP.flush();
506 Err = GC->save(SegmentedGsymPath, ByteOrder, std::nullopt);
507 if (Err)
508 return Err;
509 }
510 } else {
511 return ExpectedGC.takeError();
512 }
513 }
514 return Error::success();
515}
516
518GsymCreator::createSegment(uint64_t SegmentSize, size_t &FuncIdx) const {
519 // No function entries, return empty unique pointer
520 if (FuncIdx >= Funcs.size())
521 return std::unique_ptr<GsymCreator>();
522
523 std::unique_ptr<GsymCreator> GC(new GsymCreator(/*Quiet=*/true));
524
525 // Tell the creator that this is a segment.
526 GC->setIsSegment();
527
528 // Set the base address if there is one.
529 if (BaseAddress)
530 GC->setBaseAddress(*BaseAddress);
531 // Copy the UUID value from this object into the new creator.
532 GC->setUUID(UUID);
533 const size_t NumFuncs = Funcs.size();
534 // Track how big the function infos are for the current segment so we can
535 // emit segments that are close to the requested size. It is quick math to
536 // determine the current header and tables sizes, so we can do that each loop.
537 uint64_t SegmentFuncInfosSize = 0;
538 for (; FuncIdx < NumFuncs; ++FuncIdx) {
539 const uint64_t HeaderAndTableSize = GC->calculateHeaderAndTableSize();
540 if (HeaderAndTableSize + SegmentFuncInfosSize >= SegmentSize) {
541 if (SegmentFuncInfosSize == 0)
542 return createStringError(std::errc::invalid_argument,
543 "a segment size of %" PRIu64 " is to small to "
544 "fit any function infos, specify a larger value",
545 SegmentSize);
546
547 break;
548 }
549 SegmentFuncInfosSize += alignTo(GC->copyFunctionInfo(*this, FuncIdx), 4);
550 }
551 return std::move(GC);
552}
#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
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:220
Subclass of Error for the sole purpose of identifying the success path in the type system.
Definition: Error.h:332
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
static ErrorSuccess success()
Create a success value.
Definition: Error.h:334
Tagged union holding either a T or a Error.
Definition: Error.h:474
Error takeError()
Take ownership of the stored error.
Definition: Error.h:601
reference get()
Returns a reference to the stored T value.
Definition: Error.h:571
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.
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:579
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
Definition: Path.cpp:469
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:440
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition: Error.h:1244
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1652
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:103
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:89
std::optional< InlineInfo > Inline
Definition: FunctionInfo.h:93
bool hasRichInfo() const
Query if a FunctionInfo has rich debug info.
Definition: FunctionInfo.h:109
uint32_t Name
String table offset in the string table.
Definition: FunctionInfo.h:91
std::optional< LineTable > OptLineTable
Definition: FunctionInfo.h:92
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