42 std::lock_guard<std::mutex> Guard(
Mutex);
43 const auto NextIndex =
Files.size();
47 Files.emplace_back(FE);
48 return R.first->second;
69 std::optional<uint64_t> SegmentSize)
const {
94 std::vector<FunctionInfo> TopLevelFuncs;
97 TopLevelFuncs.emplace_back(std::move(
Funcs.front()));
102 for (
size_t Idx = 1; Idx <
Funcs.size(); ++Idx) {
115 std::move(MatchFunc));
118 TopLevelFuncs.emplace_back(std::move(MatchFunc));
123 if (mergedCount != 0)
124 Out <<
"Have " << mergedCount
125 <<
" merged functions as children of other functions\n";
131 std::lock_guard<std::mutex> Guard(
Mutex);
160 const auto NumBefore =
Funcs.size();
170 std::vector<FunctionInfo> FinalizedFuncs;
171 FinalizedFuncs.reserve(
Funcs.size());
172 FinalizedFuncs.emplace_back(std::move(
Funcs.front()));
173 for (
size_t Idx=1; Idx < NumBefore; ++Idx) {
179 const bool ranges_equal = Prev.
Range == Curr.
Range;
189 if (!(Prev == Curr)) {
192 "Duplicate address ranges with different debug info.",
194 OS <<
"warning: same address range contains "
196 <<
"info. Removing:\n"
197 << Prev <<
"\nIn favor of this one:\n"
209 OS <<
"warning: function ranges overlap:\n"
213 FinalizedFuncs.emplace_back(std::move(Curr));
222 FinalizedFuncs.emplace_back(std::move(Curr));
239 Out <<
"Pruned " << NumBefore -
Funcs.size() <<
" functions, ended with "
240 <<
Funcs.size() <<
" total\n";
259 std::lock_guard<std::mutex> Guard(
Mutex);
267 if (!
StrTab.contains(CHStr))
282 "GsymCreator::getString expects a valid offset as parameter.");
283 return I->second.val();
287 std::lock_guard<std::mutex> Guard(
Mutex);
288 Funcs.emplace_back(std::move(FI));
293 std::lock_guard<std::mutex> Guard(
Mutex);
294 for (
auto &FI :
Funcs) {
301 std::function<
bool(
const FunctionInfo &)>
const &Callback)
const {
302 std::lock_guard<std::mutex> Guard(
Mutex);
303 for (
const auto &FI :
Funcs) {
310 std::lock_guard<std::mutex> Guard(
Mutex);
326 return std::optional<uint64_t>(
Funcs.front().startAddress());
336 return std::optional<uint64_t>(
Funcs.back().startAddress());
348 case 1:
return UINT8_MAX;
349 case 2:
return UINT16_MAX;
350 case 4:
return UINT32_MAX;
361 if (AddrDelta <= UINT8_MAX)
363 else if (AddrDelta <= UINT16_MAX)
365 else if (AddrDelta <= UINT32_MAX)
376 "no functions to encode");
379 "GsymCreator wasn't finalized prior to encoding");
380 if (
Funcs.size() > UINT32_MAX)
382 "too many FunctionInfos");
386 "invalid base address");
393 O.alignTo(AddrOffSize);
394 for (
const auto &FI :
Funcs) {
395 uint64_t AddrOffset = FI.startAddress() - BaseAddr;
400 assert(AddrOffset <= MaxAddressOffset);
401 (void)MaxAddressOffset;
402 switch (AddrOffSize) {
404 O.writeU8(
static_cast<uint8_t>(AddrOffset));
407 O.writeU16(
static_cast<uint16_t>(AddrOffset));
410 O.writeU32(
static_cast<uint32_t>(AddrOffset));
413 O.writeU64(AddrOffset);
425 if (
Files.size() > UINT32_MAX)
428 for (
const auto &File :
Files) {
429 O.writeStringOffset(File.Dir);
430 O.writeStringOffset(File.Base);
441 for (
auto &ChildII:
II.Children)
461 const size_t NumLines = DstLT.
size();
462 for (
size_t I=0;
I<NumLines; ++
I) {
474 std::lock_guard<std::mutex> Guard(
Mutex);
475 Funcs.emplace_back(DstFI);
476 return Funcs.back().cacheEncoding(*
this);
482 if (SegmentSize == 0)
484 "invalid segment size zero");
487 const size_t NumFuncs =
Funcs.size();
488 while (FuncIdx < NumFuncs) {
500 std::string SegmentedGsymPath;
502 std::optional<uint64_t> FirstFuncAddr = GC->getFirstFunctionAddress();
505 Err = GC->save(SegmentedGsymPath, ByteOrder, std::nullopt);
519 if (FuncIdx >=
Funcs.size())
520 return std::unique_ptr<GsymCreator>();
522 std::unique_ptr<GsymCreator> GC =
createNew(
true);
532 const size_t NumFuncs =
Funcs.size();
537 for (; FuncIdx < NumFuncs; ++FuncIdx) {
538 const uint64_t HeaderAndTableSize = GC->calculateHeaderAndTableSize();
539 if (HeaderAndTableSize + SegmentFuncInfosSize >= SegmentSize) {
540 if (SegmentFuncInfosSize == 0)
542 "a segment size of %" PRIu64
" is to small to "
543 "fit any function infos, specify a larger value",
548 SegmentFuncInfosSize +=
alignTo(GC->copyFunctionInfo(*
this, FuncIdx), 4);
550 return std::move(GC);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
bool intersects(const AddressRange &R) const
bool contains(uint64_t Addr) const
A container which contains a StringRef plus a precomputed hash.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
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,...
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.
LineEntry & get(size_t i)
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.
A raw_ostream that writes to an std::string.
#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.
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Files in GSYM are contained in FileEntry structs where we split the directory and basename into two d...
gsym_strp_t Dir
Offsets in the string table.
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.
Line entries are used to encode the line tables in FunctionInfo objects.