blob: fbd169524b6b3e9d4c4c380899238e5eb3dfa29c [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
Zachary Turnera21558892018-03-19 20:41:59 +000019DIAInjectedSource::DIAInjectedSource(const DIASession &Session,
20 CComPtr<IDiaInjectedSource> DiaSourceFile)
21 : Session(Session), SourceFile(DiaSourceFile) {}
Zachary Turner679aead2018-03-13 17:46:06 +000022
23uint32_t DIAInjectedSource::getCrc32() const {
24 DWORD Crc;
25 return (S_OK == SourceFile->get_crc(&Crc)) ? Crc : 0;
26}
27
28uint64_t DIAInjectedSource::getCodeByteSize() const {
29 ULONGLONG Size;
30 return (S_OK == SourceFile->get_length(&Size)) ? Size : 0;
31}
32
33std::string DIAInjectedSource::getFileName() const {
34 return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_filename);
35}
36
37std::string DIAInjectedSource::getObjectFileName() const {
38 return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_objectFilename);
39}
40
41std::string DIAInjectedSource::getVirtualFileName() const {
42 return invokeBstrMethod(*SourceFile,
43 &IDiaInjectedSource::get_virtualFilename);
44}
45
46PDB_SourceCompression DIAInjectedSource::getCompression() const {
47 DWORD Compression = 0;
48 if (S_OK != SourceFile->get_sourceCompression(&Compression))
49 return PDB_SourceCompression::None;
50 return static_cast<PDB_SourceCompression>(Compression);
51}
52
53std::string DIAInjectedSource::getCode() const {
54 DWORD DataSize;
55 if (S_OK != SourceFile->get_source(0, &DataSize, nullptr))
56 return "";
57
58 std::vector<uint8_t> Buffer(DataSize);
59 if (S_OK != SourceFile->get_source(DataSize, &DataSize, Buffer.data()))
60 return "";
61 assert(Buffer.size() == DataSize);
62 return std::string(reinterpret_cast<const char *>(Buffer.data()),
63 Buffer.size());
64}