[codeview] Remove StreamReader copying method.

Since we want to move toward zero-copy access to stream data, we
want to remove all instances of copying operations.  So get rid
of some of those here.

Differential Revision: http://reviews.llvm.org/D20720
Reviewed By: ruiu

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@270960 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Zachary Turner 2016-05-27 03:51:53 +00:00
parent 1544fa2368
commit 9cc0faee65
8 changed files with 74 additions and 64 deletions

View File

@ -29,13 +29,13 @@ public:
StreamReader(const StreamInterface &S);
Error readBytes(uint32_t Size, ArrayRef<uint8_t> &Buffer);
Error readBytes(MutableArrayRef<uint8_t> Buffer);
Error readInteger(uint16_t &Dest);
Error readInteger(uint32_t &Dest);
Error readZeroString(StringRef &Dest);
Error readFixedString(StringRef &Dest, uint32_t Length);
Error readStreamRef(StreamRef &Ref);
Error readStreamRef(StreamRef &Ref, uint32_t Length);
Error readBytes(MutableArrayRef<uint8_t> Buffer);
template <typename T> Error readObject(const T *&Dest) {
ArrayRef<uint8_t> Buffer;
@ -60,12 +60,6 @@ public:
return Error::success();
}
template <typename T> Error readArray(MutableArrayRef<T> Array) {
MutableArrayRef<uint8_t> Casted(reinterpret_cast<uint8_t *>(Array.data()),
Array.size() * sizeof(T));
return readBytes(Casted);
}
void setOffset(uint32_t Off) { Offset = Off; }
uint32_t getOffset() const { return Offset; }
uint32_t getLength() const { return Stream.getLength(); }

View File

@ -12,7 +12,9 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/DebugInfo/CodeView/StreamArray.h"
#include "llvm/DebugInfo/CodeView/StreamRef.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include <cstdint>
#include <vector>
@ -36,11 +38,11 @@ public:
StringRef getStringForID(uint32_t ID) const;
uint32_t getIDForString(StringRef Str) const;
ArrayRef<uint32_t> name_ids() const;
codeview::FixedStreamArray<support::ulittle32_t> name_ids() const;
private:
codeview::StreamRef NamesBuffer;
std::vector<uint32_t> IDs;
codeview::FixedStreamArray<support::ulittle32_t> IDs;
uint32_t Signature;
uint32_t HashVersion;
uint32_t NameCount;

View File

@ -10,6 +10,7 @@
#ifndef LLVM_DEBUGINFO_PDB_RAW_PUBLICSSTREAM_H
#define LLVM_DEBUGINFO_PDB_RAW_PUBLICSSTREAM_H
#include "llvm/DebugInfo/CodeView/StreamArray.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
#include "llvm/DebugInfo/CodeView/TypeStream.h"
#include "llvm/DebugInfo/PDB/PDBTypes.h"
@ -25,7 +26,6 @@ class PDBFile;
class PublicsStream {
struct GSIHashHeader;
struct HashRecord;
struct HeaderInfo;
public:
@ -38,10 +38,18 @@ public:
uint32_t getAddrMap() const;
uint32_t getNumBuckets() const { return NumBuckets; }
iterator_range<codeview::SymbolIterator> getSymbols() const;
ArrayRef<uint32_t> getHashBuckets() const { return HashBuckets; }
ArrayRef<uint32_t> getAddressMap() const { return AddressMap; }
ArrayRef<uint32_t> getThunkMap() const { return ThunkMap; }
ArrayRef<uint32_t> getSectionOffsets() const { return SectionOffsets; }
codeview::FixedStreamArray<support::ulittle32_t> getHashBuckets() const {
return HashBuckets;
}
codeview::FixedStreamArray<support::ulittle32_t> getAddressMap() const {
return AddressMap;
}
codeview::FixedStreamArray<support::ulittle32_t> getThunkMap() const {
return ThunkMap;
}
codeview::FixedStreamArray<SectionOffset> getSectionOffsets() const {
return SectionOffsets;
}
private:
Error readSymbols();
@ -51,11 +59,12 @@ private:
uint32_t StreamNum;
MappedBlockStream Stream;
uint32_t NumBuckets = 0;
std::vector<HashRecord> HashRecords;
std::vector<uint32_t> HashBuckets;
std::vector<uint32_t> AddressMap;
std::vector<uint32_t> ThunkMap;
std::vector<uint32_t> SectionOffsets;
ArrayRef<uint8_t> Bitmap;
codeview::FixedStreamArray<PSHashRecord> HashRecords;
codeview::FixedStreamArray<support::ulittle32_t> HashBuckets;
codeview::FixedStreamArray<support::ulittle32_t> AddressMap;
codeview::FixedStreamArray<support::ulittle32_t> ThunkMap;
codeview::FixedStreamArray<SectionOffset> SectionOffsets;
const HeaderInfo *Header;
const GSIHashHeader *HashHdr;

View File

@ -10,6 +10,8 @@
#ifndef LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H
#define LLVM_DEBUGINFO_PDB_RAW_PDBRAWCONSTANTS_H
#include "llvm/Support/Endian.h"
#include <cstdint>
namespace llvm {
@ -71,6 +73,19 @@ enum class DbgHeaderType : uint16_t {
Max
};
// This struct is defined as "SO" in langapi/include/pdb.h.
struct SectionOffset {
support::ulittle32_t Off;
support::ulittle16_t Isect;
char Padding[2];
};
// This is HRFile.
struct PSHashRecord {
support::ulittle32_t Off; // Offset in the symbol record stream
support::ulittle32_t CRef;
};
} // end namespace pdb
} // end namespace llvm

View File

@ -211,6 +211,19 @@ public:
OS << "]\n";
}
template <typename T, typename U>
void printList(StringRef Label, const T &List, const U &Printer) {
startLine() << Label << ": [";
bool Comma = false;
for (const auto &Item : List) {
if (Comma)
OS << ", ";
Printer(OS, Item);
Comma = true;
}
OS << "]\n";
}
template <typename T> void printHexList(StringRef Label, const T &List) {
startLine() << Label << ": [";
bool Comma = false;

View File

@ -105,11 +105,9 @@ Error NameHashTable::load(codeview::StreamReader &Stream) {
if (auto EC = Stream.readObject(HashCount))
return EC;
std::vector<support::ulittle32_t> BucketArray(*HashCount);
if (auto EC = Stream.readArray<support::ulittle32_t>(BucketArray))
if (auto EC = Stream.readArray(IDs, *HashCount))
return make_error<RawError>(raw_error_code::corrupt_file,
"Could not read bucket array");
IDs.assign(BucketArray.begin(), BucketArray.end());
if (Stream.bytesRemaining() < sizeof(support::ulittle32_t))
return make_error<RawError>(raw_error_code::corrupt_file,
@ -154,4 +152,7 @@ uint32_t NameHashTable::getIDForString(StringRef Str) const {
return IDs[0];
}
ArrayRef<uint32_t> NameHashTable::name_ids() const { return IDs; }
codeview::FixedStreamArray<support::ulittle32_t>
NameHashTable::name_ids() const {
return IDs;
}

View File

@ -70,21 +70,6 @@ struct PublicsStream::GSIHashHeader {
ulittle32_t NumBuckets;
};
// This is HRFile.
struct PublicsStream::HashRecord {
ulittle32_t Off; // Offset in the symbol record stream
ulittle32_t CRef;
};
// This struct is defined as "SO" in langapi/include/pdb.h.
namespace {
struct SectionOffset {
ulittle32_t Off;
ulittle16_t Isect;
char Padding[2];
};
}
PublicsStream::PublicsStream(PDBFile &File, uint32_t StreamNum)
: Pdb(File), StreamNum(StreamNum), Stream(StreamNum, File) {}
@ -116,18 +101,18 @@ Error PublicsStream::reload() {
"Publics Stream does not contain a header.");
// An array of HashRecord follows. Read them.
if (HashHdr->HrSize % sizeof(HashRecord))
if (HashHdr->HrSize % sizeof(PSHashRecord))
return make_error<RawError>(raw_error_code::corrupt_file,
"Invalid HR array size.");
HashRecords.resize(HashHdr->HrSize / sizeof(HashRecord));
if (auto EC = Reader.readArray<HashRecord>(HashRecords))
uint32_t NumHashRecords = HashHdr->HrSize / sizeof(PSHashRecord);
if (auto EC = Reader.readArray(HashRecords, NumHashRecords))
return make_error<RawError>(raw_error_code::corrupt_file,
"Could not read an HR array");
// A bitmap of a fixed length follows.
size_t BitmapSizeInBits = alignTo(IPHR_HASH + 1, 32);
std::vector<uint8_t> Bitmap(BitmapSizeInBits / 8);
if (auto EC = Reader.readArray<uint8_t>(Bitmap))
uint32_t NumBitmapEntries = BitmapSizeInBits / 8;
if (auto EC = Reader.readBytes(NumBitmapEntries, Bitmap))
return make_error<RawError>(raw_error_code::corrupt_file,
"Could not read a bitmap.");
for (uint8_t B : Bitmap)
@ -139,40 +124,25 @@ Error PublicsStream::reload() {
// corrupted streams.
// Hash buckets follow.
std::vector<ulittle32_t> TempHashBuckets(NumBuckets);
if (auto EC = Reader.readArray<ulittle32_t>(TempHashBuckets))
if (auto EC = Reader.readArray(HashBuckets, NumBuckets))
return make_error<RawError>(raw_error_code::corrupt_file,
"Hash buckets corrupted.");
HashBuckets.resize(NumBuckets);
std::copy(TempHashBuckets.begin(), TempHashBuckets.end(),
HashBuckets.begin());
// Something called "address map" follows.
std::vector<ulittle32_t> TempAddressMap(Header->AddrMap / sizeof(uint32_t));
if (auto EC = Reader.readArray<ulittle32_t>(TempAddressMap))
uint32_t NumAddressMapEntries = Header->AddrMap / sizeof(uint32_t);
if (auto EC = Reader.readArray(AddressMap, NumAddressMapEntries))
return make_error<RawError>(raw_error_code::corrupt_file,
"Could not read an address map.");
AddressMap.resize(Header->AddrMap / sizeof(uint32_t));
std::copy(TempAddressMap.begin(), TempAddressMap.end(), AddressMap.begin());
// Something called "thunk map" follows.
std::vector<ulittle32_t> TempThunkMap(Header->NumThunks);
ThunkMap.resize(Header->NumThunks);
if (auto EC = Reader.readArray<ulittle32_t>(TempThunkMap))
if (auto EC = Reader.readArray(ThunkMap, Header->NumThunks))
return make_error<RawError>(raw_error_code::corrupt_file,
"Could not read a thunk map.");
ThunkMap.resize(Header->NumThunks);
std::copy(TempThunkMap.begin(), TempThunkMap.end(), ThunkMap.begin());
// Something called "section map" follows.
std::vector<SectionOffset> Offsets(Header->NumSections);
if (auto EC = Reader.readArray<SectionOffset>(Offsets))
if (auto EC = Reader.readArray(SectionOffsets, Header->NumSections))
return make_error<RawError>(raw_error_code::corrupt_file,
"Could not read a section map.");
for (auto &SO : Offsets) {
SectionOffsets.push_back(SO.Off);
SectionOffsets.push_back(SO.Isect);
}
if (Reader.bytesRemaining() > 0)
return make_error<RawError>(raw_error_code::corrupt_file,

View File

@ -569,6 +569,11 @@ static Error dumpTpiStream(ScopedPrinter &P, PDBFile &File,
return Error::success();
}
static void printSectionOffset(llvm::raw_ostream &OS,
const SectionOffset &Off) {
OS << Off.Off << ", " << Off.Isect;
}
static Error dumpPublicsStream(ScopedPrinter &P, PDBFile &File,
codeview::CVTypeDumper &TD) {
if (!opts::DumpPublics)
@ -586,7 +591,8 @@ static Error dumpPublicsStream(ScopedPrinter &P, PDBFile &File,
P.printList("Hash Buckets", Publics.getHashBuckets());
P.printList("Address Map", Publics.getAddressMap());
P.printList("Thunk Map", Publics.getThunkMap());
P.printList("Section Offsets", Publics.getSectionOffsets());
P.printList("Section Offsets", Publics.getSectionOffsets(),
printSectionOffset);
ListScope L(P, "Symbols");
codeview::CVSymbolDumper SD(P, TD, nullptr, false);
for (auto S : Publics.getSymbols()) {