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 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" 14 15 using namespace llvm; 16 17 DIASourceFile::DIASourceFile(const DIASession &PDBSession, 18 CComPtr<IDiaSourceFile> DiaSourceFile) 19 : Session(PDBSession), SourceFile(DiaSourceFile) {} 20 21 std::string DIASourceFile::getFileName() const { 22 CComBSTR FileName16; 23 HRESULT Result = SourceFile->get_fileName(&FileName16); 24 if (S_OK != Result) 25 return std::string(); 26 27 std::string FileName8; 28 llvm::ArrayRef<char> FileNameBytes(reinterpret_cast<char *>(FileName16.m_str), 29 FileName16.ByteLength()); 30 llvm::convertUTF16ToUTF8String(FileNameBytes, FileName8); 31 return FileName8; 32 } 33 34 uint32_t DIASourceFile::getUniqueId() const { 35 DWORD Id; 36 return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0; 37 } 38 39 std::string DIASourceFile::getChecksum() const { 40 DWORD ByteSize = 0; 41 HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr); 42 if (ByteSize == 0) 43 return std::string(); 44 std::vector<BYTE> ChecksumBytes(ByteSize); 45 Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]); 46 if (S_OK != Result) 47 return std::string(); 48 return std::string(ChecksumBytes.begin(), ChecksumBytes.end()); 49 } 50 51 PDB_Checksum DIASourceFile::getChecksumType() const { 52 DWORD Type; 53 HRESULT Result = SourceFile->get_checksumType(&Type); 54 if (S_OK != Result) 55 return PDB_Checksum::None; 56 return static_cast<PDB_Checksum>(Type); 57 } 58 59 std::unique_ptr<IPDBEnumSymbols> DIASourceFile::getCompilands() const { 60 CComPtr<IDiaEnumSymbols> DiaEnumerator; 61 HRESULT Result = SourceFile->get_compilands(&DiaEnumerator); 62 if (S_OK != Result) 63 return nullptr; 64 65 return std::unique_ptr<IPDBEnumSymbols>( 66 new DIAEnumSymbols(Session, DiaEnumerator)); 67 } 68