xref: /src/contrib/llvm-project/llvm/lib/DebugInfo/PDB/DIA/DIASourceFile.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
15a5ac124SDimitry Andric //===- DIASourceFile.cpp - DIA implementation of IPDBSourceFile -*- C++ -*-===//
25a5ac124SDimitry Andric //
3e6d15924SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4e6d15924SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5e6d15924SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a5ac124SDimitry Andric //
75a5ac124SDimitry Andric //===----------------------------------------------------------------------===//
85a5ac124SDimitry Andric 
901095a5dSDimitry Andric #include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h"
1001095a5dSDimitry Andric #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
115a5ac124SDimitry Andric #include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h"
125a5ac124SDimitry Andric #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
13d8e91e46SDimitry Andric #include "llvm/DebugInfo/PDB/DIA/DIAUtils.h"
1401095a5dSDimitry Andric #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
155a5ac124SDimitry Andric 
165a5ac124SDimitry Andric using namespace llvm;
1701095a5dSDimitry Andric using namespace llvm::pdb;
185a5ac124SDimitry Andric 
DIASourceFile(const DIASession & PDBSession,CComPtr<IDiaSourceFile> DiaSourceFile)195a5ac124SDimitry Andric DIASourceFile::DIASourceFile(const DIASession &PDBSession,
205a5ac124SDimitry Andric                              CComPtr<IDiaSourceFile> DiaSourceFile)
215a5ac124SDimitry Andric     : Session(PDBSession), SourceFile(DiaSourceFile) {}
225a5ac124SDimitry Andric 
getFileName() const235a5ac124SDimitry Andric std::string DIASourceFile::getFileName() const {
24d8e91e46SDimitry Andric   return invokeBstrMethod(*SourceFile, &IDiaSourceFile::get_fileName);
255a5ac124SDimitry Andric }
265a5ac124SDimitry Andric 
getUniqueId() const275a5ac124SDimitry Andric uint32_t DIASourceFile::getUniqueId() const {
285a5ac124SDimitry Andric   DWORD Id;
295a5ac124SDimitry Andric   return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
305a5ac124SDimitry Andric }
315a5ac124SDimitry Andric 
getChecksum() const325a5ac124SDimitry Andric std::string DIASourceFile::getChecksum() const {
335a5ac124SDimitry Andric   DWORD ByteSize = 0;
345a5ac124SDimitry Andric   HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr);
355a5ac124SDimitry Andric   if (ByteSize == 0)
365a5ac124SDimitry Andric     return std::string();
375a5ac124SDimitry Andric   std::vector<BYTE> ChecksumBytes(ByteSize);
385a5ac124SDimitry Andric   Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]);
395a5ac124SDimitry Andric   if (S_OK != Result)
405a5ac124SDimitry Andric     return std::string();
415a5ac124SDimitry Andric   return std::string(ChecksumBytes.begin(), ChecksumBytes.end());
425a5ac124SDimitry Andric }
435a5ac124SDimitry Andric 
getChecksumType() const445a5ac124SDimitry Andric PDB_Checksum DIASourceFile::getChecksumType() const {
455a5ac124SDimitry Andric   DWORD Type;
465a5ac124SDimitry Andric   HRESULT Result = SourceFile->get_checksumType(&Type);
475a5ac124SDimitry Andric   if (S_OK != Result)
485a5ac124SDimitry Andric     return PDB_Checksum::None;
495a5ac124SDimitry Andric   return static_cast<PDB_Checksum>(Type);
505a5ac124SDimitry Andric }
515a5ac124SDimitry Andric 
5201095a5dSDimitry Andric std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
getCompilands() const5301095a5dSDimitry Andric DIASourceFile::getCompilands() const {
545a5ac124SDimitry Andric   CComPtr<IDiaEnumSymbols> DiaEnumerator;
555a5ac124SDimitry Andric   HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
565a5ac124SDimitry Andric   if (S_OK != Result)
575a5ac124SDimitry Andric     return nullptr;
585a5ac124SDimitry Andric 
5901095a5dSDimitry Andric   auto Enumerator = std::unique_ptr<IPDBEnumSymbols>(
605a5ac124SDimitry Andric       new DIAEnumSymbols(Session, DiaEnumerator));
6101095a5dSDimitry Andric   return std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>(
6201095a5dSDimitry Andric       new ConcreteSymbolEnumerator<PDBSymbolCompiland>(std::move(Enumerator)));
635a5ac124SDimitry Andric }
64