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