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