blob: 9600a1972ea58ea63f277537543a9d5742d77bd1 [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"
Zachary Turner43ec3af2016-02-18 18:47:29 +000014#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Zachary Turnercffff262015-02-10 21:17:52 +000015#include "llvm/Support/ConvertUTF.h"
16
17using namespace llvm;
18
19DIASourceFile::DIASourceFile(const DIASession &PDBSession,
20 CComPtr<IDiaSourceFile> DiaSourceFile)
21 : Session(PDBSession), SourceFile(DiaSourceFile) {}
22
23std::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
36uint32_t DIASourceFile::getUniqueId() const {
37 DWORD Id;
38 return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
39}
40
41std::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
53PDB_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 Turner43ec3af2016-02-18 18:47:29 +000061std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
62DIASourceFile::getCompilands() const {
Zachary Turnercffff262015-02-10 21:17:52 +000063 CComPtr<IDiaEnumSymbols> DiaEnumerator;
64 HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
65 if (S_OK != Result)
66 return nullptr;
67
Zachary Turner43ec3af2016-02-18 18:47:29 +000068 auto Enumerator = std::unique_ptr<IPDBEnumSymbols>(
Zachary Turnercffff262015-02-10 21:17:52 +000069 new DIAEnumSymbols(Session, DiaEnumerator));
Zachary Turner43ec3af2016-02-18 18:47:29 +000070 return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>(
71 new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator)));
Zachary Turnercffff262015-02-10 21:17:52 +000072}