10b57cec5SDimitry Andric //===- DIADataStream.cpp - DIA implementation of IPDBDataStream -*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric
90b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/DIA/DIADataStream.h"
100b57cec5SDimitry Andric #include "llvm/DebugInfo/PDB/DIA/DIAUtils.h"
110b57cec5SDimitry Andric
120b57cec5SDimitry Andric using namespace llvm;
130b57cec5SDimitry Andric using namespace llvm::pdb;
140b57cec5SDimitry Andric
DIADataStream(CComPtr<IDiaEnumDebugStreamData> DiaStreamData)150b57cec5SDimitry Andric DIADataStream::DIADataStream(CComPtr<IDiaEnumDebugStreamData> DiaStreamData)
160b57cec5SDimitry Andric : StreamData(DiaStreamData) {}
170b57cec5SDimitry Andric
getRecordCount() const180b57cec5SDimitry Andric uint32_t DIADataStream::getRecordCount() const {
190b57cec5SDimitry Andric LONG Count = 0;
200b57cec5SDimitry Andric return (S_OK == StreamData->get_Count(&Count)) ? Count : 0;
210b57cec5SDimitry Andric }
220b57cec5SDimitry Andric
getName() const230b57cec5SDimitry Andric std::string DIADataStream::getName() const {
240b57cec5SDimitry Andric return invokeBstrMethod(*StreamData, &IDiaEnumDebugStreamData::get_name);
250b57cec5SDimitry Andric }
260b57cec5SDimitry Andric
27*bdd1243dSDimitry Andric std::optional<DIADataStream::RecordType>
getItemAtIndex(uint32_t Index) const280b57cec5SDimitry Andric DIADataStream::getItemAtIndex(uint32_t Index) const {
290b57cec5SDimitry Andric RecordType Record;
300b57cec5SDimitry Andric DWORD RecordSize = 0;
310b57cec5SDimitry Andric StreamData->Item(Index, 0, &RecordSize, nullptr);
320b57cec5SDimitry Andric if (RecordSize == 0)
33*bdd1243dSDimitry Andric return std::nullopt;
340b57cec5SDimitry Andric
350b57cec5SDimitry Andric Record.resize(RecordSize);
360b57cec5SDimitry Andric if (S_OK != StreamData->Item(Index, RecordSize, &RecordSize, &Record[0]))
37*bdd1243dSDimitry Andric return std::nullopt;
380b57cec5SDimitry Andric return Record;
390b57cec5SDimitry Andric }
400b57cec5SDimitry Andric
getNext(RecordType & Record)410b57cec5SDimitry Andric bool DIADataStream::getNext(RecordType &Record) {
420b57cec5SDimitry Andric Record.clear();
430b57cec5SDimitry Andric DWORD RecordSize = 0;
440b57cec5SDimitry Andric ULONG CountFetched = 0;
450b57cec5SDimitry Andric StreamData->Next(1, 0, &RecordSize, nullptr, &CountFetched);
460b57cec5SDimitry Andric if (RecordSize == 0)
470b57cec5SDimitry Andric return false;
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric Record.resize(RecordSize);
500b57cec5SDimitry Andric if (S_OK ==
510b57cec5SDimitry Andric StreamData->Next(1, RecordSize, &RecordSize, &Record[0], &CountFetched))
520b57cec5SDimitry Andric return false;
530b57cec5SDimitry Andric return true;
540b57cec5SDimitry Andric }
550b57cec5SDimitry Andric
reset()560b57cec5SDimitry Andric void DIADataStream::reset() { StreamData->Reset(); }
57