1 //===- DIASourceFile.cpp - DIA implementation of IPDBSourceFile -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
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"
17 using namespace llvm::pdb
;
19 DIASourceFile::DIASourceFile(const DIASession
&PDBSession
,
20 CComPtr
<IDiaSourceFile
> DiaSourceFile
)
21 : Session(PDBSession
), SourceFile(DiaSourceFile
) {}
23 std::string
DIASourceFile::getFileName() const {
24 return invokeBstrMethod(*SourceFile
, &IDiaSourceFile::get_fileName
);
27 uint32_t DIASourceFile::getUniqueId() const {
29 return (S_OK
== SourceFile
->get_uniqueId(&Id
)) ? Id
: 0;
32 std::string
DIASourceFile::getChecksum() const {
34 HRESULT Result
= SourceFile
->get_checksum(0, &ByteSize
, nullptr);
37 std::vector
<BYTE
> ChecksumBytes(ByteSize
);
38 Result
= SourceFile
->get_checksum(ByteSize
, &ByteSize
, &ChecksumBytes
[0]);
41 return std::string(ChecksumBytes
.begin(), ChecksumBytes
.end());
44 PDB_Checksum
DIASourceFile::getChecksumType() const {
46 HRESULT Result
= SourceFile
->get_checksumType(&Type
);
48 return PDB_Checksum::None
;
49 return static_cast<PDB_Checksum
>(Type
);
52 std::unique_ptr
<IPDBEnumChildren
<PDBSymbolCompiland
>>
53 DIASourceFile::getCompilands() const {
54 CComPtr
<IDiaEnumSymbols
> DiaEnumerator
;
55 HRESULT Result
= SourceFile
->get_compilands(&DiaEnumerator
);
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
)));