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

Alexander Kornienko alexfh at google.com
Mon Aug 3 05:04:05 PDT 2015


On Mon, Aug 3, 2015 at 2:10 AM, Frederic Riss <friss at apple.com> wrote:

> Author: friss
> Date: Sun Aug  2 19:10:31 2015
> New Revision: 243862
>
> URL: http://llvm.org/viewvc/llvm-project?rev=243862&view=rev
> Log:
> [dwarfdump] Add support for dumping mach-o universal objectfiles
>
> Added:
>     llvm/trunk/test/DebugInfo/dwarfdump-macho-universal.test
> Modified:
>     llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
>
> Added: llvm/trunk/test/DebugInfo/dwarfdump-macho-universal.test
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-macho-universal.test?rev=243862&view=auto
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/dwarfdump-macho-universal.test (added)
> +++ llvm/trunk/test/DebugInfo/dwarfdump-macho-universal.test Sun Aug  2
> 19:10:31 2015
> @@ -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
>

FYI, using a file from other top-level test/ subdirectory breaks our test
setup. I've fixed this in r243872 by copying the file to
test/DebugInfo/Inputs/.


> +
> +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"
>
> Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=243862&r1=243861&r2=243862&view=diff
>
> ==============================================================================
> --- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
> +++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Sun Aug  2 19:10:31
> 2015
> @@ -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, st
>    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();
> -
> -  DumpObjectFile(Obj, Filename);
> +  ErrorOr<std::unique_ptr<Binary>> BinOrErr =
> +      object::createBinary(Buff->getMemBufferRef());
> +  error(Filename, BinOrErr.getError());
> +
> +  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) {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150803/54a32217/attachment.html>


More information about the llvm-commits mailing list