[dwarfdump] Add support for dumping mach-o universal objectfiles

llvm-svn: 243862
This commit is contained in:
Frederic Riss 2015-08-03 00:10:31 +00:00
parent 40c01793f4
commit 4c5d357b57
2 changed files with 33 additions and 8 deletions

View File

@ -0,0 +1,17 @@
Reuse a test input from llvm-dsymutil, it's perfect for what we want to exercise
RUN: llvm-dwarfdump %S/../tools/dsymutil/Inputs/fat-test.o -debug-dump=info | FileCheck %s
CHECK: fat-test.o (x86_64): file format Mach-O 64-bit x86-64
CHECK: DW_TAG_variable
CHECK-NOT: {{NULL|DW_TAG}}
CHECK: DW_AT_name {{.*}} "x86_64_var"
CHECK: fat-test.o (i386): file format Mach-O 32-bit i386
CHECK: DW_TAG_variable
CHECK-NOT: {{NULL|DW_TAG}}
CHECK: DW_AT_name {{.*}} "i386_var"
CHECK: fat-test.o (x86_64h): file format Mach-O 64-bit x86-64
CHECK: DW_TAG_variable
CHECK-NOT: {{NULL|DW_TAG}}
CHECK: DW_AT_name {{.*}} "x86_64h_var"

View File

@ -15,6 +15,7 @@
#include "llvm/ADT/Triple.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/Object/MachOUniversal.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/RelocVisitor.h"
#include "llvm/Support/CommandLine.h"
@ -76,11 +77,11 @@ static void error(StringRef Filename, std::error_code EC) {
exit(1);
}
static void DumpObjectFile(ObjectFile &Obj, StringRef Filename) {
static void DumpObjectFile(ObjectFile &Obj, Twine Filename) {
std::unique_ptr<DIContext> DICtx(new DWARFContextInMemory(Obj));
outs() << Filename
<< ":\tfile format " << Obj.getFileFormatName() << "\n\n";
outs() << Filename.str() << ":\tfile format " << Obj.getFileFormatName()
<< "\n\n";
// Dump the complete DWARF structure.
DICtx->dump(outs(), DumpType);
}
@ -91,12 +92,19 @@ static void DumpInput(StringRef Filename) {
error(Filename, BuffOrErr.getError());
std::unique_ptr<MemoryBuffer> Buff = std::move(BuffOrErr.get());
ErrorOr<std::unique_ptr<ObjectFile>> ObjOrErr =
ObjectFile::createObjectFile(Buff->getMemBufferRef());
error(Filename, ObjOrErr.getError());
ObjectFile &Obj = *ObjOrErr.get();
ErrorOr<std::unique_ptr<Binary>> BinOrErr =
object::createBinary(Buff->getMemBufferRef());
error(Filename, BinOrErr.getError());
DumpObjectFile(Obj, Filename);
if (auto *Obj = dyn_cast<ObjectFile>(BinOrErr->get()))
DumpObjectFile(*Obj, Filename);
else if (auto *Fat = dyn_cast<MachOUniversalBinary>(BinOrErr->get()))
for (auto &ObjForArch : Fat->objects()) {
auto MachOOrErr = ObjForArch.getAsObjectFile();
error(Filename, MachOOrErr.getError());
DumpObjectFile(**MachOOrErr,
Filename + " (" + ObjForArch.getArchTypeName() + ")");
}
}
int main(int argc, char **argv) {