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