Zachary Turner | 679aead | 2018-03-13 17:46:06 +0000 | [diff] [blame] | 1 | //===- DIAInjectedSource.cpp - DIA impl for IPDBInjectedSource --*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Zachary Turner | 679aead | 2018-03-13 17:46:06 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/DebugInfo/PDB/DIA/DIAInjectedSource.h" |
| 10 | #include "llvm/ADT/ArrayRef.h" |
| 11 | #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h" |
| 12 | #include "llvm/DebugInfo/PDB/DIA/DIASession.h" |
| 13 | #include "llvm/DebugInfo/PDB/DIA/DIAUtils.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | using namespace llvm::pdb; |
| 17 | |
Reid Kleckner | 8562c1a | 2018-03-21 21:47:26 +0000 | [diff] [blame] | 18 | DIAInjectedSource::DIAInjectedSource(CComPtr<IDiaInjectedSource> DiaSourceFile) |
| 19 | : SourceFile(DiaSourceFile) {} |
Zachary Turner | 679aead | 2018-03-13 17:46:06 +0000 | [diff] [blame] | 20 | |
| 21 | uint32_t DIAInjectedSource::getCrc32() const { |
| 22 | DWORD Crc; |
| 23 | return (S_OK == SourceFile->get_crc(&Crc)) ? Crc : 0; |
| 24 | } |
| 25 | |
| 26 | uint64_t DIAInjectedSource::getCodeByteSize() const { |
| 27 | ULONGLONG Size; |
| 28 | return (S_OK == SourceFile->get_length(&Size)) ? Size : 0; |
| 29 | } |
| 30 | |
| 31 | std::string DIAInjectedSource::getFileName() const { |
| 32 | return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_filename); |
| 33 | } |
| 34 | |
| 35 | std::string DIAInjectedSource::getObjectFileName() const { |
| 36 | return invokeBstrMethod(*SourceFile, &IDiaInjectedSource::get_objectFilename); |
| 37 | } |
| 38 | |
| 39 | std::string DIAInjectedSource::getVirtualFileName() const { |
| 40 | return invokeBstrMethod(*SourceFile, |
| 41 | &IDiaInjectedSource::get_virtualFilename); |
| 42 | } |
| 43 | |
Nico Weber | 7bb5fc0 | 2019-07-17 22:59:52 +0000 | [diff] [blame] | 44 | uint32_t DIAInjectedSource::getCompression() const { |
Zachary Turner | 679aead | 2018-03-13 17:46:06 +0000 | [diff] [blame] | 45 | DWORD Compression = 0; |
| 46 | if (S_OK != SourceFile->get_sourceCompression(&Compression)) |
| 47 | return PDB_SourceCompression::None; |
Nico Weber | 7bb5fc0 | 2019-07-17 22:59:52 +0000 | [diff] [blame] | 48 | return static_cast<uint32_t>(Compression); |
Zachary Turner | 679aead | 2018-03-13 17:46:06 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | std::string DIAInjectedSource::getCode() const { |
| 52 | DWORD DataSize; |
| 53 | if (S_OK != SourceFile->get_source(0, &DataSize, nullptr)) |
| 54 | return ""; |
| 55 | |
| 56 | std::vector<uint8_t> Buffer(DataSize); |
| 57 | if (S_OK != SourceFile->get_source(DataSize, &DataSize, Buffer.data())) |
| 58 | return ""; |
| 59 | assert(Buffer.size() == DataSize); |
| 60 | return std::string(reinterpret_cast<const char *>(Buffer.data()), |
| 61 | Buffer.size()); |
| 62 | } |