[lld] r255826 - Add more debugging output to MachO lld. NFC.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 16 14:03:21 PST 2015


Author: pete
Date: Wed Dec 16 16:03:21 2015
New Revision: 255826

URL: http://llvm.org/viewvc/llvm-project?rev=255826&view=rev
Log:
Add more debugging output to MachO lld.  NFC.

In debug builds there's now a dump method on Section and improved
printing of atoms.

Modified:
    lld/trunk/lib/Core/Resolver.cpp
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=255826&r1=255825&r2=255826&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Wed Dec 16 16:03:21 2015
@@ -179,6 +179,8 @@ void Resolver::doDefinedAtom(const Defin
                     << atom.ordinal()
                     << ", name="
                     << atom.name()
+                    << ", type="
+                    << atom.contentType()
                     << "\n");
 
   // add to list of known atoms
@@ -525,12 +527,29 @@ bool Resolver::resolve() {
 void Resolver::MergedFile::addAtoms(std::vector<const Atom *> &all) {
   ScopedTask task(getDefaultDomain(), "addAtoms");
   DEBUG_WITH_TYPE("resolver", llvm::dbgs() << "Resolver final atom list:\n");
+
   for (const Atom *atom : all) {
-    DEBUG_WITH_TYPE("resolver", llvm::dbgs()
-                    << llvm::format("    0x%09lX", atom)
-                    << ", name="
-                    << atom->name()
-                    << "\n");
+#ifndef NDEBUG
+    if (auto *definedAtom = dyn_cast<DefinedAtom>(atom)) {
+      DEBUG_WITH_TYPE("resolver", llvm::dbgs()
+                      << llvm::format("    0x%09lX", atom)
+                      << ", file=#"
+                      << definedAtom->file().ordinal()
+                      << ", atom=#"
+                      << definedAtom->ordinal()
+                      << ", name="
+                      << definedAtom->name()
+                      << ", type="
+                      << definedAtom->contentType()
+                      << "\n");
+    } else {
+      DEBUG_WITH_TYPE("resolver", llvm::dbgs()
+                      << llvm::format("    0x%09lX", atom)
+                      << ", name="
+                      << atom->name()
+                      << "\n");
+    }
+#endif
     addAtom(*atom);
   }
 }

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h?rev=255826&r1=255825&r2=255826&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFile.h Wed Dec 16 16:03:21 2015
@@ -45,6 +45,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Allocator.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/MachO.h"
 #include "llvm/Support/YAMLTraits.h"
@@ -119,6 +120,15 @@ struct Section {
   ArrayRef<uint8_t> content;
   Relocations     relocations;
   IndirectSymbols indirectSymbols;
+
+#ifndef NDEBUG
+  raw_ostream& operator<<(raw_ostream &OS) const {
+    dump(OS);
+    return OS;
+  }
+
+  void dump(raw_ostream &OS = llvm::dbgs()) const;
+#endif
 };
 
 

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=255826&r1=255825&r2=255826&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Wed Dec 16 16:03:21 2015
@@ -27,13 +27,17 @@
 #include "MachONormalizedFileBinaryUtils.h"
 #include "lld/Core/Error.h"
 #include "lld/Core/LLVM.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
 #include "llvm/Support/MachO.h"
 #include "llvm/Support/LEB128.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm::MachO;
 using namespace lld::mach_o::normalized;
 
+#define DEBUG_TYPE "normalized-file-to-atoms"
+
 namespace lld {
 namespace mach_o {
 
@@ -892,10 +896,13 @@ std::error_code
 normalizedObjectToAtoms(MachOFile *file,
                         const NormalizedFile &normalizedFile,
                         bool copyRefs) {
+  DEBUG(llvm::dbgs() << "******** Normalizing file to atoms: "
+                    << file->path() << "\n");
   bool scatterable = ((normalizedFile.flags & MH_SUBSECTIONS_VIA_SYMBOLS) != 0);
 
   // Create atoms from each section.
   for (auto &sect : normalizedFile.sections) {
+    DEBUG(llvm::dbgs() << "Creating atoms: "; sect.dump());
     if (isDebugInfoSection(sect))
       continue;
     bool customSectionName;
@@ -1061,6 +1068,14 @@ normalizedToAtoms(const NormalizedFile &
   }
 }
 
+#ifndef NDEBUG
+void Section::dump(llvm::raw_ostream &OS) const {
+  OS << "Section (\"" << segmentName << ", " << sectionName << "\"";
+  OS << ", addr: " << llvm::format_hex(address, 16, true);
+  OS << ", size: " << llvm::format_hex(content.size(), 8, true) << ")\n";
+}
+#endif
+
 } // namespace normalized
 } // namespace mach_o
 } // namespace lld




More information about the llvm-commits mailing list