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);
108 if (
Kind >=
sizeof(Kinds))
111 Entry.Kind = Kinds[
Kind];
112 Entry.AlwaysInstrument = Extractor.
getU8(&OffsetPtr) != 0;
118 CurFn = Entry.Function;
119 FunctionAddresses[FuncId] = Entry.Function;
120 FunctionIds[Entry.Function] = FuncId;
122 if (Entry.Function != CurFn) {
124 CurFn = Entry.Function;
125 FunctionAddresses[FuncId] = Entry.Function;
126 FunctionIds[Entry.Function] = FuncId;
139 Fd, sys::fs::mapped_file_region::mapmode::readonly, FileSize, 0, EC);
141 return make_error<StringError>(
142 Twine(
"Failed memory-mapping file '") + Filename +
"'.", EC);
144 std::vector<YAMLXRaySledEntry> YAMLSleds;
148 return make_error<StringError>(
149 Twine(
"Failed loading YAML document from '") + Filename +
"'.",
152 Sleds.reserve(YAMLSleds.size());
153 for (
const auto &
Y : YAMLSleds) {
154 FunctionAddresses[
Y.FuncId] =
Y.Function;
155 FunctionIds[
Y.Function] =
Y.FuncId;
157 SledEntry{
Y.Address,
Y.Function,
Y.Kind,
Y.AlwaysInstrument});
172 if (!ObjectFileOrError) {
173 auto E = ObjectFileOrError.takeError();
190 if (
auto E =
loadYAML(Fd, FileSize, Filename, Map.Sleds,
191 Map.FunctionAddresses, Map.FunctionIds))
193 }
else if (
auto E =
loadELF64(Filename, *ObjectFileOrError, Map.Sleds,
194 Map.FunctionAddresses, Map.FunctionIds)) {
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Create ObjectFile from path.
FunctionKinds
Each entry here represents the kinds of supported instrumentation map entries.
std::error_code openFileForRead(const Twine &Name, int &ResultFD, SmallVectorImpl< char > *RealPath=nullptr)
This class represents a memory mapped file.
std::unordered_map< uint64_t, int32_t > FunctionAddressReverseMap
virtual unsigned getArch() const =0
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|.
std::error_code getName(StringRef &Result) const
Represents an XRay instrumentation sled entry from an object file.
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)
section_iterator_range sections() const
Optional< int32_t > getFunctionId(uint64_t Addr) const
Returns an XRay computed function id, provided a function address.
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.
Optional< uint64_t > getFunctionAddr(int32_t FuncId) const
Returns the function address for a function id.
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.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
This is a value type class that represents a single section in the list of sections in the object fil...