blob: 8605f55b402c32de149e2e3e57d6f90217e889e9 [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"
Nico Weber179b3832016-04-18 13:31:31 +000011#include "llvm/ADT/ArrayRef.h"
Zachary Turner43ec3af2016-02-18 18:47:29 +000012#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
Zachary Turnercffff262015-02-10 21:17:52 +000013#include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h"
14#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
Zachary Turner43ec3af2016-02-18 18:47:29 +000015#include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
Zachary Turnercffff262015-02-10 21:17:52 +000016#include "llvm/Support/ConvertUTF.h"
17
18using namespace llvm;
Zachary Turnerec28fc32016-05-04 20:32:13 +000019using namespace llvm::pdb;
Zachary Turnercffff262015-02-10 21:17:52 +000020
21DIASourceFile::DIASourceFile(const DIASession &PDBSession,
22 CComPtr<IDiaSourceFile> DiaSourceFile)
23 : Session(PDBSession), SourceFile(DiaSourceFile) {}
24
25std::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
38uint32_t DIASourceFile::getUniqueId() const {
39 DWORD Id;
40 return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
41}
42
43std::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
55PDB_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 Turner43ec3af2016-02-18 18:47:29 +000063std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
64DIASourceFile::getCompilands() const {
Zachary Turnercffff262015-02-10 21:17:52 +000065 CComPtr<IDiaEnumSymbols> DiaEnumerator;
66 HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
67 if (S_OK != Result)
68 return nullptr;
69
Zachary Turner43ec3af2016-02-18 18:47:29 +000070 auto Enumerator = std::unique_ptr<IPDBEnumSymbols>(
Zachary Turnercffff262015-02-10 21:17:52 +000071 new DIAEnumSymbols(Session, DiaEnumerator));
Zachary Turner43ec3af2016-02-18 18:47:29 +000072 return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>(
73 new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator)));
Zachary Turnercffff262015-02-10 21:17:52 +000074}