1 //===- DIASourceFile.cpp - DIA implementation of IPDBSourceFile -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h"
11 #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
12 #include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h"
13 #include "llvm/Support/ConvertUTF.h"
17 DIASourceFile::DIASourceFile(const DIASession &PDBSession,
18 CComPtr<IDiaSourceFile> DiaSourceFile)
19 : Session(PDBSession), SourceFile(DiaSourceFile) {}
21 std::string DIASourceFile::getFileName() const {
23 HRESULT Result = SourceFile->get_fileName(&FileName16);
27 std::string FileName8;
28 llvm::ArrayRef<char> FileNameBytes(reinterpret_cast<char *>(FileName16.m_str),
29 FileName16.ByteLength());
30 llvm::convertUTF16ToUTF8String(FileNameBytes, FileName8);
34 uint32_t DIASourceFile::getUniqueId() const {
36 return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
39 std::string DIASourceFile::getChecksum() const {
41 HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr);
44 std::vector<BYTE> ChecksumBytes(ByteSize);
45 Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]);
48 return std::string(ChecksumBytes.begin(), ChecksumBytes.end());
51 PDB_Checksum DIASourceFile::getChecksumType() const {
53 HRESULT Result = SourceFile->get_checksumType(&Type);
55 return PDB_Checksum::None;
56 return static_cast<PDB_Checksum>(Type);
59 std::unique_ptr<IPDBEnumSymbols> DIASourceFile::getCompilands() const {
60 CComPtr<IDiaEnumSymbols> DiaEnumerator;
61 HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
65 return std::unique_ptr<IPDBEnumSymbols>(
66 new DIAEnumSymbols(Session, DiaEnumerator));