1 //===- DIADataStream.cpp - DIA implementation of IPDBDataStream -*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/DebugInfo/PDB/DIA/DIADataStream.h" 11 #include "llvm/DebugInfo/PDB/DIA/DIAUtils.h" 12 13 using namespace llvm; 14 using namespace llvm::pdb; 15 16 DIADataStream::DIADataStream(CComPtr<IDiaEnumDebugStreamData> DiaStreamData) 17 : StreamData(DiaStreamData) {} 18 19 uint32_t DIADataStream::getRecordCount() const { 20 LONG Count = 0; 21 return (S_OK == StreamData->get_Count(&Count)) ? Count : 0; 22 } 23 24 std::string DIADataStream::getName() const { 25 return invokeBstrMethod(*StreamData, &IDiaEnumDebugStreamData::get_name); 26 } 27 28 llvm::Optional<DIADataStream::RecordType> 29 DIADataStream::getItemAtIndex(uint32_t Index) const { 30 RecordType Record; 31 DWORD RecordSize = 0; 32 StreamData->Item(Index, 0, &RecordSize, nullptr); 33 if (RecordSize == 0) 34 return llvm::Optional<RecordType>(); 35 36 Record.resize(RecordSize); 37 if (S_OK != StreamData->Item(Index, RecordSize, &RecordSize, &Record[0])) 38 return llvm::Optional<RecordType>(); 39 return Record; 40 } 41 42 bool DIADataStream::getNext(RecordType &Record) { 43 Record.clear(); 44 DWORD RecordSize = 0; 45 ULONG CountFetched = 0; 46 StreamData->Next(1, 0, &RecordSize, nullptr, &CountFetched); 47 if (RecordSize == 0) 48 return false; 49 50 Record.resize(RecordSize); 51 if (S_OK == 52 StreamData->Next(1, RecordSize, &RecordSize, &Record[0], &CountFetched)) 53 return false; 54 return true; 55 } 56 57 void DIADataStream::reset() { StreamData->Reset(); } 58