29 #include <system_error> 36 auto I = FunctionIds.find(Addr);
37 if (
I != FunctionIds.end())
43 auto I = FunctionAddresses.find(FuncId);
44 if (
I != FunctionAddresses.end())
60 return make_error<StringError>(
61 "File format not supported (only does ELF little endian 64-bit).",
70 return Name ==
"xray_instr_map";
73 if (
I == Sections.end())
74 return make_error<StringError>(
75 "Failed to find XRay instrumentation map.",
78 if (
I->getContents(Contents))
83 auto C = Contents.bytes_begin();
84 static constexpr
size_t ELF64SledEntrySize = 32;
86 if ((
C - Contents.bytes_end()) % ELF64SledEntrySize != 0)
87 return make_error<StringError>(
88 Twine(
"Instrumentation map entries not evenly divisible by size of " 89 "an XRay sled entry in ELF64."),
94 for (;
C != Contents.bytes_end();
C += ELF64SledEntrySize) {
96 StringRef(reinterpret_cast<const char *>(
C), ELF64SledEntrySize),
true,
99 auto &Entry = Sleds.back();
101 Entry.Address = Extractor.
getU64(&OffsetPtr);
102 Entry.Function = Extractor.
getU64(&OffsetPtr);
109 if (
Kind >=
sizeof(Kinds))
112 Entry.Kind = Kinds[
Kind];
113 Entry.AlwaysInstrument = Extractor.
getU8(&OffsetPtr) != 0;
119 CurFn = Entry.Function;
120 FunctionAddresses[FuncId] = Entry.Function;
121 FunctionIds[Entry.Function] = FuncId;
123 if (Entry.Function != CurFn) {
125 CurFn = Entry.Function;
126 FunctionAddresses[FuncId] = Entry.Function;
127 FunctionIds[Entry.Function] = FuncId;
140 Fd, sys::fs::mapped_file_region::mapmode::readonly, FileSize, 0, EC);
142 return make_error<StringError>(
143 Twine(
"Failed memory-mapping file '") + Filename +
"'.", EC);
145 std::vector<YAMLXRaySledEntry> YAMLSleds;
149 return make_error<StringError>(
150 Twine(
"Failed loading YAML document from '") + Filename +
"'.",
153 Sleds.reserve(YAMLSleds.size());
154 for (
const auto &
Y : YAMLSleds) {
155 FunctionAddresses[
Y.FuncId] =
Y.Function;
156 FunctionIds[
Y.Function] =
Y.FuncId;
158 SledEntry{
Y.Address,
Y.Function,
Y.Kind,
Y.AlwaysInstrument});
173 if (!ObjectFileOrError) {
174 auto E = ObjectFileOrError.takeError();
191 if (
auto E =
loadYAML(Fd, FileSize, Filename, Map.Sleds,
192 Map.FunctionAddresses, Map.FunctionIds))
194 }
else if (
auto E =
loadELF64(Filename, *ObjectFileOrError, Map.Sleds,
195 Map.FunctionAddresses, Map.FunctionIds)) {
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Optional< uint64_t > getFunctionAddr(int32_t FuncId) const
Returns the function address for a function id.
Compute iterated dominance frontiers using a linear time algorithm.
std::error_code openFileForRead(const Twine &Name, int &ResultFD, OpenFlags Flags=OF_None, SmallVectorImpl< char > *RealPath=nullptr)
Opens the file with the given name in a read-only mode, returning its open file descriptor.
FunctionKinds
Each entry here represents the kinds of supported instrumentation map entries.
This class represents a memory mapped file.
std::unordered_map< uint64_t, int32_t > FunctionAddressReverseMap
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::vector< SledEntry > SledContainer
std::error_code make_error_code(BitcodeError E)
std::error_code file_size(const Twine &Path, uint64_t &Result)
Get file size.
Tagged union holding either a T or a Error.
Expected< InstrumentationMap > loadInstrumentationMap(StringRef Filename)
Loads the instrumentation map from |Filename|.
Represents an XRay instrumentation sled entry from an object file.
section_iterator_range sections() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
static Error loadELF64(StringRef Filename, object::OwningBinary< object::ObjectFile > &ObjFile, InstrumentationMap::SledContainer &Sleds, InstrumentationMap::FunctionAddressMap &FunctionAddresses, InstrumentationMap::FunctionAddressReverseMap &FunctionIds)
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
void consumeError(Error Err)
Consume a Error without doing anything.
static Error loadYAML(int Fd, size_t FileSize, StringRef Filename, InstrumentationMap::SledContainer &Sleds, InstrumentationMap::FunctionAddressMap &FunctionAddresses, InstrumentationMap::FunctionAddressReverseMap &FunctionIds)
static ErrorSuccess success()
Create a success value.
std::error_code getName(StringRef &Result) const
virtual Triple::ArchType getArch() const =0
Optional< int32_t > getFunctionId(uint64_t Addr) const
Returns an XRay computed function id, provided a function address.
std::unordered_map< int32_t, uint64_t > FunctionAddressMap
The InstrumentationMap represents the computed function id's and indicated function addresses from an...
Lightweight error class with error context and mandatory checking.
StringRef - Represent a constant reference to a string, i.e.
This is a value type class that represents a single section in the list of sections in the object fil...