mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 11:02:59 +02:00
Define DbiStreamBuilder::addDbgStream to add stream.
Previously, there is no way to create a stream other than pre-defined special stream such as DBI or IPI. This patch adds a new method, addDbgStream, to add a debug stream to a PDB file. Differential Revision: https://reviews.llvm.org/D25356 llvm-svn: 283823
This commit is contained in:
parent
2fa8e84ed6
commit
b3845e5ad0
@ -19,6 +19,7 @@
|
|||||||
#include "llvm/DebugInfo/PDB/PDBTypes.h"
|
#include "llvm/DebugInfo/PDB/PDBTypes.h"
|
||||||
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
||||||
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
|
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
|
||||||
|
#include "llvm/Support/Endian.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace msf {
|
namespace msf {
|
||||||
@ -44,6 +45,9 @@ public:
|
|||||||
void setFlags(uint16_t F);
|
void setFlags(uint16_t F);
|
||||||
void setMachineType(PDB_Machine M);
|
void setMachineType(PDB_Machine M);
|
||||||
|
|
||||||
|
// Add given bytes as a new stream.
|
||||||
|
Error addDbgStream(pdb::DbgHeaderType Type, ArrayRef<uint8_t> Data);
|
||||||
|
|
||||||
uint32_t calculateSerializedLength() const;
|
uint32_t calculateSerializedLength() const;
|
||||||
|
|
||||||
Error addModuleInfo(StringRef ObjFile, StringRef Module);
|
Error addModuleInfo(StringRef ObjFile, StringRef Module);
|
||||||
@ -57,6 +61,11 @@ public:
|
|||||||
const msf::WritableStream &Buffer);
|
const msf::WritableStream &Buffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
struct DebugStream {
|
||||||
|
ArrayRef<uint8_t> Data;
|
||||||
|
uint16_t StreamNumber = kInvalidStreamIndex;
|
||||||
|
};
|
||||||
|
|
||||||
Error finalize();
|
Error finalize();
|
||||||
uint32_t calculateModiSubstreamSize() const;
|
uint32_t calculateModiSubstreamSize() const;
|
||||||
uint32_t calculateFileInfoSubstreamSize() const;
|
uint32_t calculateFileInfoSubstreamSize() const;
|
||||||
@ -92,6 +101,7 @@ private:
|
|||||||
msf::WritableStreamRef NamesBuffer;
|
msf::WritableStreamRef NamesBuffer;
|
||||||
msf::MutableByteStream ModInfoBuffer;
|
msf::MutableByteStream ModInfoBuffer;
|
||||||
msf::MutableByteStream FileInfoBuffer;
|
msf::MutableByteStream FileInfoBuffer;
|
||||||
|
llvm::SmallVector<DebugStream, (int)DbgHeaderType::Max> DbgStreams;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "llvm/ADT/BitVector.h"
|
#include "llvm/ADT/BitVector.h"
|
||||||
#include "llvm/ADT/Optional.h"
|
#include "llvm/ADT/Optional.h"
|
||||||
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
#include "llvm/DebugInfo/PDB/Raw/PDBFile.h"
|
||||||
|
#include "llvm/DebugInfo/PDB/Raw/RawConstants.h"
|
||||||
#include "llvm/Support/Allocator.h"
|
#include "llvm/Support/Allocator.h"
|
||||||
#include "llvm/Support/Endian.h"
|
#include "llvm/Support/Endian.h"
|
||||||
#include "llvm/Support/Error.h"
|
#include "llvm/Support/Error.h"
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h"
|
#include "llvm/DebugInfo/PDB/Raw/DbiStreamBuilder.h"
|
||||||
|
|
||||||
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/DebugInfo/MSF/MSFBuilder.h"
|
#include "llvm/DebugInfo/MSF/MSFBuilder.h"
|
||||||
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
|
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
|
||||||
#include "llvm/DebugInfo/MSF/StreamWriter.h"
|
#include "llvm/DebugInfo/MSF/StreamWriter.h"
|
||||||
@ -43,10 +44,24 @@ void DbiStreamBuilder::setFlags(uint16_t F) { Flags = F; }
|
|||||||
|
|
||||||
void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; }
|
void DbiStreamBuilder::setMachineType(PDB_Machine M) { MachineType = M; }
|
||||||
|
|
||||||
|
Error DbiStreamBuilder::addDbgStream(pdb::DbgHeaderType Type,
|
||||||
|
ArrayRef<uint8_t> Data) {
|
||||||
|
if (DbgStreams[(int)Type].StreamNumber == kInvalidStreamIndex)
|
||||||
|
return make_error<RawError>(raw_error_code::duplicate_entry,
|
||||||
|
"The specified stream type already exists");
|
||||||
|
auto ExpectedIndex = Msf.addStream(Data.size());
|
||||||
|
if (!ExpectedIndex)
|
||||||
|
return ExpectedIndex.takeError();
|
||||||
|
uint32_t Index = std::move(*ExpectedIndex);
|
||||||
|
DbgStreams[(int)Type].Data = Data;
|
||||||
|
DbgStreams[(int)Type].StreamNumber = Index;
|
||||||
|
return Error::success();
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t DbiStreamBuilder::calculateSerializedLength() const {
|
uint32_t DbiStreamBuilder::calculateSerializedLength() const {
|
||||||
// For now we only support serializing the header.
|
// For now we only support serializing the header.
|
||||||
return sizeof(DbiStreamHeader) + calculateFileInfoSubstreamSize() +
|
return sizeof(DbiStreamHeader) + calculateFileInfoSubstreamSize() +
|
||||||
calculateModiSubstreamSize();
|
calculateModiSubstreamSize() + DbgStreams.size() * sizeof(uint16_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
Error DbiStreamBuilder::addModuleInfo(StringRef ObjFile, StringRef Module) {
|
Error DbiStreamBuilder::addModuleInfo(StringRef ObjFile, StringRef Module) {
|
||||||
@ -216,7 +231,7 @@ Error DbiStreamBuilder::finalize() {
|
|||||||
H->ECSubstreamSize = 0;
|
H->ECSubstreamSize = 0;
|
||||||
H->FileInfoSize = FileInfoBuffer.getLength();
|
H->FileInfoSize = FileInfoBuffer.getLength();
|
||||||
H->ModiSubstreamSize = ModInfoBuffer.getLength();
|
H->ModiSubstreamSize = ModInfoBuffer.getLength();
|
||||||
H->OptionalDbgHdrSize = 0;
|
H->OptionalDbgHdrSize = DbgStreams.size() * sizeof(uint16_t);
|
||||||
H->SecContrSubstreamSize = 0;
|
H->SecContrSubstreamSize = 0;
|
||||||
H->SectionMapSize = 0;
|
H->SectionMapSize = 0;
|
||||||
H->TypeServerSize = 0;
|
H->TypeServerSize = 0;
|
||||||
@ -273,6 +288,19 @@ Error DbiStreamBuilder::commit(const msf::MSFLayout &Layout,
|
|||||||
return EC;
|
return EC;
|
||||||
if (auto EC = Writer.writeStreamRef(FileInfoBuffer))
|
if (auto EC = Writer.writeStreamRef(FileInfoBuffer))
|
||||||
return EC;
|
return EC;
|
||||||
|
for (auto &Stream : DbgStreams)
|
||||||
|
if (auto EC = Writer.writeInteger(Stream.StreamNumber))
|
||||||
|
return EC;
|
||||||
|
|
||||||
|
for (auto &Stream : DbgStreams) {
|
||||||
|
if (Stream.StreamNumber == kInvalidStreamIndex)
|
||||||
|
continue;
|
||||||
|
auto WritableStream = WritableMappedBlockStream::createIndexedStream(
|
||||||
|
Layout, Buffer, Stream.StreamNumber);
|
||||||
|
StreamWriter DbgStreamWriter(*WritableStream);
|
||||||
|
if (auto EC = DbgStreamWriter.writeArray(Stream.Data))
|
||||||
|
return EC;
|
||||||
|
}
|
||||||
|
|
||||||
if (Writer.bytesRemaining() > 0)
|
if (Writer.bytesRemaining() > 0)
|
||||||
return make_error<RawError>(raw_error_code::invalid_format,
|
return make_error<RawError>(raw_error_code::invalid_format,
|
||||||
|
Loading…
Reference in New Issue
Block a user