llvm.org GIT mirror llvm / 7aa4746
[llvm-pdbdump] Propagate errors a little more consistently PDBFile::getBlockData didn't really return any indication that it failed. It merely returned an empty buffer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275009 91177308-0d34-0410-b5e6-96231b3b80d8 David Majnemer 3 years ago
6 changed file(s) with 27 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
2828
2929 Error readBytes(uint32_t Offset, uint32_t Size,
3030 ArrayRef &Buffer) const override {
31 if (ViewOffset + Offset < Offset)
32 return make_error(cv_error_code::insufficient_buffer);
3133 if (Size + Offset > Length)
3234 return make_error(cv_error_code::insufficient_buffer);
3335 return Stream->readBytes(ViewOffset + Offset, Size, Buffer);
3232 virtual ArrayRef
3333 getStreamBlockList(uint32_t StreamIndex) const = 0;
3434
35 virtual ArrayRef getBlockData(uint32_t BlockIndex,
36 uint32_t NumBytes) const = 0;
35 virtual Expected> getBlockData(uint32_t BlockIndex,
36 uint32_t NumBytes) const = 0;
3737 virtual Error setBlockData(uint32_t BlockIndex, uint32_t Offset,
3838 ArrayRef Data) const = 0;
3939 };
8383 getStreamBlockList(uint32_t StreamIndex) const override;
8484 size_t getFileSize() const;
8585
86 ArrayRef getBlockData(uint32_t BlockIndex,
87 uint32_t NumBytes) const override;
86 Expected> getBlockData(uint32_t BlockIndex,
87 uint32_t NumBytes) const override;
8888 Error setBlockData(uint32_t BlockIndex, uint32_t Offset,
8989 ArrayRef Data) const override;
9090
138138 uint32_t BlockSpan = Last - First + 1;
139139 uint32_t ByteSpan =
140140 BytesFromFirstBlock + (BlockSpan - 1) * Pdb.getBlockSize();
141 Buffer = Pdb.getBlockData(BlockList[First], Pdb.getBlockSize());
142 Buffer = Buffer.drop_front(OffsetInFirstBlock);
141 auto Result = Pdb.getBlockData(BlockList[First], Pdb.getBlockSize());
142 if (!Result)
143 return Result.takeError();
144 Buffer = Result->drop_front(OffsetInFirstBlock);
143145 Buffer = ArrayRef(Buffer.data(), ByteSpan);
144146 return Error::success();
145147 }
172174 }
173175
174176 uint32_t FirstBlockAddr = BlockList[BlockNum];
175 auto Data = Pdb.getBlockData(FirstBlockAddr, Pdb.getBlockSize());
176 Data = Data.drop_front(OffsetInBlock);
177 auto Result = Pdb.getBlockData(FirstBlockAddr, Pdb.getBlockSize());
178 if (!Result) {
179 consumeError(Result.takeError());
180 return false;
181 }
182 auto Data = Result->drop_front(OffsetInBlock);
177183 Buffer = ArrayRef(Data.data(), Size);
178184 return true;
179185 }
196202 while (BytesLeft > 0) {
197203 uint32_t StreamBlockAddr = BlockList[BlockNum];
198204
199 auto Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());
200
205 auto Result = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize());
206 if (!Result)
207 return Result.takeError();
208
209 auto Data = *Result;
201210 const uint8_t *ChunkStart = Data.data() + OffsetInBlock;
202211 uint32_t BytesInChunk =
203212 std::min(BytesLeft, Pdb.getBlockSize() - OffsetInBlock);
7272
7373 size_t PDBFile::getFileSize() const { return Buffer->getLength(); }
7474
75 ArrayRef PDBFile::getBlockData(uint32_t BlockIndex,
76 uint32_t NumBytes) const {
75 Expected> PDBFile::getBlockData(uint32_t BlockIndex,
76 uint32_t NumBytes) const {
7777 uint64_t StreamBlockOffset = blockToOffset(BlockIndex, getBlockSize());
7878
7979 ArrayRef Result;
8080 if (auto EC = Buffer->readBytes(StreamBlockOffset, NumBytes, Result))
81 consumeError(std::move(EC));
81 return std::move(EC);
8282 return Result;
8383 }
8484
459459 }
460460
461461 return Buffer->commit();
462 }
462 }
6060 return ArrayRef();
6161 return Blocks;
6262 }
63 ArrayRef getBlockData(uint32_t BlockIndex,
64 uint32_t NumBytes) const override {
63 Expected> getBlockData(uint32_t BlockIndex,
64 uint32_t NumBytes) const override {
6565 return ArrayRef(&Data[BlockIndex], NumBytes);
6666 }
6767