summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-07-15 22:17:08 +0000
committerZachary Turner <zturner@google.com>2016-07-15 22:17:08 +0000
commit5e534c7fb357a157793e9a47c8a00880bdb18799 (patch)
treed0df9f3be4f297dbfb463891e8961c62d9973561 /llvm/lib
parentfaa554b2fd6c327cb9cc0ac9983bd3c178f2276c (diff)
downloadbcm5719-llvm-5e534c7fb357a157793e9a47c8a00880bdb18799.tar.gz
bcm5719-llvm-5e534c7fb357a157793e9a47c8a00880bdb18799.zip
[pdb] Round trip the NameMap data structure to YAML.
llvm-svn: 275628
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp8
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp44
-rw-r--r--llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp30
3 files changed, 75 insertions, 7 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp b/llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
index 5a0e835dd56..7be9cc32db9 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
@@ -28,6 +28,10 @@ void InfoStreamBuilder::setAge(uint32_t A) { Age = A; }
void InfoStreamBuilder::setGuid(PDB_UniqueId G) { Guid = G; }
+NameMapBuilder &InfoStreamBuilder::getNamedStreamsBuilder() {
+ return NamedStreams;
+}
+
uint32_t InfoStreamBuilder::calculateSerializedLength() const {
return sizeof(InfoStream::HeaderInfo) +
NamedStreams.calculateSerializedLength();
@@ -55,5 +59,9 @@ Expected<std::unique_ptr<InfoStream>> InfoStreamBuilder::build(PDBFile &File) {
Info->Signature = *Sig;
Info->Age = *Age;
Info->Guid = *Guid;
+ auto NS = NamedStreams.build();
+ if (!NS)
+ return NS.takeError();
+ Info->NamedStreams = **NS;
return std::move(Info);
}
diff --git a/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp b/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
index 3638380eb22..b8a4eb79a48 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/NameMap.cpp
@@ -146,20 +146,56 @@ Error NameMap::load(codeview::StreamReader &Stream) {
}
Error NameMap::commit(codeview::StreamWriter &Writer) {
- if (auto EC = Writer.writeInteger(0U)) // Number of bytes in table
+ // The first field is the number of bytes of string data. So add
+ // up the length of all strings plus a null terminator for each
+ // one.
+ uint32_t NumBytes = 0;
+ for (auto B = Mapping.begin(), E = Mapping.end(); B != E; ++B) {
+ NumBytes += B->getKeyLength() + 1;
+ }
+
+ if (auto EC = Writer.writeInteger(NumBytes)) // Number of bytes of string data
return EC;
+ // Now all of the string data itself.
+ for (auto B = Mapping.begin(), E = Mapping.end(); B != E; ++B) {
+ if (auto EC = Writer.writeZeroString(B->getKey()))
+ return EC;
+ }
- if (auto EC = Writer.writeInteger(0U)) // Hash Size
+ if (auto EC = Writer.writeInteger(Mapping.size())) // Hash Size
return EC;
- if (auto EC = Writer.writeInteger(0U)) // Max Number of Strings
+ if (auto EC = Writer.writeInteger(Mapping.size())) // Max Number of Strings
return EC;
- if (auto EC = Writer.writeInteger(0U)) // Num Present Words
+ if (auto EC = Writer.writeInteger(Mapping.size())) // Num Present Words
return EC;
+ // For each entry in the mapping, write a bit mask which represents a bucket
+ // to store it in. We don't use this, so the value we write isn't important
+ // to us, it just has to be there.
+ for (auto B = Mapping.begin(), E = Mapping.end(); B != E; ++B) {
+ if (auto EC = Writer.writeInteger(1U))
+ return EC;
+ }
+
if (auto EC = Writer.writeInteger(0U)) // Num Deleted Words
return EC;
+
+ // Mappings of each word.
+ uint32_t OffsetSoFar = 0;
+ for (auto B = Mapping.begin(), E = Mapping.end(); B != E; ++B) {
+ // This is a list of key value pairs where the key is the offset into the
+ // strings buffer, and the value is a stream number. Write each pair.
+ if (auto EC = Writer.writeInteger(OffsetSoFar))
+ return EC;
+
+ if (auto EC = Writer.writeInteger(B->second))
+ return EC;
+
+ OffsetSoFar += B->getKeyLength() + 1;
+ }
+
return Error::success();
}
diff --git a/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp b/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
index fe033c368e7..41c6c2cd810 100644
--- a/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
+++ b/llvm/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
@@ -10,17 +10,41 @@
#include "llvm/DebugInfo/PDB/Raw/NameMapBuilder.h"
#include "llvm/DebugInfo/PDB/Raw/NameMap.h"
+#include "llvm/Support/Endian.h"
using namespace llvm;
using namespace llvm::pdb;
NameMapBuilder::NameMapBuilder() {}
+void NameMapBuilder::addMapping(StringRef Name, uint32_t Mapping) {
+ StringDataBytes += Name.size() + 1;
+ Map.insert({Name, Mapping});
+}
+
Expected<std::unique_ptr<NameMap>> NameMapBuilder::build() {
- return llvm::make_unique<NameMap>();
+ auto Result = llvm::make_unique<NameMap>();
+ Result->Mapping = Map;
+ return std::move(Result);
}
uint32_t NameMapBuilder::calculateSerializedLength() const {
- // For now we write an empty name map, nothing else.
- return 5 * sizeof(uint32_t);
+ uint32_t TotalLength = 0;
+
+ TotalLength += sizeof(support::ulittle32_t); // StringDataBytes value
+ TotalLength += StringDataBytes; // actual string data
+
+ TotalLength += sizeof(support::ulittle32_t); // Hash Size
+ TotalLength += sizeof(support::ulittle32_t); // Max Number of Strings
+ TotalLength += sizeof(support::ulittle32_t); // Num Present Words
+ // One bitmask word for each present entry
+ TotalLength += Map.size() * sizeof(support::ulittle32_t);
+ TotalLength += sizeof(support::ulittle32_t); // Num Deleted Words
+
+ // For each present word, which we are treating as equivalent to the number of
+ // entries in the table, we have a pair of integers. An offset into the
+ // string data, and a corresponding stream number.
+ TotalLength += Map.size() * 2 * sizeof(support::ulittle32_t);
+
+ return TotalLength;
}
OpenPOWER on IntegriCloud