From 8eb4aa593671eeabb76e673e965dc21621c911b1 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 23 Dec 2015 21:51:13 +0000 Subject: [PATCH] llvm-dwarfdump: Add support for dumping .dSYM bundles. This replicates the logic of Darwin dwarfdump for manually opening up .dSYM bundles without introducing any new dependencies. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256350 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../dsymutil/X86/basic-linking-bundle.test | 6 +++ tools/llvm-dwarfdump/llvm-dwarfdump.cpp | 45 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/test/tools/dsymutil/X86/basic-linking-bundle.test b/test/tools/dsymutil/X86/basic-linking-bundle.test index bf92091f402..c07fa5894f3 100644 --- a/test/tools/dsymutil/X86/basic-linking-bundle.test +++ b/test/tools/dsymutil/X86/basic-linking-bundle.test @@ -3,7 +3,13 @@ RUN: mkdir -p %T/basic-linking-bundle/dsymdest RUN: cat %p/../Inputs/basic.macho.x86_64 > %T/basic-linking-bundle/basic.macho.x86_64 RUN: llvm-dsymutil -oso-prepend-path=%p/.. %T/basic-linking-bundle/basic.macho.x86_64 + +Check that the object file in the bundle exists and is sane: RUN: llvm-dwarfdump %T/basic-linking-bundle/basic.macho.x86_64.dSYM/Contents/Resources/DWARF/basic.macho.x86_64 | FileCheck %S/basic-linking-x86.test + +Check that llvm-dwarfdump recognizes the bundle as a dSYM: +RUN: llvm-dwarfdump %T/basic-linking-bundle/basic.macho.x86_64.dSYM | FileCheck %S/basic-linking-x86.test + RUN: FileCheck %s --input-file %T/basic-linking-bundle/basic.macho.x86_64.dSYM/Contents/Info.plist RUN: llvm-dsymutil -oso-prepend-path=%p/.. %T/basic-linking-bundle/basic.macho.x86_64 -o %T/basic-linking-bundle/dsymdest/basic.macho.x86_64.dSYM diff --git a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp index d742eb3ec34..eaacc7c5f21 100644 --- a/tools/llvm-dwarfdump/llvm-dwarfdump.cpp +++ b/tools/llvm-dwarfdump/llvm-dwarfdump.cpp @@ -23,6 +23,7 @@ #include "llvm/Support/Format.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" @@ -36,7 +37,7 @@ using namespace llvm; using namespace object; static cl::list -InputFilenames(cl::Positional, cl::desc(""), +InputFilenames(cl::Positional, cl::desc(""), cl::ZeroOrMore); static cl::opt DumpType( @@ -110,6 +111,39 @@ static void DumpInput(StringRef Filename) { } } +/// If the input path is a .dSYM bundle (as created by the dsymutil tool), +/// replace it with individual entries for each of the object files inside the +/// bundle otherwise return the input path. +static std::vector expandBundle(std::string InputPath) { + std::vector BundlePaths; + SmallString<256> BundlePath(InputPath); + // Manually open up the bundle to avoid introducing additional dependencies. + if (sys::fs::is_directory(BundlePath) && + sys::path::extension(BundlePath) == ".dSYM") { + std::error_code EC; + sys::path::append(BundlePath, "Contents", "Resources", "DWARF"); + for (sys::fs::directory_iterator Dir(BundlePath, EC), DirEnd; + Dir != DirEnd && !EC; Dir.increment(EC)) { + const std::string &Path = Dir->path(); + sys::fs::file_status Status; + EC = sys::fs::status(Path, Status); + error(Path, EC); + switch (Status.type()) { + case sys::fs::file_type::regular_file: + case sys::fs::file_type::symlink_file: + case sys::fs::file_type::type_unknown: + BundlePaths.push_back(Path); + break; + default: /*ignore*/; + } + } + error(BundlePath, EC); + } + if (!BundlePaths.size()) + BundlePaths.push_back(InputPath); + return BundlePaths; +} + int main(int argc, char **argv) { // Print a stack trace if we signal out. sys::PrintStackTraceOnErrorSignal(); @@ -122,7 +156,14 @@ int main(int argc, char **argv) { if (InputFilenames.size() == 0) InputFilenames.push_back("a.out"); - std::for_each(InputFilenames.begin(), InputFilenames.end(), DumpInput); + // Expand any .dSYM bundles to the individual object files contained therein. + std::vector Objects; + for (auto F : InputFilenames) { + auto Objs = expandBundle(F); + Objects.insert(Objects.end(), Objs.begin(), Objs.end()); + } + + std::for_each(Objects.begin(), Objects.end(), DumpInput); return EXIT_SUCCESS; } -- 2.34.1