[lld] r189570 - [PECOFF] Add helper functions for debugging

Rui Ueyama ruiu at google.com
Thu Aug 29 00:17:47 PDT 2013


Author: ruiu
Date: Thu Aug 29 02:17:47 2013
New Revision: 189570

URL: http://llvm.org/viewvc/llvm-project?rev=189570&view=rev
Log:
[PECOFF] Add helper functions for debugging

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp

Modified: lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp?rev=189570&r1=189569&r2=189570&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/WriterPECOFF.cpp Thu Aug 29 02:17:47 2013
@@ -43,6 +43,7 @@
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileOutputBuffer.h"
+#include "llvm/Support/Format.h"
 
 using llvm::support::ulittle16_t;
 using llvm::support::ulittle32_t;
@@ -330,6 +331,17 @@ public:
     }
   }
 
+  /// Print atom VAs. Used only for debugging.
+  void printAtomAddresses(uint64_t baseAddr) {
+    for (const auto *layout : _atomLayouts) {
+      const DefinedAtom *atom = cast<DefinedAtom>(layout->_atom);
+      uint64_t addr = layout->_virtualAddr;
+      llvm::dbgs() << llvm::format("0x%08llx: ", addr + baseAddr)
+                   << (atom->name().empty() ? "(anonymous)" : atom->name())
+                   << "\n";
+    }
+  }
+
   /// List all the relocation sites that need to be fixed up if image base is
   /// relocated. Such relocation types are DIR32 and DIR32NB on i386. REL32 does
   /// not be (and should not be) fixed up because it's PC-relative.
@@ -822,6 +834,7 @@ public:
     for (const auto &chunk : _chunks)
       chunk->write(buffer->getBufferStart());
     applyAllRelocations(buffer->getBufferStart());
+    DEBUG(printAllAtomAddresses());
     return buffer->commit();
   }
 
@@ -837,6 +850,13 @@ private:
                                 _PECOFFLinkingContext.getBaseAddress());
   }
 
+  /// Print atom VAs. Used only for debugging.
+  void printAllAtomAddresses() {
+    for (auto &cp : _chunks)
+      if (AtomChunk *chunk = dyn_cast<AtomChunk>(&*cp))
+        chunk->printAtomAddresses(_PECOFFLinkingContext.getBaseAddress());
+  }
+
   void addChunk(Chunk *chunk) {
     _chunks.push_back(std::unique_ptr<Chunk>(chunk));
   }





More information about the llvm-commits mailing list