[llvm] r310439 - [PDB] Fix an issue writing the publics stream.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 8 21:23:59 PDT 2017


Author: zturner
Date: Tue Aug  8 21:23:59 2017
New Revision: 310439

URL: http://llvm.org/viewvc/llvm-project?rev=310439&view=rev
Log:
[PDB] Fix an issue writing the publics stream.

In the refactor to merge the publics and globals stream, a bug
was introduced that wrote the wrong value for one of the fields
of the PublicsStreamHeader.  This caused debugging in WinDbg
to break.

We had no way of dumping any of these fields, so in addition to
fixing the bug I've added dumping support for them along with a
test that verifies the correct value is written.

Modified:
    llvm/trunk/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h
    llvm/trunk/include/llvm/DebugInfo/PDB/Native/PublicsStream.h
    llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
    llvm/trunk/lib/DebugInfo/PDB/Native/PublicsStream.cpp
    llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h?rev=310439&r1=310438&r2=310439&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/GlobalsStream.h Tue Aug  8 21:23:59 2017
@@ -57,6 +57,11 @@ public:
 
   Error read(BinaryStreamReader &Reader);
 
+  uint32_t getVerSignature() const { return HashHdr->VerSignature; }
+  uint32_t getVerHeader() const { return HashHdr->VerHdr; }
+  uint32_t getHashRecordSize() const { return HashHdr->HrSize; }
+  uint32_t getNumBuckets() const { return HashHdr->NumBuckets; }
+
   typedef GSIHashHeader iterator;
   GSIHashIterator begin() const { return GSIHashIterator(HashRecords.begin()); }
   GSIHashIterator end() const { return GSIHashIterator(HashRecords.end()); }

Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Native/PublicsStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Native/PublicsStream.h?rev=310439&r1=310438&r2=310439&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Native/PublicsStream.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Native/PublicsStream.h Tue Aug  8 21:23:59 2017
@@ -32,7 +32,8 @@ public:
   Error reload();
 
   uint32_t getSymHash() const;
-  uint32_t getAddrMap() const;
+  uint16_t getThunkTableSection() const;
+  uint32_t getThunkTableOffset() const;
   const GSIHashTable &getPublicsTable() const { return PublicsTable; }
   FixedStreamArray<support::ulittle32_t> getAddressMap() const {
     return AddressMap;

Modified: llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp?rev=310439&r1=310438&r2=310439&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/GSIStreamBuilder.cpp Tue Aug  8 21:23:59 2017
@@ -153,7 +153,6 @@ Error GSIStreamBuilder::finalizeMsfLayou
   if (!Idx)
     return Idx.takeError();
   PSH->StreamIndex = *Idx;
-
   Idx = Msf.addStream(calculateGlobalsHashStreamSize());
   if (!Idx)
     return Idx.takeError();
@@ -253,32 +252,22 @@ Error GSIStreamBuilder::commitSymbolReco
 
 Error GSIStreamBuilder::commitPublicsHashStream(
     WritableBinaryStreamRef Stream) {
-  // Skip the publics stream header so that we can write the GSH header first.
-  // Then seek back to the beginning and update the publics stream header with
-  // the byte offset after the GSH header.
   BinaryStreamWriter Writer(Stream);
-  Writer.setOffset(sizeof(PublicsStreamHeader));
-
-  if (auto EC = PSH->commit(Writer))
-    return EC;
-  uint32_t OffsetAfterGSIHashes = Writer.getOffset();
-
-  Writer.setOffset(0);
-
-  // FIXME: Fill these in. They are for incremental linking.
   PublicsStreamHeader Header;
-  Header.AddrMap = PSH->Records.size() * 4;
 
+  // FIXME: Fill these in. They are for incremental linking.
   Header.NumThunks = 0;
   Header.SizeOfThunk = 0;
   Header.ISectThunkTable = 0;
   Header.OffThunkTable = 0;
   Header.NumSections = 0;
-  Header.SymHash = OffsetAfterGSIHashes;
+  Header.SymHash = PSH->calculateSerializedLength();
+  Header.AddrMap = PSH->Records.size() * 4;
   if (auto EC = Writer.writeObject(Header))
     return EC;
 
-  Writer.setOffset(OffsetAfterGSIHashes);
+  if (auto EC = PSH->commit(Writer))
+    return EC;
 
   std::vector<ulittle32_t> AddrMap = computeAddrMap(PSH->Records);
   if (auto EC = Writer.writeArray(makeArrayRef(AddrMap)))

Modified: llvm/trunk/lib/DebugInfo/PDB/Native/PublicsStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Native/PublicsStream.cpp?rev=310439&r1=310438&r2=310439&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Native/PublicsStream.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Native/PublicsStream.cpp Tue Aug  8 21:23:59 2017
@@ -46,7 +46,12 @@ PublicsStream::PublicsStream(std::unique
 PublicsStream::~PublicsStream() = default;
 
 uint32_t PublicsStream::getSymHash() const { return Header->SymHash; }
-uint32_t PublicsStream::getAddrMap() const { return Header->AddrMap; }
+uint16_t PublicsStream::getThunkTableSection() const {
+  return Header->ISectThunkTable;
+}
+uint32_t PublicsStream::getThunkTableOffset() const {
+  return Header->OffThunkTable;
+}
 
 // Publics stream contains fixed-size headers and a serialized hash table.
 // This implementation is not complete yet. It reads till the end of the

Modified: llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp?rev=310439&r1=310438&r2=310439&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbutil/DumpOutputStyle.cpp Tue Aug  8 21:23:59 2017
@@ -896,6 +896,13 @@ Error DumpOutputStyle::dumpPublics() {
   auto &Publics = Err(File.getPDBPublicsStream());
 
   const GSIHashTable &PublicsTable = Publics.getPublicsTable();
+  if (opts::dump::DumpPublicExtras) {
+    P.printLine("Publics Header");
+    AutoIndent Indent(P);
+    P.formatLine("sym hash = {0}, thunk table addr = {1}", Publics.getSymHash(),
+                 formatSegmentOffset(Publics.getThunkTableSection(),
+                                     Publics.getThunkTableOffset()));
+  }
   Err(dumpSymbolsFromGSI(PublicsTable, opts::dump::DumpPublicExtras));
 
   // Skip the rest if we aren't dumping extras.
@@ -941,30 +948,42 @@ Error DumpOutputStyle::dumpSymbolsFromGS
   auto ExpectedIds = initializeTypes(StreamIPI);
   if (!ExpectedIds)
     return ExpectedIds.takeError();
-  SymbolVisitorCallbackPipeline Pipeline;
-  SymbolDeserializer Deserializer(nullptr, CodeViewContainer::Pdb);
-  MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, *ExpectedIds,
-                             *ExpectedTypes);
-
-  Pipeline.addCallbackToPipeline(Deserializer);
-  Pipeline.addCallbackToPipeline(Dumper);
-  CVSymbolVisitor Visitor(Pipeline);
-
-  BinaryStreamRef SymStream =
-      ExpectedSyms->getSymbolArray().getUnderlyingStream();
-  for (uint32_t PubSymOff : Table) {
-    Expected<CVSymbol> Sym = readSymbolFromStream(SymStream, PubSymOff);
-    if (!Sym)
-      return Sym.takeError();
-    if (auto E = Visitor.visitSymbolRecord(*Sym, PubSymOff))
-      return E;
+
+  if (HashExtras) {
+    P.printLine("GSI Header");
+    AutoIndent Indent(P);
+    P.formatLine("sig = {0:X}, hdr = {1:X}, hr size = {2}, num buckets = {3}",
+                 Table.getVerSignature(), Table.getVerHeader(),
+                 Table.getHashRecordSize(), Table.getNumBuckets());
+  }
+
+  {
+    P.printLine("Records");
+    SymbolVisitorCallbackPipeline Pipeline;
+    SymbolDeserializer Deserializer(nullptr, CodeViewContainer::Pdb);
+    MinimalSymbolDumper Dumper(P, opts::dump::DumpSymRecordBytes, *ExpectedIds,
+                               *ExpectedTypes);
+
+    Pipeline.addCallbackToPipeline(Deserializer);
+    Pipeline.addCallbackToPipeline(Dumper);
+    CVSymbolVisitor Visitor(Pipeline);
+
+    BinaryStreamRef SymStream =
+        ExpectedSyms->getSymbolArray().getUnderlyingStream();
+    for (uint32_t PubSymOff : Table) {
+      Expected<CVSymbol> Sym = readSymbolFromStream(SymStream, PubSymOff);
+      if (!Sym)
+        return Sym.takeError();
+      if (auto E = Visitor.visitSymbolRecord(*Sym, PubSymOff))
+        return E;
+    }
   }
 
   // Return early if we aren't dumping public hash table and address map info.
   if (!HashExtras)
     return Error::success();
 
-  P.formatLine("Hash Records");
+  P.formatLine("Hash Entries");
   {
     AutoIndent Indent2(P);
     for (const PSHashRecord &HR : Table.HashRecords)




More information about the llvm-commits mailing list