20 Expected<std::string> readStreamData(BinaryStream &Stream,
uint32_t Limit) {
23 Result.reserve(DataLength);
24 while (
Offset < DataLength) {
25 ArrayRef<uint8_t>
Data;
26 if (
auto E = Stream.readLongestContiguousChunk(
Offset, Data))
35 class NativeInjectedSource final :
public IPDBInjectedSource {
36 const SrcHeaderBlockEntry &Entry;
37 const PDBStringTable &Strings;
41 NativeInjectedSource(
const SrcHeaderBlockEntry &Entry,
42 PDBFile &
File,
const PDBStringTable &Strings)
43 : Entry(Entry), Strings(Strings),
File(
File) {}
45 uint32_t getCrc32()
const override {
return Entry.CRC; }
46 uint64_t getCodeByteSize()
const override {
return Entry.FileSize; }
49 StringRef
Ret =
cantFail(Strings.getStringForID(Entry.FileNI),
50 "InjectedSourceStream should have rejected this");
51 return std::string(
Ret);
54 std::string getObjectFileName()
const override {
55 StringRef
Ret =
cantFail(Strings.getStringForID(Entry.ObjNI),
56 "InjectedSourceStream should have rejected this");
57 return std::string(
Ret);
60 std::string getVirtualFileName()
const override {
61 StringRef
Ret =
cantFail(Strings.getStringForID(Entry.VFileNI),
62 "InjectedSourceStream should have rejected this");
63 return std::string(
Ret);
66 uint32_t getCompression()
const override {
return Entry.Compression; }
68 std::string getCode()
const override {
71 cantFail(Strings.getStringForID(Entry.VFileNI),
72 "InjectedSourceStream should have rejected this");
73 std::string StreamName = (
"/src/files/" + VName).str();
78 auto ExpectedFileStream =
File.safelyCreateNamedStream(StreamName);
79 if (!ExpectedFileStream) {
81 return "(failed to open data stream)";
84 auto Data = readStreamData(**ExpectedFileStream, Entry.FileSize);
87 return "(failed to read data)";
98 :
File(
File), Stream(IJS), Strings(Strings), Cur(Stream.
begin()) {}
101 return static_cast<uint32_t>(Stream.size());
104 std::unique_ptr<IPDBInjectedSource>
108 return std::make_unique<NativeInjectedSource>(std::next(Stream.begin(),
N)->second,
113 if (Cur == Stream.end())
115 return std::make_unique<NativeInjectedSource>((Cur++)->second, File, Strings);