• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- 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 
16 using namespace llvm;
17 using namespace llvm::pdb;
18 
DIAInjectedSource(CComPtr<IDiaInjectedSource> DiaSourceFile)19 DIAInjectedSource::DIAInjectedSource(CComPtr<IDiaInjectedSource> DiaSourceFile)
20     : SourceFile(DiaSourceFile) {}
21 
getCrc32() const22 uint32_t DIAInjectedSource::getCrc32() const {
23   DWORD Crc;
24   return (S_OK == SourceFile->get_crc(&Crc)) ? Crc : 0;
25 }
26 
getCodeByteSize() const27 uint64_t DIAInjectedSource::getCodeByteSize() const {
28   ULONGLONG Size;
29   return (S_OK == SourceFile->get_length(&Size)) ? Size : 0;
30 }
31 
getFileName() const32 std::string DIAInjectedSource::getFileName() const {
33   return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_filename);
34 }
35 
getObjectFileName() const36 std::string DIAInjectedSource::getObjectFileName() const {
37   return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_objectFilename);
38 }
39 
getVirtualFileName() const40 std::string DIAInjectedSource::getVirtualFileName() const {
41   return invokeBstrMethod(*SourceFile,
42                           &IDiaInjectedSource::get_virtualFilename);
43 }
44 
getCompression() const45 PDB_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 
getCode() const52 std::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 }
64