xref: /freebsd/contrib/llvm-project/llvm/lib/DebugInfo/PDB/DIA/DIASourceFile.cpp (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1 //===- DIASourceFile.cpp - DIA implementation of IPDBSourceFile -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h"
10 #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
11 #include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h"
12 #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
13 #include "llvm/DebugInfo/PDB/DIA/DIAUtils.h"
14 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
15 
16 using namespace llvm;
17 using namespace llvm::pdb;
18 
19 DIASourceFile::DIASourceFile(const DIASession &PDBSession,
20                              CComPtr<IDiaSourceFile> DiaSourceFile)
21     : Session(PDBSession), SourceFile(DiaSourceFile) {}
22 
23 std::string DIASourceFile::getFileName() const {
24   return invokeBstrMethod(*SourceFile, &IDiaSourceFile::get_fileName);
25 }
26 
27 uint32_t DIASourceFile::getUniqueId() const {
28   DWORD Id;
29   return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
30 }
31 
32 std::string DIASourceFile::getChecksum() const {
33   DWORD ByteSize = 0;
34   HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr);
35   if (ByteSize == 0)
36     return std::string();
37   std::vector<BYTE> ChecksumBytes(ByteSize);
38   Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]);
39   if (S_OK != Result)
40     return std::string();
41   return std::string(ChecksumBytes.begin(), ChecksumBytes.end());
42 }
43 
44 PDB_Checksum DIASourceFile::getChecksumType() const {
45   DWORD Type;
46   HRESULT Result = SourceFile->get_checksumType(&Type);
47   if (S_OK != Result)
48     return PDB_Checksum::None;
49   return static_cast<PDB_Checksum>(Type);
50 }
51 
52 std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
53 DIASourceFile::getCompilands() const {
54   CComPtr<IDiaEnumSymbols> DiaEnumerator;
55   HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
56   if (S_OK != Result)
57     return nullptr;
58 
59   auto Enumerator = std::unique_ptr<IPDBEnumSymbols>(
60       new DIAEnumSymbols(Session, DiaEnumerator));
61   return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>(
62       new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator)));
63 }
64