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" |
Nico Weber | 179b383 | 2016-04-18 13:31:31 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/ArrayRef.h" |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 12 | #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 13 | #include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h" |
| 14 | #include "llvm/DebugInfo/PDB/DIA/DIASession.h" |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 15 | #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h" |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 16 | #include "llvm/Support/ConvertUTF.h" |
| 17 | |
| 18 | using namespace llvm; |
Zachary Turner | ec28fc3 | 2016-05-04 20:32:13 +0000 | [diff] [blame] | 19 | using namespace llvm::pdb; |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 20 | |
| 21 | DIASourceFile::DIASourceFile(const DIASession &PDBSession, |
| 22 | CComPtr<IDiaSourceFile> DiaSourceFile) |
| 23 | : Session(PDBSession), SourceFile(DiaSourceFile) {} |
| 24 | |
| 25 | std::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 | |
| 38 | uint32_t DIASourceFile::getUniqueId() const { |
| 39 | DWORD Id; |
| 40 | return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0; |
| 41 | } |
| 42 | |
| 43 | std::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 | |
| 55 | PDB_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 | |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 63 | std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> |
| 64 | DIASourceFile::getCompilands() const { |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 65 | CComPtr<IDiaEnumSymbols> DiaEnumerator; |
| 66 | HRESULT Result = SourceFile->get_compilands(&DiaEnumerator); |
| 67 | if (S_OK != Result) |
| 68 | return nullptr; |
| 69 | |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 70 | auto Enumerator = std::unique_ptr<IPDBEnumSymbols>( |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 71 | new DIAEnumSymbols(Session, DiaEnumerator)); |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 72 | return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>( |
| 73 | new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator))); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 74 | } |