blob: 762dda6caf544b234b69fddcf63874094b5a18bd [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;
19
20DIASourceFile::DIASourceFile(const DIASession &PDBSession,
21 CComPtr<IDiaSourceFile> DiaSourceFile)
22 : Session(PDBSession), SourceFile(DiaSourceFile) {}
23
24std::string DIASourceFile::getFileName() const {
25 CComBSTR FileName16;
26 HRESULT Result = SourceFile->get_fileName(&FileName16);
27 if (S_OK != Result)
28 return std::string();
29
30 std::string FileName8;
31 llvm::ArrayRef<char> FileNameBytes(reinterpret_cast<char *>(FileName16.m_str),
32 FileName16.ByteLength());
33 llvm::convertUTF16ToUTF8String(FileNameBytes, FileName8);
34 return FileName8;
35}
36
37uint32_t DIASourceFile::getUniqueId() const {
38 DWORD Id;
39 return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
40}
41
42std::string DIASourceFile::getChecksum() const {
43 DWORD ByteSize = 0;
44 HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr);
45 if (ByteSize == 0)
46 return std::string();
47 std::vector<BYTE> ChecksumBytes(ByteSize);
48 Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]);
49 if (S_OK != Result)
50 return std::string();
51 return std::string(ChecksumBytes.begin(), ChecksumBytes.end());
52}
53
54PDB_Checksum DIASourceFile::getChecksumType() const {
55 DWORD Type;
56 HRESULT Result = SourceFile->get_checksumType(&Type);
57 if (S_OK != Result)
58 return PDB_Checksum::None;
59 return static_cast<PDB_Checksum>(Type);
60}
61
Zachary Turner43ec3af2016-02-18 18:47:29 +000062std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
63DIASourceFile::getCompilands() const {
Zachary Turnercffff262015-02-10 21:17:52 +000064 CComPtr<IDiaEnumSymbols> DiaEnumerator;
65 HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
66 if (S_OK != Result)
67 return nullptr;
68
Zachary Turner43ec3af2016-02-18 18:47:29 +000069 auto Enumerator = std::unique_ptr<IPDBEnumSymbols>(
Zachary Turnercffff262015-02-10 21:17:52 +000070 new DIAEnumSymbols(Session, DiaEnumerator));
Zachary Turner43ec3af2016-02-18 18:47:29 +000071 return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>(
72 new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator)));
Zachary Turnercffff262015-02-10 21:17:52 +000073}