Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 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 | |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame^] | 10 | #include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h" |
| 11 | #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h" |
| 13 | #include "llvm/DebugInfo/PDB/DIA/DIASession.h" |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame^] | 14 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 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 | |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame^] | 61 | std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> |
| 62 | DIASourceFile::getCompilands() const { |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 63 | CComPtr<IDiaEnumSymbols> DiaEnumerator; |
| 64 | HRESULT Result = SourceFile->get_compilands(&DiaEnumerator); |
| 65 | if (S_OK != Result) |
| 66 | return nullptr; |
| 67 | |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame^] | 68 | auto Enumerator = std::unique_ptr<IPDBEnumSymbols>( |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 69 | new DIAEnumSymbols(Session, DiaEnumerator)); |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame^] | 70 | return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>( |
| 71 | new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator))); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 72 | } |