[StackMaps] Add a lightweight parser for stackmap version 1 sections.

The parser provides a convenient interface for reading llvm stackmap v1 sections
in object files.

This patch also includes a new option for llvm-readobj, '-stackmap', which uses
the parser to pretty-print stackmap sections for debugging/testing purposes.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240860 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Lang Hames
2015-06-26 23:56:53 +00:00
parent 60bd365f59
commit 63f4054f8e
9 changed files with 687 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#include "ARMEHABIPrinter.h"
#include "Error.h"
#include "ObjDumper.h"
#include "StackMapPrinter.h"
#include "StreamWriter.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
@ -61,6 +62,8 @@ public:
void printMipsABIFlags() override;
void printMipsReginfo() override;
void printStackMap() const override;
private:
typedef ELFFile<ELFT> ELFO;
typedef typename ELFO::Elf_Shdr Elf_Shdr;
@ -1494,3 +1497,25 @@ template <class ELFT> void ELFDumper<ELFT>::printMipsReginfo() {
W.printHex("Co-Proc Mask2", Reginfo->ri_cprmask[2]);
W.printHex("Co-Proc Mask3", Reginfo->ri_cprmask[3]);
}
template <class ELFT> void ELFDumper<ELFT>::printStackMap() const {
const typename ELFFile<ELFT>::Elf_Shdr *StackMapSection = nullptr;
for (const auto &Sec : Obj->sections()) {
ErrorOr<StringRef> Name = Obj->getSectionName(&Sec);
if (*Name == ".llvm_stackmaps") {
StackMapSection = &Sec;
break;
}
}
if (!StackMapSection)
return;
StringRef StackMapContents;
ErrorOr<ArrayRef<uint8_t>> StackMapContentsArray =
Obj->getSectionContents(StackMapSection);
prettyPrintStackMap(
llvm::outs(),
StackMapV1Parser<ELFT::TargetEndianness>(*StackMapContentsArray));
}