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" |
Aaron Smith | 757274f | 2018-09-28 02:32:07 +0000 | [diff] [blame^] | 14 | #include "llvm/DebugInfo/PDB/DIA/DIAUtils.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 | |
| 17 | using namespace llvm; |
Zachary Turner | ec28fc3 | 2016-05-04 20:32:13 +0000 | [diff] [blame] | 18 | using namespace llvm::pdb; |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 19 | |
| 20 | DIASourceFile::DIASourceFile(const DIASession &PDBSession, |
| 21 | CComPtr<IDiaSourceFile> DiaSourceFile) |
| 22 | : Session(PDBSession), SourceFile(DiaSourceFile) {} |
| 23 | |
| 24 | std::string DIASourceFile::getFileName() const { |
Aaron Smith | 757274f | 2018-09-28 02:32:07 +0000 | [diff] [blame^] | 25 | return invokeBstrMethod(*SourceFile, &IDiaSourceFile::get_fileName); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 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 | |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 53 | std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>> |
| 54 | DIASourceFile::getCompilands() const { |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 55 | CComPtr<IDiaEnumSymbols> DiaEnumerator; |
| 56 | HRESULT Result = SourceFile->get_compilands(&DiaEnumerator); |
| 57 | if (S_OK != Result) |
| 58 | return nullptr; |
| 59 | |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 60 | auto Enumerator = std::unique_ptr<IPDBEnumSymbols>( |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 61 | new DIAEnumSymbols(Session, DiaEnumerator)); |
Zachary Turner | 43ec3af | 2016-02-18 18:47:29 +0000 | [diff] [blame] | 62 | return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>( |
| 63 | new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator))); |
Zachary Turner | cffff26 | 2015-02-10 21:17:52 +0000 | [diff] [blame] | 64 | } |