34 std::lock_guard<std::recursive_mutex> Guard(
Mutex);
35 const auto NextIndex = Files.size();
37 auto R = FileEntryToIndex.
insert(std::make_pair(FE, NextIndex));
39 Files.emplace_back(FE);
40 return R.first->second;
54 std::lock_guard<std::recursive_mutex> Guard(
Mutex);
57 "no functions to encode");
60 "GsymCreator wasn't finalized prior to encoding");
62 if (Funcs.size() > UINT32_MAX)
64 "too many FunctionInfos");
65 const uint64_t MinAddr = Funcs.front().startAddress();
66 const uint64_t MaxAddr = Funcs.back().startAddress();
67 const uint64_t AddrDelta = MaxAddr - MinAddr;
77 memset(Hdr.
UUID, 0,
sizeof(Hdr.
UUID));
82 if (AddrDelta <= UINT8_MAX)
84 else if (AddrDelta <= UINT16_MAX)
86 else if (AddrDelta <= UINT32_MAX)
100 for (
const auto &FuncInfo : Funcs) {
101 uint64_t AddrOffset = FuncInfo.startAddress() - Hdr.
BaseAddress;
103 case 1: O.
writeU8(static_cast<uint8_t>(AddrOffset));
break;
104 case 2: O.
writeU16(static_cast<uint16_t>(AddrOffset));
break;
105 case 4: O.
writeU32(static_cast<uint32_t>(AddrOffset));
break;
106 case 8: O.
writeU64(AddrOffset);
break;
112 const off_t AddrInfoOffsetsOffset = O.
tell();
113 for (
size_t i = 0, n = Funcs.size(); i < n; ++i)
119 assert(Files[0].Dir == 0);
121 size_t NumFiles = Files.size();
122 if (NumFiles > UINT32_MAX)
125 O.
writeU32(static_cast<uint32_t>(NumFiles));
126 for (
auto File: Files) {
132 const off_t StrtabOffset = O.
tell();
134 const off_t StrtabSize = O.
tell() - StrtabOffset;
135 std::vector<uint32_t> AddrInfoOffsets;
138 for (
const auto &FuncInfo : Funcs) {
140 AddrInfoOffsets.push_back(OffsetOrErr.get());
142 return OffsetOrErr.takeError();
150 for (
auto AddrInfoOffset: AddrInfoOffsets) {
151 O.
fixup32(AddrInfoOffset, AddrInfoOffsetsOffset + Offset);
158 std::lock_guard<std::recursive_mutex> Guard(
Mutex);
161 "already finalized");
190 auto NumBefore = Funcs.size();
191 auto Curr = Funcs.begin();
192 auto Prev = Funcs.end();
193 while (Curr != Funcs.end()) {
196 if (Prev != Funcs.end()) {
197 if (Prev->Range.intersects(Curr->Range)) {
199 if (Prev->Range == Curr->Range) {
204 if (*Prev == *Curr) {
206 OS <<
"warning: duplicate function info entries, removing " 209 Curr = Funcs.erase(Prev);
211 if (!Prev->hasRichInfo() && Curr->hasRichInfo()) {
214 Curr = Funcs.erase(Prev);
216 OS <<
"warning: same address range contains different debug " 217 <<
"info. Removing:\n" 218 << *Prev <<
"\nIn favor of this one:\n" 220 Curr = Funcs.erase(Prev);
225 OS <<
"warning: function ranges overlap:\n" 229 }
else if (Prev->Range.size() == 0 &&
230 Curr->Range.contains(Prev->Range.Start)) {
231 OS <<
"warning: removing symbol:\n" 232 << *Prev <<
"\nKeeping:\n" 234 Curr = Funcs.erase(Prev);
237 if (Curr == Funcs.end())
242 OS <<
"Pruned " << NumBefore - Funcs.size() <<
" functions, ended with " 243 << Funcs.size() <<
" total\n";
248 std::lock_guard<std::recursive_mutex> Guard(
Mutex);
251 return StrTab.
add(S);
255 std::lock_guard<std::recursive_mutex> Guard(
Mutex);
256 Funcs.emplace_back(FI);
261 std::lock_guard<std::recursive_mutex> Guard(
Mutex);
262 for (
auto &FI : Funcs) {
270 std::lock_guard<std::recursive_mutex> Guard(
Mutex);
271 for (
const auto &FI : Funcs) {
void forEachFunctionInfo(std::function< bool(FunctionInfo &)> const &Callback)
Thread safe iteration over all function infos.
This class represents lattice values for constants.
void writeU8(uint8_t Value)
Write a single uint8_t value into the stream at the current file position.
Subclass of Error for the sole purpose of identifying the success path in the type system...
void alignTo(size_t Align)
Pad with zeroes at the current file position until the current file position matches the specified al...
Function information in GSYM files encodes information for one contiguous address range...
void fixup32(uint32_t Value, uint64_t Offset)
Fixup a uint32_t value at the specified offset in the stream.
uint32_t insertString(StringRef S)
Insert a string into the GSYM string table.
void writeU32(uint32_t Value)
Write a single uint32_t value into the stream at the current file position.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void writeU64(uint64_t Value)
Write a single uint64_t value into the stream at the current file position.
Tagged union holding either a T or a Error.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
void write(raw_ostream &OS) const
Utility for building string tables with deduplicated suffixes.
size_t add(CachedHashStringRef S)
Add a string to the builder.
void finalizeInOrder()
Finalize the string table without reording it.
Instrumentation for Order File
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
llvm::Error finalize(llvm::raw_ostream &OS)
Finalize the data in the GSYM creator prior to saving the data out.
#define offsetof(TYPE, MEMBER)
A simplified binary data writer class that doesn't require targets, target definitions, architectures, or require any other optional compile time libraries to be enabled via the build process.
llvm::Error encode(FileWriter &O) const
Encode a GSYM into the file writer stream at the current position.
llvm::Error save(StringRef Path, llvm::support::endianness ByteOrder) const
Save a GSYM file to a stand alone file.
StringRef parent_path(StringRef path, Style style=Style::native)
Get parent path.
void sort(IteratorTy Start, IteratorTy End)
static ErrorSuccess success()
Create a success value.
std::pair< llvm::MachO::Target, std::string > UUID
void addFunctionInfo(FunctionInfo &&FI)
Add a function info to this GSYM creator.
Files in GSYM are contained in FileEntry structs where we split the directory and basename into two d...
A raw_ostream that writes to a file descriptor.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
uint64_t tell()
Return the current offset within the file.
llvm::raw_pwrite_stream & get_stream()
void writeU16(uint16_t Value)
Write a single uint16_t value into the stream at the current file position.
uint32_t insertFile(StringRef Path, sys::path::Style Style=sys::path::Style::native)
Insert a file into this GSYM creator.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
constexpr uint32_t GSYM_MAGIC
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
constexpr uint32_t GSYM_VERSION
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.