<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Sep 14, 2017 at 10:03 AM Adrian Prantl via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: adrian<br>
Date: Thu Sep 14 10:01:53 2017<br>
New Revision: 313272<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=313272&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=313272&view=rev</a><br>
Log:<br>
llvm-dwarfdump: support dumping static archives.<br>
<br>
Added:<br>
llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test<br>
Modified:<br>
llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br>
llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=313272&r1=313271&r2=313272&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=313272&r1=313271&r2=313272&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Thu Sep 14 10:01:53 2017<br>
@@ -230,9 +230,6 @@ void DWARFContext::dump(raw_ostream &OS,<br>
<br>
// Print UUID header.<br>
const auto *ObjFile = DObj->getFile();<br>
- if (!(DumpType & DIDT_UUID) || DumpType == DIDT_All)<br>
- outs() << ObjFile->getFileName() << ":\tfile format "<br>
- << ObjFile->getFileFormatName() << "\n\n";<br>
if (DumpType & DIDT_UUID)<br>
dumpUUID(OS, *ObjFile);<br>
<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test?rev=313272&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test?rev=313272&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/archive.test Thu Sep 14 10:01:53 2017<br>
@@ -0,0 +1,5 @@<br>
+RUN: llvm-dwarfdump --debug-info %S/../../dsymutil/Inputs/libfat-test.a | FileCheck %s<br>
+CHECK: libfat-test.a(x86_64)(fat-test.o): file format Mach-O 64-bit x86-64<br>
+CHECK: .debug_info contents:<br>
+CHECK: libfat-test.a(i386)(fat-test.o): file format Mach-O 32-bit i386<br>
+CHECK: .debug_info contents:<br>
<br>
Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=313272&r1=313271&r2=313272&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=313272&r1=313271&r2=313272&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)<br>
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Thu Sep 14 10:01:53 2017<br>
@@ -15,6 +15,7 @@<br>
#include "llvm/ADT/Triple.h"<br>
#include "llvm/DebugInfo/DIContext.h"<br>
#include "llvm/DebugInfo/DWARF/DWARFContext.h"<br>
+#include "llvm/Object/Archive.h"<br>
#include "llvm/Object/MachOUniversal.h"<br>
#include "llvm/Object/ObjectFile.h"<br>
#include "llvm/Object/RelocVisitor.h"<br>
@@ -123,22 +124,51 @@ static bool verifyObjectFile(ObjectFile<br>
}<br>
<br>
static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,<br>
+ std::function<bool(ObjectFile &, Twine)> HandleObj);<br>
+<br>
+static bool handleArchive(StringRef Filename, Archive &Arch,<br>
+ std::function<bool(ObjectFile &, Twine)> HandleObj) {<br>
+ bool Result = true;<br>
+ Error Err = Error::success();<br>
+ for (auto Child : Arch.children(Err)) {<br>
+ auto BuffOrErr = Child.getMemoryBufferRef();<br>
+ error(Filename, errorToErrorCode(BuffOrErr.takeError()));<br>
+ auto NameOrErr = Child.getName();<br>
+ error(Filename, errorToErrorCode(NameOrErr.takeError()));<br>
+ std::string Name = (Filename + "(" + NameOrErr.get() + ")").str();<br>
+ Result &= handleBuffer(Name, BuffOrErr.get(), HandleObj);<br>
+ }<br>
+ error(Filename, errorToErrorCode(std::move(Err)));<br>
+<br>
+ return Result;<br>
+}<br>
+<br>
+static bool handleBuffer(StringRef Filename, MemoryBufferRef Buffer,<br>
std::function<bool(ObjectFile &, Twine)> HandleObj) {<br>
Expected<std::unique_ptr<Binary>> BinOrErr = object::createBinary(Buffer);<br>
- if (!BinOrErr)<br>
- error(Filename, errorToErrorCode(BinOrErr.takeError()));<br>
+ error(Filename, errorToErrorCode(BinOrErr.takeError()));<br>
<br>
bool Result = true;<br>
if (auto *Obj = dyn_cast<ObjectFile>(BinOrErr->get()))<br>
Result = HandleObj(*Obj, Filename);<br>
else if (auto *Fat = dyn_cast<MachOUniversalBinary>(BinOrErr->get()))<br>
for (auto &ObjForArch : Fat->objects()) {<br>
- auto MachOOrErr = ObjForArch.getAsObjectFile();<br>
- error(Filename, errorToErrorCode(MachOOrErr.takeError()));<br>
- if (!HandleObj(**MachOOrErr,<br>
- Filename + " (" + ObjForArch.getArchFlagName() + ")"))<br>
- Result = false;<br>
+ std::string ObjName =<br>
+ (Filename + "(" + ObjForArch.getArchFlagName() + ")").str();<br>
+ if (auto MachOOrErr = ObjForArch.getAsObjectFile()) {<br>
+ Result &= HandleObj(**MachOOrErr, ObjName);<br>
+ continue;<br>
+ } else<br></blockquote><div><br>Drop the else after continue<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ consumeError(MachOOrErr.takeError());<br>
+ if (auto ArchiveOrErr = ObjForArch.getAsArchive()) {<br>
+ error(ObjName, errorToErrorCode(ArchiveOrErr.takeError()));<br>
+ Result &= handleArchive(ObjName, *ArchiveOrErr.get(), HandleObj);<br>
+ continue;<br>
+ } else<br></blockquote><div><br>Similarly here ^<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ consumeError(ArchiveOrErr.takeError());<br></blockquote><div> </div><div>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").<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
}<br>
+ else if (auto *Arch = dyn_cast<Archive>(BinOrErr->get()))<br>
+ Result = handleArchive(Filename, *Arch, HandleObj);<br>
return Result;<br>
}<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>