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