blob: 1d642f221d79574955fc74affec0b3417375ef03 [file] [log] [blame]
Zachary Turner679aead2018-03-13 17:46:06 +00001//===- DIAInjectedSource.cpp - DIA impl for IPDBInjectedSource --*- 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
10#include "llvm/DebugInfo/PDB/DIA/DIAInjectedSource.h"
11#include "llvm/ADT/ArrayRef.h"
12#include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
13#include "llvm/DebugInfo/PDB/DIA/DIASession.h"
14#include "llvm/DebugInfo/PDB/DIA/DIAUtils.h"
15
16using namespace llvm;
17using namespace llvm::pdb;
18
Reid Kleckner8562c1a2018-03-21 21:47:26 +000019DIAInjectedSource::DIAInjectedSource(CComPtr<IDiaInjectedSource> DiaSourceFile)
20 : SourceFile(DiaSourceFile) {}
Zachary Turner679aead2018-03-13 17:46:06 +000021
22uint32_t DIAInjectedSource::getCrc32() const {
23 DWORD Crc;
24 return (S_OK == SourceFile->get_crc(&Crc)) ? Crc : 0;
25}
26
27uint64_t DIAInjectedSource::getCodeByteSize() const {
28 ULONGLONG Size;
29 return (S_OK == SourceFile->get_length(&Size)) ? Size : 0;
30}
31
32std::string DIAInjectedSource::getFileName() const {
33 return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_filename);
34}
35
36std::string DIAInjectedSource::getObjectFileName() const {
37 return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_objectFilename);
38}
39
40std::string DIAInjectedSource::getVirtualFileName() const {
41 return invokeBstrMethod(*SourceFile,
42 &IDiaInjectedSource::get_virtualFilename);
43}
44
45PDB_SourceCompression DIAInjectedSource::getCompression() const {
46 DWORD Compression = 0;
47 if (S_OK != SourceFile->get_sourceCompression(&Compression))
48 return PDB_SourceCompression::None;
49 return static_cast<PDB_SourceCompression>(Compression);
50}
51
52std::string DIAInjectedSource::getCode() const {
53 DWORD DataSize;
54 if (S_OK != SourceFile->get_source(0, &DataSize, nullptr))
55 return "";
56
57 std::vector<uint8_t> Buffer(DataSize);
58 if (S_OK != SourceFile->get_source(DataSize, &DataSize, Buffer.data()))
59 return "";
60 assert(Buffer.size() == DataSize);
61 return std::string(reinterpret_cast<const char *>(Buffer.data()),
62 Buffer.size());
63}