[DebugInfo] Add a DWARFDataExtractor constructor that takes ArrayRef<uint8_t>

Similar to D67797 (DataExtractor).
This commit is contained in:
Fangrui Song 2020-02-09 17:28:20 -08:00
parent 312a9d1b83
commit 512c03bac4
5 changed files with 12 additions and 11 deletions

View File

@ -23,8 +23,7 @@ DWARFDataExtractor::GetDWARFOffset(lldb::offset_t *offset_ptr) const {
llvm::DWARFDataExtractor DWARFDataExtractor::GetAsLLVM() const {
return llvm::DWARFDataExtractor(
llvm::StringRef(reinterpret_cast<const char *>(GetDataStart()),
GetByteSize()),
llvm::makeArrayRef(GetDataStart(), GetByteSize()),
GetByteOrder() == lldb::eByteOrderLittle, GetAddressByteSize());
}
} // namespace lldb_private

View File

@ -468,8 +468,8 @@ void DWARFUnit::SetLoclistsBase(dw_addr_t loclists_base) {
std::unique_ptr<llvm::DWARFLocationTable>
DWARFUnit::GetLocationTable(const DataExtractor &data) const {
llvm::DWARFDataExtractor llvm_data(
toStringRef(data.GetData()),
data.GetByteOrder() == lldb::eByteOrderLittle, data.GetAddressByteSize());
data.GetData(), data.GetByteOrder() == lldb::eByteOrderLittle,
data.GetAddressByteSize());
if (m_is_dwo || GetVersion() >= 5)
return std::make_unique<llvm::DWARFDebugLoclists>(llvm_data, GetVersion());

View File

@ -32,6 +32,11 @@ public:
/// Constructor for cases when there are no relocations.
DWARFDataExtractor(StringRef Data, bool IsLittleEndian, uint8_t AddressSize)
: DataExtractor(Data, IsLittleEndian, AddressSize) {}
DWARFDataExtractor(ArrayRef<uint8_t> Data, bool IsLittleEndian,
uint8_t AddressSize)
: DataExtractor(
StringRef(reinterpret_cast<const char *>(Data.data()), Data.size()),
IsLittleEndian, AddressSize) {}
/// Extracts a value and applies a relocation to the result if
/// one exists for the given offset.

View File

@ -109,7 +109,7 @@ DWARFLocationInterpreter::Interpret(const DWARFLocationEntry &E) {
static void dumpExpression(raw_ostream &OS, ArrayRef<uint8_t> Data,
bool IsLittleEndian, unsigned AddressSize,
const MCRegisterInfo *MRI, DWARFUnit *U) {
DWARFDataExtractor Extractor(toStringRef(Data), IsLittleEndian, AddressSize);
DWARFDataExtractor Extractor(Data, IsLittleEndian, AddressSize);
DWARFExpression(Extractor, AddressSize).print(OS, MRI, U);
}

View File

@ -186,12 +186,9 @@ void PrinterContext<ELFT>::printEHFrame(
if (Error E = Result.takeError())
reportError(std::move(E), ObjF->getFileName());
auto Contents = Result.get();
DWARFDataExtractor DE(
StringRef(reinterpret_cast<const char *>(Contents.data()),
Contents.size()),
ELFT::TargetEndianness == support::endianness::little,
ELFT::Is64Bits ? 8 : 4);
DWARFDataExtractor DE(*Result,
ELFT::TargetEndianness == support::endianness::little,
ELFT::Is64Bits ? 8 : 4);
DWARFDebugFrame EHFrame(Triple::ArchType(ObjF->getArch()), /*IsEH=*/true,
/*EHFrameAddress=*/Address);
EHFrame.parse(DE);