[llvm] r275628 - [pdb] Round trip the NameMap data structure to YAML.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 15 15:17:08 PDT 2016
Author: zturner
Date: Fri Jul 15 17:17:08 2016
New Revision: 275628
URL: http://llvm.org/viewvc/llvm-project?rev=275628&view=rev
Log:
[pdb] Round trip the NameMap data structure to YAML.
Modified:
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h
llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h
llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp
llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test
llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp
llvm/trunk/tools/llvm-pdbdump/PdbYaml.h
llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp
llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/InfoStreamBuilder.h Fri Jul 15 17:17:08 2016
@@ -33,6 +33,8 @@ public:
void setAge(uint32_t A);
void setGuid(PDB_UniqueId G);
+ NameMapBuilder &getNamedStreamsBuilder();
+
uint32_t calculateSerializedLength() const;
Expected<std::unique_ptr<InfoStream>> build(PDBFile &File);
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMap.h Fri Jul 15 17:17:08 2016
@@ -21,8 +21,10 @@ class StreamReader;
class StreamWriter;
}
namespace pdb {
-
+class NameMapBuilder;
class NameMap {
+ friend NameMapBuilder;
+
public:
NameMap();
Modified: llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/PDB/Raw/NameMapBuilder.h Fri Jul 15 17:17:08 2016
@@ -10,6 +10,7 @@
#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBNAMEMAPBUILDER_H
#define LLVM_DEBUGINFO_PDB_RAW_PDBNAMEMAPBUILDER_H
+#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Error.h"
#include <cstdint>
@@ -23,9 +24,15 @@ class NameMapBuilder {
public:
NameMapBuilder();
+ void addMapping(StringRef Name, uint32_t Mapping);
+
Expected<std::unique_ptr<NameMap>> build();
uint32_t calculateSerializedLength() const;
+
+private:
+ StringMap<uint32_t> Map;
+ uint32_t StringDataBytes = 0;
};
} // end namespace pdb
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/InfoStreamBuilder.cpp Fri Jul 15 17:17:08 2016
@@ -28,6 +28,10 @@ void InfoStreamBuilder::setAge(uint32_t
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>> In
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);
}
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NameMap.cpp Fri Jul 15 17:17:08 2016
@@ -146,20 +146,56 @@ Error NameMap::load(codeview::StreamRead
}
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();
}
Modified: llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp (original)
+++ llvm/trunk/lib/DebugInfo/PDB/Raw/NameMapBuilder.cpp Fri Jul 15 17:17:08 2016
@@ -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;
}
Modified: llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test (original)
+++ llvm/trunk/test/DebugInfo/PDB/pdbdump-yaml.test Fri Jul 15 17:17:08 2016
@@ -74,6 +74,13 @@
; YAML-NEXT: Guid: '{0B355641-86A0-A249-896F-9988FAE52FF0}'
; YAML-NEXT: Signature: 1424295906
; YAML-NEXT: Version: VC70
+; YAML-NEXT: NamedStreams:
+; YAML-NEXT: - Name: /names
+; YAML-NEXT: StreamNum: 13
+; YAML-NEXT: - Name: /LinkInfo
+; YAML-NEXT: StreamNum: 5
+; YAML-NEXT: - Name: /src/headerblock
+; YAML-NEXT: StreamNum: 9
; YAML-NEXT: ...
; NO-HEADERS: ---
Modified: llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/PdbYaml.cpp Fri Jul 15 17:17:08 2016
@@ -142,6 +142,7 @@ void MappingTraits<PdbInfoStream>::mappi
IO.mapRequired("Guid", Obj.Guid);
IO.mapRequired("Signature", Obj.Signature);
IO.mapRequired("Version", Obj.Version);
+ IO.mapRequired("NamedStreams", Obj.NamedStreams);
}
void MappingTraits<PdbDbiStream>::mapping(IO &IO, PdbDbiStream &Obj) {
@@ -153,3 +154,9 @@ void MappingTraits<PdbDbiStream>::mappin
IO.mapRequired("Flags", Obj.Flags);
IO.mapRequired("MachineType", Obj.MachineType);
}
+
+void MappingTraits<NamedStreamMapping>::mapping(IO &IO,
+ NamedStreamMapping &Obj) {
+ IO.mapRequired("Name", Obj.StreamName);
+ IO.mapRequired("StreamNum", Obj.StreamNumber);
+}
Modified: llvm/trunk/tools/llvm-pdbdump/PdbYaml.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/PdbYaml.h?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/PdbYaml.h (original)
+++ llvm/trunk/tools/llvm-pdbdump/PdbYaml.h Fri Jul 15 17:17:08 2016
@@ -38,11 +38,17 @@ struct StreamBlockList {
std::vector<uint32_t> Blocks;
};
+struct NamedStreamMapping {
+ StringRef StreamName;
+ uint32_t StreamNumber;
+};
+
struct PdbInfoStream {
PdbRaw_ImplVer Version;
uint32_t Signature;
uint32_t Age;
PDB_UniqueId Guid;
+ std::vector<NamedStreamMapping> NamedStreams;
};
struct PdbDbiStream {
@@ -92,10 +98,15 @@ template <> struct MappingTraits<pdb::ya
template <> struct MappingTraits<pdb::yaml::PdbDbiStream> {
static void mapping(IO &IO, pdb::yaml::PdbDbiStream &Obj);
};
+
+template <> struct MappingTraits<pdb::yaml::NamedStreamMapping> {
+ static void mapping(IO &IO, pdb::yaml::NamedStreamMapping &Obj);
+};
}
}
LLVM_YAML_IS_SEQUENCE_VECTOR(uint32_t)
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::NamedStreamMapping)
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::pdb::yaml::StreamBlockList)
#endif // LLVM_TOOLS_LLVMPDBDUMP_PDBYAML_H
Modified: llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/YAMLOutputStyle.cpp Fri Jul 15 17:17:08 2016
@@ -106,6 +106,12 @@ Error YAMLOutputStyle::dumpPDBStream() {
Obj.PdbStream->Guid = InfoS.getGuid();
Obj.PdbStream->Signature = InfoS.getSignature();
Obj.PdbStream->Version = InfoS.getVersion();
+ for (auto &NS : InfoS.named_streams()) {
+ yaml::NamedStreamMapping Mapping;
+ Mapping.StreamName = NS.getKey();
+ Mapping.StreamNumber = NS.getValue();
+ Obj.PdbStream->NamedStreams.push_back(Mapping);
+ }
return Error::success();
}
Modified: llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp?rev=275628&r1=275627&r2=275628&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp (original)
+++ llvm/trunk/tools/llvm-pdbdump/llvm-pdbdump.cpp Fri Jul 15 17:17:08 2016
@@ -361,6 +361,9 @@ static void yamlToPdb(StringRef Path) {
InfoBuilder.setGuid(YamlObj.PdbStream->Guid);
InfoBuilder.setSignature(YamlObj.PdbStream->Signature);
InfoBuilder.setVersion(YamlObj.PdbStream->Version);
+ for (auto &NM : YamlObj.PdbStream->NamedStreams)
+ InfoBuilder.getNamedStreamsBuilder().addMapping(NM.StreamName,
+ NM.StreamNumber);
}
if (YamlObj.DbiStream.hasValue()) {
More information about the llvm-commits
mailing list