LLVM  4.0.0
DIASourceFile.cpp
Go to the documentation of this file.
1 //===- DIASourceFile.cpp - DIA implementation of IPDBSourceFile -*- 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"
17 
18 using namespace llvm;
19 using namespace llvm::pdb;
20 
22  CComPtr<IDiaSourceFile> DiaSourceFile)
23  : Session(PDBSession), SourceFile(DiaSourceFile) {}
24 
25 std::string DIASourceFile::getFileName() const {
26  CComBSTR FileName16;
27  HRESULT Result = SourceFile->get_fileName(&FileName16);
28  if (S_OK != Result)
29  return std::string();
30 
31  std::string FileName8;
32  llvm::ArrayRef<char> FileNameBytes(reinterpret_cast<char *>(FileName16.m_str),
33  FileName16.ByteLength());
34  llvm::convertUTF16ToUTF8String(FileNameBytes, FileName8);
35  return FileName8;
36 }
37 
39  DWORD Id;
40  return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
41 }
42 
43 std::string DIASourceFile::getChecksum() const {
44  DWORD ByteSize = 0;
45  HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr);
46  if (ByteSize == 0)
47  return std::string();
48  std::vector<BYTE> ChecksumBytes(ByteSize);
49  Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]);
50  if (S_OK != Result)
51  return std::string();
52  return std::string(ChecksumBytes.begin(), ChecksumBytes.end());
53 }
54 
56  DWORD Type;
57  HRESULT Result = SourceFile->get_checksumType(&Type);
58  if (S_OK != Result)
59  return PDB_Checksum::None;
60  return static_cast<PDB_Checksum>(Type);
61 }
62 
63 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
65  CComPtr<IDiaEnumSymbols> DiaEnumerator;
66  HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
67  if (S_OK != Result)
68  return nullptr;
69 
70  auto Enumerator = std::unique_ptr<IPDBEnumSymbols>(
71  new DIAEnumSymbols(Session, DiaEnumerator));
72  return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>(
74 }
std::unique_ptr< IPDBEnumChildren< PDBSymbolCompiland > > getCompilands() const override
PDB_Checksum
Specifies the hash algorithm that a source file from a PDB was hashed with.
Definition: PDBTypes.h:103
uint32_t getUniqueId() const override
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
std::string getChecksum() 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.
PDB_Checksum getChecksumType() const override
DIASourceFile(const DIASession &Session, CComPtr< IDiaSourceFile > DiaSourceFile)
std::string getFileName() const override