[llvm] r313272 - llvm-dwarfdump: support dumping static archives.
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 18 12:29:35 PDT 2017
> On Sep 18, 2017, at 11:40 AM, David Blaikie <dblaikie at gmail.com> wrote:
>
>
>
> On Thu, Sep 14, 2017 at 10:03 AM Adrian Prantl via llvm-commits <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
> Author: adrian
> Date: Thu Sep 14 10:01:53 2017
> New Revision: 313272
>
> URL: http://llvm.org/viewvc/llvm-project?rev=313272&view=rev <http://llvm.org/viewvc/llvm-project?rev=313272&view=rev>
> Log:
> llvm-dwarfdump: support dumping static archives.
>
> Added:
> llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test
> Modified:
> llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
> llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
>
> Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=313272&r1=313271&r2=313272&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=313272&r1=313271&r2=313272&view=diff>
> ==============================================================================
> --- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)
> +++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Thu Sep 14 10:01:53 2017
> @@ -230,9 +230,6 @@ void DWARFContext::dump(raw_ostream &OS,
>
> // Print UUID header.
> const auto *ObjFile = DObj->getFile();
> - if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)
> - outs() << ObjFile->getFileName() << ":\tfile format "
> - << ObjFile->getFileFormatName() << "\n\n";
> if (DumpType & DIDT_UUID)
> dumpUUID(OS, *ObjFile);
>
>
> Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test?rev=313272&view=auto <http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test?rev=313272&view=auto>
> ==============================================================================
> --- llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test (added)
> +++ llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test Thu Sep 14 10:01:53 2017
> @@ -0,0 +1,5 @@
> +RUN: llvm-dwarfdump --debug-info %S/../../dsymutil/Inputs/libfat-test.a | FileCheck %s
> +CHECK: libfat-test.a(x86_64)(fat-test.o): file format Mach-O 64-bit x86-64
> +CHECK: .debug_info contents:
> +CHECK: libfat-test.a(i386)(fat-test.o): file format Mach-O 32-bit i386
> +CHECK: .debug_info contents:
>
> 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=313272&r1=313271&r2=313272&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=313272&r1=313271&r2=313272&view=diff>
> ==============================================================================
> --- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)
> +++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Thu Sep 14 10:01:53 2017
> @@ -15,6 +15,7 @@
> #include "llvm/ADT/Triple.h"
> #include "llvm/DebugInfo/DIContext.h"
> #include "llvm/DebugInfo/DWARF/DWARFContext.h"
> +#include "llvm/Object/Archive.h"
> #include "llvm/Object/MachOUniversal.h"
> #include "llvm/Object/ObjectFile.h"
> #include "llvm/Object/RelocVisitor.h"
> @@ -123,22 +124,51 @@ static bool verifyObjectFile(ObjectFile
> }
>
> static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
> + std::function<bool(ObjectFile &, Twine)> HandleObj);
> +
> +static bool handleArchive(StringRef Filename, Archive &Arch,
> + std::function<bool(ObjectFile &, Twine)> HandleObj) {
> + bool Result = true;
> + Error Err = Error::success();
> + for (auto Child : Arch.children(Err)) {
> + auto BuffOrErr = Child.getMemoryBufferRef();
> + error(Filename, errorToErrorCode(BuffOrErr.takeError()));
> + auto NameOrErr = Child.getName();
> + error(Filename, errorToErrorCode(NameOrErr.takeError()));
> + std::string Name = (Filename + "(" + NameOrErr.get() + ")").str();
> + Result &= handleBuffer(Name, BuffOrErr.get(), HandleObj);
> + }
> + error(Filename, errorToErrorCode(std::move(Err)));
> +
> + return Result;
> +}
> +
> +static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,
> std::function<bool(ObjectFile &, Twine)> HandleObj) {
> Expected<std::unique_ptr<Binary>> BinOrErr = object::createBinary(Buffer);
> - if (!BinOrErr)
> - error(Filename, errorToErrorCode(BinOrErr.takeError()));
> + error(Filename, errorToErrorCode(BinOrErr.takeError()));
>
> bool Result = true;
> if (auto *Obj = dyn_cast<ObjectFile>(BinOrErr->get()))
> Result = HandleObj(*Obj, Filename);
> else if (auto *Fat = dyn_cast<MachOUniversalBinary>(BinOrErr->get()))
> for (auto &ObjForArch : Fat->objects()) {
> - auto MachOOrErr = ObjForArch.getAsObjectFile();
> - error(Filename, errorToErrorCode(MachOOrErr.takeError()));
> - if (!HandleObj(**MachOOrErr,
> - Filename + " (" + ObjForArch.getArchFlagName() + ")"))
> - Result = false;
> + std::string ObjName =
> + (Filename + "(" + ObjForArch.getArchFlagName() + ")").str();
> + if (auto MachOOrErr = ObjForArch.getAsObjectFile()) {
> + Result &= HandleObj(**MachOOrErr, ObjName);
> + continue;
> + } else
>
> Drop the else after continue
>
> + consumeError(MachOOrErr.takeError());
> + if (auto ArchiveOrErr = ObjForArch.getAsArchive()) {
> + error(ObjName, errorToErrorCode(ArchiveOrErr.takeError()));
> + Result &= handleArchive(ObjName, *ArchiveOrErr.get(), HandleObj);
> + continue;
> + } else
>
> Similarly here ^
>
> + consumeError(ArchiveOrErr.takeError());
Turns out I can't because of the scoping for the variable ArchiveOrErr.
-- adrian
>
> Do you really want to be silently ignoring all these errors? Oh, I guess so, due to the fallback style handling here ("try to treat this as X, if that doesn't work try Y, etc").
>
> }
> + else if (auto *Arch = dyn_cast<Archive>(BinOrErr->get()))
> + Result = handleArchive(Filename, *Arch, HandleObj);
> return Result;
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170918/387a6ac4/attachment.html>
More information about the llvm-commits
mailing list