#include "llvm-readobj.h"
#include "Error.h"
#include "ObjDumper.h"
+#include "StackMapPrinter.h"
#include "StreamWriter.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
void printSymbols() override;
void printDynamicSymbols() override;
void printUnwindInfo() override;
+ void printStackMap() const override;
private:
template<class MachHeader>
DataRefImpl DR = Section.getRawDataRefImpl();
StringRef Name;
- if (error(Section.getName(Name)))
- Name = "";
+ error(Section.getName(Name));
ArrayRef<char> RawName = Obj->getSectionRawName(DR);
StringRef SegmentName = Obj->getSectionFinalSegmentName(DR);
bool IsBSS = Section.isBSS();
if (!IsBSS) {
StringRef Data;
- if (error(Section.getContents(Data)))
- break;
+ error(Section.getContents(Data));
W.printBinaryBlock("SectionData", Data);
}
std::error_code EC;
for (const SectionRef &Section : Obj->sections()) {
StringRef Name;
- if (error(Section.getName(Name)))
- continue;
+ error(Section.getName(Name));
bool PrintedGroup = false;
for (const RelocationRef &Reloc : Section.relocations()) {
void MachODumper::printRelocation(const MachOObjectFile *Obj,
const RelocationRef &Reloc) {
- uint64_t Offset;
+ uint64_t Offset = Reloc.getOffset();
SmallString<32> RelocName;
- if (error(Reloc.getOffset(Offset)))
- return;
- if (error(Reloc.getTypeName(RelocName)))
- return;
+ Reloc.getTypeName(RelocName);
DataRefImpl DR = Reloc.getRawDataRefImpl();
MachO::any_relocation_info RE = Obj->getRelocation(DR);
if (IsExtern) {
symbol_iterator Symbol = Reloc.getSymbol();
if (Symbol != Obj->symbol_end()) {
- if (error(Symbol->getName(TargetName)))
- return;
+ ErrorOr<StringRef> TargetNameOrErr = Symbol->getName();
+ error(TargetNameOrErr.getError());
+ TargetName = *TargetNameOrErr;
}
} else if (!IsScattered) {
- section_iterator SecI = Reloc.getSection();
+ section_iterator SecI = Obj->getRelocationSection(DR);
if (SecI != Obj->section_end()) {
- if (error(SecI->getName(TargetName)))
- return;
+ error(SecI->getName(TargetName));
}
}
if (TargetName.empty())
void MachODumper::printSymbol(const SymbolRef &Symbol) {
StringRef SymbolName;
- if (Symbol.getName(SymbolName))
- SymbolName = "";
+ if (ErrorOr<StringRef> SymbolNameOrErr = Symbol.getName())
+ SymbolName = *SymbolNameOrErr;
MachOSymbol MOSymbol;
getSymbol(Obj, Symbol.getRawDataRefImpl(), MOSymbol);
StringRef SectionName = "";
section_iterator SecI(Obj->section_begin());
- if (!error(Symbol.getSection(SecI)) && SecI != Obj->section_end())
+ error(Symbol.getSection(SecI));
+ if (SecI != Obj->section_end())
error(SecI->getName(SectionName));
DictScope D(W, "Symbol");
void MachODumper::printUnwindInfo() {
W.startLine() << "UnwindInfo not implemented.\n";
}
+
+void MachODumper::printStackMap() const {
+ object::SectionRef StackMapSection;
+ for (auto Sec : Obj->sections()) {
+ StringRef Name;
+ Sec.getName(Name);
+ if (Name == "__llvm_stackmaps") {
+ StackMapSection = Sec;
+ break;
+ }
+ }
+
+ if (StackMapSection == object::SectionRef())
+ return;
+
+ StringRef StackMapContents;
+ StackMapSection.getContents(StackMapContents);
+ ArrayRef<uint8_t> StackMapContentsArray(
+ reinterpret_cast<const uint8_t*>(StackMapContents.data()),
+ StackMapContents.size());
+
+ if (Obj->isLittleEndian())
+ prettyPrintStackMap(
+ llvm::outs(),
+ StackMapV1Parser<support::little>(StackMapContentsArray));
+ else
+ prettyPrintStackMap(llvm::outs(),
+ StackMapV1Parser<support::big>(StackMapContentsArray));
+}