本文整理汇总了C++中StringRef::bytes_end方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRef::bytes_end方法的具体用法?C++ StringRef::bytes_end怎么用?C++ StringRef::bytes_end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRef
的用法示例。
在下文中一共展示了StringRef::bytes_end方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: success
Error llvm::codeview::consume(ArrayRef<uint8_t> &Data, StringRef &Item) {
if (Data.empty())
return make_error<CodeViewError>(cv_error_code::corrupt_record,
"Null terminated string buffer is empty!");
StringRef Rest;
std::tie(Item, Rest) = getBytesAsCharacters(Data).split('\0');
// We expect this to be null terminated. If it was not, it is an error.
if (Data.size() == Item.size())
return make_error<CodeViewError>(cv_error_code::corrupt_record,
"Expected null terminator!");
Data = ArrayRef<uint8_t>(Rest.bytes_begin(), Rest.bytes_end());
return Error::success();
}
示例2: errorCodeToError
static Error
loadObj(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile,
InstrumentationMap::SledContainer &Sleds,
InstrumentationMap::FunctionAddressMap &FunctionAddresses,
InstrumentationMap::FunctionAddressReverseMap &FunctionIds) {
InstrumentationMap Map;
// Find the section named "xray_instr_map".
if ((!ObjFile.getBinary()->isELF() && !ObjFile.getBinary()->isMachO()) ||
!(ObjFile.getBinary()->getArch() == Triple::x86_64 ||
ObjFile.getBinary()->getArch() == Triple::ppc64le))
return make_error<StringError>(
"File format not supported (only does ELF and Mach-O little endian 64-bit).",
std::make_error_code(std::errc::not_supported));
StringRef Contents = "";
const auto &Sections = ObjFile.getBinary()->sections();
auto I = llvm::find_if(Sections, [&](object::SectionRef Section) {
StringRef Name = "";
if (Section.getName(Name))
return false;
return Name == "xray_instr_map";
});
if (I == Sections.end())
return make_error<StringError>(
"Failed to find XRay instrumentation map.",
std::make_error_code(std::errc::executable_format_error));
if (I->getContents(Contents))
return errorCodeToError(
std::make_error_code(std::errc::executable_format_error));
RelocMap Relocs;
if (ObjFile.getBinary()->isELF()) {
uint32_t RelativeRelocation = [](object::ObjectFile *ObjFile) {
if (const auto *ELFObj = dyn_cast<object::ELF32LEObjectFile>(ObjFile))
return ELFObj->getELFFile()->getRelativeRelocationType();
else if (const auto *ELFObj = dyn_cast<object::ELF32BEObjectFile>(ObjFile))
return ELFObj->getELFFile()->getRelativeRelocationType();
else if (const auto *ELFObj = dyn_cast<object::ELF64LEObjectFile>(ObjFile))
return ELFObj->getELFFile()->getRelativeRelocationType();
else if (const auto *ELFObj = dyn_cast<object::ELF64BEObjectFile>(ObjFile))
return ELFObj->getELFFile()->getRelativeRelocationType();
else
return static_cast<uint32_t>(0);
}(ObjFile.getBinary());
for (const object::SectionRef &Section : Sections) {
for (const object::RelocationRef &Reloc : Section.relocations()) {
if (Reloc.getType() != RelativeRelocation)
continue;
if (auto AddendOrErr = object::ELFRelocationRef(Reloc).getAddend())
Relocs.insert({Reloc.getOffset(), *AddendOrErr});
}
}
}
// Copy the instrumentation map data into the Sleds data structure.
auto C = Contents.bytes_begin();
static constexpr size_t ELF64SledEntrySize = 32;
if ((C - Contents.bytes_end()) % ELF64SledEntrySize != 0)
return make_error<StringError>(
Twine("Instrumentation map entries not evenly divisible by size of "
"an XRay sled entry in ELF64."),
std::make_error_code(std::errc::executable_format_error));
auto RelocateOrElse = [&](uint32_t Offset, uint64_t Address) {
if (!Address) {
uint64_t A = I->getAddress() + C - Contents.bytes_begin() + Offset;
RelocMap::const_iterator R = Relocs.find(A);
if (R != Relocs.end())
return R->second;
}
return Address;
};
int32_t FuncId = 1;
uint64_t CurFn = 0;
for (; C != Contents.bytes_end(); C += ELF64SledEntrySize) {
DataExtractor Extractor(
StringRef(reinterpret_cast<const char *>(C), ELF64SledEntrySize), true,
8);
Sleds.push_back({});
auto &Entry = Sleds.back();
uint32_t OffsetPtr = 0;
uint32_t AddrOff = OffsetPtr;
Entry.Address = RelocateOrElse(AddrOff, Extractor.getU64(&OffsetPtr));
uint32_t FuncOff = OffsetPtr;
Entry.Function = RelocateOrElse(FuncOff, Extractor.getU64(&OffsetPtr));
auto Kind = Extractor.getU8(&OffsetPtr);
static constexpr SledEntry::FunctionKinds Kinds[] = {
SledEntry::FunctionKinds::ENTRY, SledEntry::FunctionKinds::EXIT,
SledEntry::FunctionKinds::TAIL,
SledEntry::FunctionKinds::LOG_ARGS_ENTER,
SledEntry::FunctionKinds::CUSTOM_EVENT};
if (Kind >= sizeof(Kinds))
return errorCodeToError(
std::make_error_code(std::errc::executable_format_error));
//.........这里部分代码省略.........
示例3: Bytes
Error llvm::codeview::consume(StringRef &Data, uint32_t &Item) {
ArrayRef<uint8_t> Bytes(Data.bytes_begin(), Data.bytes_end());
auto EC = consume(Bytes, Item);
Data = StringRef(reinterpret_cast<const char *>(Bytes.data()), Bytes.size());
return EC;
}
示例4: encloses
// Returns true if S encloses T.
static bool encloses(StringRef S, StringRef T) {
return S.bytes_begin() <= T.bytes_begin() && T.bytes_end() <= S.bytes_end();
}
示例5: writeFixedString
Error BinaryStreamWriter::writeFixedString(StringRef Str) {
return writeBytes(ArrayRef<uint8_t>(Str.bytes_begin(), Str.bytes_end()));
}
示例6: BinaryStreamRef
BinaryStreamRef::BinaryStreamRef(StringRef Data, endianness Endian)
: BinaryStreamRef(makeArrayRef(Data.bytes_begin(), Data.bytes_end()),
Endian) {}