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/ADT/ArrayRef.h" 12#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" 13#include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h" 14#include "llvm/DebugInfo/PDB/DIA/DIASession.h" 15#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" 16#include "llvm/Support/ConvertUTF.h" 17 18using namespace llvm; 19using namespace llvm::pdb; 20 21DIASourceFile::DIASourceFile(const DIASession &PDBSession, 22 CComPtr<IDiaSourceFile> DiaSourceFile) 23 : Session(PDBSession), SourceFile(DiaSourceFile) {} 24 25std::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 38uint32_t DIASourceFile::getUniqueId() const { 39 DWORD Id; 40 return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0; 41} 42 43std::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 55PDB_Checksum DIASourceFile::getChecksumType() const { 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 63std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> 64DIASourceFile::getCompilands() const { 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>>( 73 new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator))); 74} 75