#include "ARMWinEHPrinter.h"
#include "Error.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/ARMWinEH.h"
#include "llvm/Support/Format.h"
ErrorOr<object::SectionRef>
Decoder::getSectionContaining(const COFFObjectFile &COFF, uint64_t VA) {
for (const auto &Section : COFF.sections()) {
- uint64_t Address;
- uint64_t Size;
-
- if (std::error_code EC = Section.getAddress(Address))
- return EC;
- if (std::error_code EC = Section.getSize(Size))
- return EC;
+ uint64_t Address = Section.getAddress();
+ uint64_t Size = Section.getSize();
if (VA >= Address && (VA - Address) <= Size)
return Section;
ErrorOr<object::SymbolRef> Decoder::getSymbol(const COFFObjectFile &COFF,
uint64_t VA, bool FunctionOnly) {
for (const auto &Symbol : COFF.symbols()) {
- if (FunctionOnly) {
- SymbolRef::Type Type;
- if (std::error_code EC = Symbol.getType(Type))
- return EC;
- if (Type != SymbolRef::ST_Function)
- continue;
- }
+ if (FunctionOnly && Symbol.getType() != SymbolRef::ST_Function)
+ continue;
- uint64_t Address;
- if (std::error_code EC = Symbol.getAddress(Address))
+ ErrorOr<uint64_t> Address = Symbol.getAddress();
+ if (std::error_code EC = Address.getError())
return EC;
- if (Address == VA)
+ if (*Address == VA)
return Symbol;
}
return readobj_error::unknown_symbol;
const SectionRef &Section,
uint64_t Offset) {
for (const auto &Relocation : Section.relocations()) {
- uint64_t RelocationOffset;
- if (auto Error = Relocation.getOffset(RelocationOffset))
- return Error;
+ uint64_t RelocationOffset = Relocation.getOffset();
if (RelocationOffset == Offset)
return *Relocation.getSymbol();
}
if (COFF.getSectionContents(COFF.getCOFFSection(Section), Contents))
return false;
- uint64_t SectionVA;
- if (Section.getAddress(SectionVA))
- return false;
-
+ uint64_t SectionVA = Section.getAddress();
uint64_t Offset = VA - SectionVA;
const ulittle32_t *Data =
reinterpret_cast<const ulittle32_t *>(Contents.data() + Offset);
if (!Symbol)
Symbol = getSymbol(COFF, Address, /*FunctionOnly=*/true);
- StringRef Name;
- if (Symbol)
- Symbol->getName(Name);
+ ErrorOr<StringRef> Name = Symbol->getName();
+ if (std::error_code EC = Name.getError())
+ report_fatal_error(EC.message());
ListScope EHS(SW, "ExceptionHandler");
- SW.printString("Routine", formatSymbol(Name, Address));
+ SW.printString("Routine", formatSymbol(*Name, Address));
SW.printHex("Parameter", Parameter);
}
StringRef FunctionName;
uint64_t FunctionAddress;
if (Function) {
- Function->getName(FunctionName);
- Function->getAddress(FunctionAddress);
+ ErrorOr<StringRef> FunctionNameOrErr = Function->getName();
+ if (std::error_code EC = FunctionNameOrErr.getError())
+ report_fatal_error(EC.message());
+ FunctionName = *FunctionNameOrErr;
+ ErrorOr<uint64_t> FunctionAddressOrErr = Function->getAddress();
+ if (std::error_code EC = FunctionAddressOrErr.getError())
+ report_fatal_error(EC.message());
+ FunctionAddress = *FunctionAddressOrErr;
} else {
const pe32_header *PEHeader;
if (COFF.getPE32Header(PEHeader))
SW.printString("Function", formatSymbol(FunctionName, FunctionAddress));
if (XDataRecord) {
- StringRef Name;
- uint64_t Address;
+ ErrorOr<StringRef> Name = XDataRecord->getName();
+ if (std::error_code EC = Name.getError())
+ report_fatal_error(EC.message());
- XDataRecord->getName(Name);
- XDataRecord->getAddress(Address);
+ ErrorOr<uint64_t> AddressOrErr = XDataRecord->getAddress();
+ if (std::error_code EC = AddressOrErr.getError())
+ report_fatal_error(EC.message());
+ uint64_t Address = *AddressOrErr;
- SW.printString("ExceptionRecord", formatSymbol(Name, Address));
+ SW.printString("ExceptionRecord", formatSymbol(*Name, Address));
- section_iterator SI = COFF.section_end();
- if (XDataRecord->getSection(SI))
+ ErrorOr<section_iterator> SIOrErr = XDataRecord->getSection();
+ if (!SIOrErr)
return false;
+ section_iterator SI = *SIOrErr;
return dumpXDataRecord(COFF, *SI, FunctionAddress, Address);
} else {
StringRef FunctionName;
uint64_t FunctionAddress;
if (Function) {
- Function->getName(FunctionName);
- Function->getAddress(FunctionAddress);
+ ErrorOr<StringRef> FunctionNameOrErr = Function->getName();
+ if (std::error_code EC = FunctionNameOrErr.getError())
+ report_fatal_error(EC.message());
+ FunctionName = *FunctionNameOrErr;
+ ErrorOr<uint64_t> FunctionAddressOrErr = Function->getAddress();
+ FunctionAddress = *FunctionAddressOrErr;
} else {
const pe32_header *PEHeader;
if (COFF.getPE32Header(PEHeader))