llvm.org GIT mirror llvm / 7cd34c0
[dwarfdump] Add support for dumping mach-o universal objectfiles git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243862 91177308-0d34-0410-b5e6-96231b3b80d8 Frederic Riss 5 years ago
2 changed file(s) with 33 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
0 Reuse a test input from llvm-dsymutil, it's perfect for what we want to exercise
1 RUN: llvm-dwarfdump %S/../tools/dsymutil/Inputs/fat-test.o -debug-dump=info | FileCheck %s
2
3 CHECK: fat-test.o (x86_64): file format Mach-O 64-bit x86-64
4 CHECK: DW_TAG_variable
5 CHECK-NOT: {{NULL|DW_TAG}}
6 CHECK: DW_AT_name {{.*}} "x86_64_var"
7
8 CHECK: fat-test.o (i386): file format Mach-O 32-bit i386
9 CHECK: DW_TAG_variable
10 CHECK-NOT: {{NULL|DW_TAG}}
11 CHECK: DW_AT_name {{.*}} "i386_var"
12
13 CHECK: fat-test.o (x86_64h): file format Mach-O 64-bit x86-64
14 CHECK: DW_TAG_variable
15 CHECK-NOT: {{NULL|DW_TAG}}
16 CHECK: DW_AT_name {{.*}} "x86_64h_var"
1414 #include "llvm/ADT/Triple.h"
1515 #include "llvm/DebugInfo/DIContext.h"
1616 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
17 #include "llvm/Object/MachOUniversal.h"
1718 #include "llvm/Object/ObjectFile.h"
1819 #include "llvm/Object/RelocVisitor.h"
1920 #include "llvm/Support/CommandLine.h"
7576 exit(1);
7677 }
7778
78 static void DumpObjectFile(ObjectFile &Obj, StringRef Filename) {
79 static void DumpObjectFile(ObjectFile &Obj, Twine Filename) {
7980 std::unique_ptr DICtx(new DWARFContextInMemory(Obj));
8081
81 outs() << Filename
82 << ":\tfile format " << Obj.getFileFormatName() << "\n\n";
82 outs() << Filename.str() << ":\tfile format " << Obj.getFileFormatName()
83 << "\n\n";
8384 // Dump the complete DWARF structure.
8485 DICtx->dump(outs(), DumpType);
8586 }
9091 error(Filename, BuffOrErr.getError());
9192 std::unique_ptr Buff = std::move(BuffOrErr.get());
9293
93 ErrorOr> ObjOrErr =
94 ObjectFile::createObjectFile(Buff->getMemBufferRef());
95 error(Filename, ObjOrErr.getError());
96 ObjectFile &Obj = *ObjOrErr.get();
94 ErrorOr> BinOrErr =
95 object::createBinary(Buff->getMemBufferRef());
96 error(Filename, BinOrErr.getError());
9797
98 DumpObjectFile(Obj, Filename);
98 if (auto *Obj = dyn_cast(BinOrErr->get()))
99 DumpObjectFile(*Obj, Filename);
100 else if (auto *Fat = dyn_cast(BinOrErr->get()))
101 for (auto &ObjForArch : Fat->objects()) {
102 auto MachOOrErr = ObjForArch.getAsObjectFile();
103 error(Filename, MachOOrErr.getError());
104 DumpObjectFile(**MachOOrErr,
105 Filename + " (" + ObjForArch.getArchTypeName() + ")");
106 }
99107 }
100108
101109 int main(int argc, char **argv) {