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 19 DIAInjectedSource::DIAInjectedSource(const DIASession &Session, 20 CComPtr<IDiaInjectedSource> DiaSourceFile) 21 : Session(Session), SourceFile(DiaSourceFile) {} 22 23 uint32_t DIAInjectedSource::getCrc32() const { 24 DWORD Crc; 25 return (S_OK == SourceFile->get_crc(&Crc)) ? Crc : 0; 26 } 27 28 uint64_t DIAInjectedSource::getCodeByteSize() const { 29 ULONGLONG Size; 30 return (S_OK == SourceFile->get_length(&Size)) ? Size : 0; 31 } 32 33 std::string DIAInjectedSource::getFileName() const { 34 return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_filename); 35 } 36 37 std::string DIAInjectedSource::getObjectFileName() const { 38 return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_objectFilename); 39 } 40 41 std::string DIAInjectedSource::getVirtualFileName() const { 42 return invokeBstrMethod(*SourceFile, 43 &IDiaInjectedSource::get_virtualFilename); 44 } 45 46 PDB_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 53 std::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 } 65