Zachary Turner | 679aead | 2018-03-13 17:46:06 +0000 | [diff] [blame] | 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 | |
Reid Kleckner | 8562c1a | 2018-03-21 21:47:26 +0000 | [diff] [blame^] | 19 | DIAInjectedSource::DIAInjectedSource(CComPtr<IDiaInjectedSource> DiaSourceFile) |
| 20 | : SourceFile(DiaSourceFile) {} |
Zachary Turner | 679aead | 2018-03-13 17:46:06 +0000 | [diff] [blame] | 21 | |
| 22 | uint32_t DIAInjectedSource::getCrc32() const { |
| 23 | DWORD Crc; |
| 24 | return (S_OK == SourceFile->get_crc(&Crc)) ? Crc : 0; |
| 25 | } |
| 26 | |
| 27 | uint64_t DIAInjectedSource::getCodeByteSize() const { |
| 28 | ULONGLONG Size; |
| 29 | return (S_OK == SourceFile->get_length(&Size)) ? Size : 0; |
| 30 | } |
| 31 | |
| 32 | std::string DIAInjectedSource::getFileName() const { |
| 33 | return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_filename); |
| 34 | } |
| 35 | |
| 36 | std::string DIAInjectedSource::getObjectFileName() const { |
| 37 | return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_objectFilename); |
| 38 | } |
| 39 | |
| 40 | std::string DIAInjectedSource::getVirtualFileName() const { |
| 41 | return invokeBstrMethod(*SourceFile, |
| 42 | &IDiaInjectedSource::get_virtualFilename); |
| 43 | } |
| 44 | |
| 45 | 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 | |
| 52 | 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 | } |