[macho2yaml] Add support for dumping mach_headers

This patch adds the ability to dump mach headers. For my local clang binary the macho2yaml output is now:

--- !mach-o
FileHeader:
  cputype:         0x01000007
  cpusubtype:      0x80000003
  filetype:        0x00000002
  ncmds:           19
  flags:           0x00A18085
...

llvm-svn: 269304
This commit is contained in:
Chris Bieneman 2016-05-12 16:04:20 +00:00
parent 9062ab943f
commit c28531295d
1 changed files with 29 additions and 1 deletions

View File

@ -11,11 +11,39 @@
#include "obj2yaml.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Object/MachOUniversal.h"
#include "llvm/ObjectYAML/MachOYAML.h"
using namespace llvm;
class MachODumper {
const object::MachOObjectFile &Obj;
public:
MachODumper(const object::MachOObjectFile &O) : Obj(O) {}
Expected<MachOYAML::Object *> dump();
};
Expected<MachOYAML::Object *> MachODumper::dump() {
auto Y = make_unique<MachOYAML::Object>();
Y->Header.cputype = Obj.getHeader().cputype;
Y->Header.cpusubtype = Obj.getHeader().cpusubtype;
Y->Header.filetype = Obj.getHeader().filetype;
Y->Header.ncmds = Obj.getHeader().ncmds;
Y->Header.flags = Obj.getHeader().flags;
return Y.release();
}
Error macho2yaml(raw_ostream &Out, const object::MachOObjectFile &Obj) {
return make_error<Obj2YamlError>(obj2yaml_error::not_implemented);
MachODumper Dumper(Obj);
Expected<MachOYAML::Object *> YAML = Dumper.dump();
if (!YAML)
return YAML.takeError();
yaml::Output Yout(Out);
Yout << *(YAML.get());
return Error::success();
}
Error macho2yaml(raw_ostream &Out, const object::MachOUniversalBinary &Obj) {