blob: d3e408166a874039364b64e5c1d76e55cee2d25e [file] [log] [blame]
Zachary Turnercffff262015-02-10 21:17:52 +00001//===- 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 Turner43ec3af2016-02-18 18:47:29 +000010#include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h"
11#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
Zachary Turnercffff262015-02-10 21:17:52 +000012#include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h"
13#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
Aaron Smith757274f2018-09-28 02:32:07 +000014#include "llvm/DebugInfo/PDB/DIA/DIAUtils.h"
Zachary Turner43ec3af2016-02-18 18:47:29 +000015#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Zachary Turnercffff262015-02-10 21:17:52 +000016
17using namespace llvm;
Zachary Turnerec28fc32016-05-04 20:32:13 +000018using namespace llvm::pdb;
Zachary Turnercffff262015-02-10 21:17:52 +000019
20DIASourceFile::DIASourceFile(const DIASession &PDBSession,
21 CComPtr<IDiaSourceFile> DiaSourceFile)
22 : Session(PDBSession), SourceFile(DiaSourceFile) {}
23
24std::string DIASourceFile::getFileName() const {
Aaron Smith757274f2018-09-28 02:32:07 +000025 return invokeBstrMethod(*SourceFile, &IDiaSourceFile::get_fileName);
Zachary Turnercffff262015-02-10 21:17:52 +000026}
27
28uint32_t DIASourceFile::getUniqueId() const {
29 DWORD Id;
30 return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
31}
32
33std::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
45PDB_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 Turner43ec3af2016-02-18 18:47:29 +000053std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
54DIASourceFile::getCompilands() const {
Zachary Turnercffff262015-02-10 21:17:52 +000055 CComPtr<IDiaEnumSymbols> DiaEnumerator;
56 HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
57 if (S_OK != Result)
58 return nullptr;
59
Zachary Turner43ec3af2016-02-18 18:47:29 +000060 auto Enumerator = std::unique_ptr<IPDBEnumSymbols>(
Zachary Turnercffff262015-02-10 21:17:52 +000061 new DIAEnumSymbols(Session, DiaEnumerator));
Zachary Turner43ec3af2016-02-18 18:47:29 +000062 return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>(
63 new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator)));
Zachary Turnercffff262015-02-10 21:17:52 +000064}