LLVM  4.0.0
DIADataStream.cpp
Go to the documentation of this file.
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 
11 #include "llvm/ADT/ArrayRef.h"
13 
14 using namespace llvm;
15 using namespace llvm::pdb;
16 
17 DIADataStream::DIADataStream(CComPtr<IDiaEnumDebugStreamData> DiaStreamData)
18  : StreamData(DiaStreamData) {}
19 
21  LONG Count = 0;
22  return (S_OK == StreamData->get_Count(&Count)) ? Count : 0;
23 }
24 
25 std::string DIADataStream::getName() const {
26  CComBSTR Name16;
27  if (S_OK != StreamData->get_name(&Name16))
28  return std::string();
29 
30  std::string Name8;
31  llvm::ArrayRef<char> Name16Bytes(reinterpret_cast<char *>(Name16.m_str),
32  Name16.ByteLength());
33  if (!llvm::convertUTF16ToUTF8String(Name16Bytes, Name8))
34  return std::string();
35  return Name8;
36 }
37 
41  DWORD RecordSize = 0;
42  StreamData->Item(Index, 0, &RecordSize, nullptr);
43  if (RecordSize == 0)
45 
46  Record.resize(RecordSize);
47  if (S_OK != StreamData->Item(Index, RecordSize, &RecordSize, &Record[0]))
49  return Record;
50 }
51 
53  Record.clear();
54  DWORD RecordSize = 0;
55  ULONG CountFetched = 0;
56  StreamData->Next(1, 0, &RecordSize, nullptr, &CountFetched);
57  if (RecordSize == 0)
58  return false;
59 
60  Record.resize(RecordSize);
61  if (S_OK ==
62  StreamData->Next(1, RecordSize, &RecordSize, &Record[0], &CountFetched))
63  return false;
64  return true;
65 }
66 
67 void DIADataStream::reset() { StreamData->Reset(); }
68 
70  CComPtr<IDiaEnumDebugStreamData> EnumeratorClone;
71  if (S_OK != StreamData->Clone(&EnumeratorClone))
72  return nullptr;
73 
74  return new DIADataStream(EnumeratorClone);
75 }
DIADataStream(CComPtr< IDiaEnumDebugStreamData > DiaStreamData)
bool getNext(RecordType &Record) override
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
DIADataStream * clone() const override
std::string getName() const override
bool convertUTF16ToUTF8String(ArrayRef< char > SrcBytes, std::string &Out)
Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
llvm::Optional< RecordType > getItemAtIndex(uint32_t Index) const override
uint32_t getRecordCount() const override
void resize(size_type N)
Definition: SmallVector.h:352