mirror of
https://github.com/RPCSX/llvm.git
synced 2026-01-31 01:05:23 +01:00
In order to efficiently write PDBs, we need to be able to make a StreamWriter class similar to a StreamReader, which can transparently deal with writing to discontiguous streams, and we need to use this for all writing, similar to how we use StreamReader for all reading. Most discontiguous streams are the typical numbered streams that appear in a PDB file and are described by the directory, but the exception to this, that until now has been parsed by hand, is the directory itself. MappedBlockStream works by querying the directory to find out which blocks a stream occupies and various other things, so naturally the same logic could not possibly work to describe the blocks that the directory itself resided on. To solve this, I've introduced an abstraction IPDBStreamData, which allows the client to query for the list of blocks occupied by the stream, as well as the stream length. I provide two implementations of this: one which queries the directory (for indexed streams), and one which queries the super block (for the directory stream). This has the side benefit of vastly simplifying the code to parse the directory. Whereas before a mini state machine was rolled by hand, now we simply use FixedStreamArray to read out the stream sizes, then build a vector of FixedStreamArrays for the stream map, all in just a few lines of code. Reviewed By: ruiu Differential Revision: http://reviews.llvm.org/D21046 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271982 91177308-0d34-0410-b5e6-96231b3b80d8
79 lines
2.6 KiB
C++
79 lines
2.6 KiB
C++
//===- ModStream.cpp - PDB Module Info Stream Access ----------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/DebugInfo/PDB/Raw/ModStream.h"
|
|
|
|
#include "llvm/DebugInfo/CodeView/StreamReader.h"
|
|
#include "llvm/DebugInfo/PDB/Raw/IndexedStreamData.h"
|
|
#include "llvm/DebugInfo/PDB/Raw/ModInfo.h"
|
|
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
|
#include "llvm/DebugInfo/PDB/Raw/RawError.h"
|
|
#include "llvm/DebugInfo/PDB/Raw/RawTypes.h"
|
|
|
|
using namespace llvm;
|
|
using namespace llvm::pdb;
|
|
|
|
ModStream::ModStream(const PDBFile &File, const ModInfo &Module)
|
|
: Mod(Module), Stream(llvm::make_unique<IndexedStreamData>(
|
|
Module.getModuleStreamIndex(), File),
|
|
File) {}
|
|
|
|
ModStream::~ModStream() {}
|
|
|
|
Error ModStream::reload() {
|
|
codeview::StreamReader Reader(Stream);
|
|
|
|
uint32_t SymbolSize = Mod.getSymbolDebugInfoByteSize();
|
|
uint32_t C11Size = Mod.getLineInfoByteSize();
|
|
uint32_t C13Size = Mod.getC13LineInfoByteSize();
|
|
|
|
if (C11Size > 0 && C13Size > 0)
|
|
return llvm::make_error<RawError>(raw_error_code::corrupt_file,
|
|
"Module has both C11 and C13 line info");
|
|
|
|
codeview::StreamRef S;
|
|
|
|
uint32_t SymbolSubstreamSig = 0;
|
|
if (auto EC = Reader.readInteger(SymbolSubstreamSig))
|
|
return EC;
|
|
if (auto EC = Reader.readArray(SymbolsSubstream, SymbolSize - 4))
|
|
return EC;
|
|
|
|
if (auto EC = Reader.readStreamRef(LinesSubstream, C11Size))
|
|
return EC;
|
|
if (auto EC = Reader.readStreamRef(C13LinesSubstream, C13Size))
|
|
return EC;
|
|
|
|
codeview::StreamReader LineReader(C13LinesSubstream);
|
|
if (auto EC = LineReader.readArray(LineInfo, LineReader.bytesRemaining()))
|
|
return EC;
|
|
|
|
uint32_t GlobalRefsSize;
|
|
if (auto EC = Reader.readInteger(GlobalRefsSize))
|
|
return EC;
|
|
if (auto EC = Reader.readStreamRef(GlobalRefsSubstream, GlobalRefsSize))
|
|
return EC;
|
|
if (Reader.bytesRemaining() > 0)
|
|
return llvm::make_error<RawError>(raw_error_code::corrupt_file,
|
|
"Unexpected bytes in module stream.");
|
|
|
|
return Error::success();
|
|
}
|
|
|
|
iterator_range<codeview::CVSymbolArray::Iterator>
|
|
ModStream::symbols(bool *HadError) const {
|
|
return llvm::make_range(SymbolsSubstream.begin(HadError),
|
|
SymbolsSubstream.end());
|
|
}
|
|
|
|
iterator_range<codeview::ModuleSubstreamArray::Iterator>
|
|
ModStream::lines(bool *HadError) const {
|
|
return llvm::make_range(LineInfo.begin(HadError), LineInfo.end());
|
|
}
|