From 4c5d357b57ea9717edb3f8efecdef6d4fbc13042 Mon Sep 17 00:00:00 2001 From: Frederic Riss Date: Mon, 3 Aug 2015 00:10:31 +0000 Subject: [PATCH] [dwarfdump] Add support for dumping mach-o universal objectfiles llvm-svn: 243862 --- llvm/test/DebugInfo/dwarfdump-macho-universal.test | 17 +++++++++++++++ llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 24 ++++++++++++++-------- 2 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 llvm/test/DebugInfo/dwarfdump-macho-universal.test diff --git a/llvm/test/DebugInfo/dwarfdump-macho-universal.test b/llvm/test/DebugInfo/dwarfdump-macho-universal.test new file mode 100644 index 0000000..f8dc192 --- /dev/null +++ b/llvm/test/DebugInfo/dwarfdump-macho-universal.test @@ -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" diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index 018e666..f641c6b 100644 --- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -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 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 Buff = std::move(BuffOrErr.get()); - ErrorOr> ObjOrErr = - ObjectFile::createObjectFile(Buff->getMemBufferRef()); - error(Filename, ObjOrErr.getError()); - ObjectFile &Obj = *ObjOrErr.get(); + ErrorOr> BinOrErr = + object::createBinary(Buff->getMemBufferRef()); + error(Filename, BinOrErr.getError()); - DumpObjectFile(Obj, Filename); + if (auto *Obj = dyn_cast(BinOrErr->get())) + DumpObjectFile(*Obj, Filename); + else if (auto *Fat = dyn_cast(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) { -- 2.7.4