[llvm] r269304 - [macho2yaml] Add support for dumping mach_headers
Chris Bieneman via llvm-commits
llvm-commits at lists.llvm.org
Thu May 12 09:04:21 PDT 2016
Author: cbieneman
Date: Thu May 12 11:04:20 2016
New Revision: 269304
URL: http://llvm.org/viewvc/llvm-project?rev=269304&view=rev
Log:
[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
...
Modified:
llvm/trunk/tools/obj2yaml/macho2yaml.cpp
Modified: llvm/trunk/tools/obj2yaml/macho2yaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/obj2yaml/macho2yaml.cpp?rev=269304&r1=269303&r2=269304&view=diff
==============================================================================
--- llvm/trunk/tools/obj2yaml/macho2yaml.cpp (original)
+++ llvm/trunk/tools/obj2yaml/macho2yaml.cpp Thu May 12 11:04:20 2016
@@ -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) {
More information about the llvm-commits
mailing list