DIASourceFile.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //===- DIASourceFile.cpp - DIA implementation of IPDBSourceFile -*- 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. #include "llvm/DebugInfo/PDB/DIA/DIAEnumSymbols.h"
  10. #include "llvm/DebugInfo/PDB/DIA/DIASession.h"
  11. #include "llvm/DebugInfo/PDB/DIA/DIASourceFile.h"
  12. #include "llvm/Support/ConvertUTF.h"
  13. using namespace llvm;
  14. DIASourceFile::DIASourceFile(const DIASession &PDBSession,
  15. CComPtr<IDiaSourceFile> DiaSourceFile)
  16. : Session(PDBSession), SourceFile(DiaSourceFile) {}
  17. std::string DIASourceFile::getFileName() const {
  18. CComBSTR FileName16;
  19. HRESULT Result = SourceFile->get_fileName(&FileName16);
  20. if (S_OK != Result)
  21. return std::string();
  22. std::string FileName8;
  23. llvm::ArrayRef<char> FileNameBytes(reinterpret_cast<char *>(FileName16.m_str),
  24. FileName16.ByteLength());
  25. llvm::convertUTF16ToUTF8String(FileNameBytes, FileName8);
  26. return FileName8;
  27. }
  28. uint32_t DIASourceFile::getUniqueId() const {
  29. DWORD Id;
  30. return (S_OK == SourceFile->get_uniqueId(&Id)) ? Id : 0;
  31. }
  32. std::string DIASourceFile::getChecksum() const {
  33. DWORD ByteSize = 0;
  34. HRESULT Result = SourceFile->get_checksum(0, &ByteSize, nullptr);
  35. if (ByteSize == 0)
  36. return std::string();
  37. std::vector<BYTE> ChecksumBytes(ByteSize);
  38. Result = SourceFile->get_checksum(ByteSize, &ByteSize, &ChecksumBytes[0]);
  39. if (S_OK != Result)
  40. return std::string();
  41. return std::string(ChecksumBytes.begin(), ChecksumBytes.end());
  42. }
  43. PDB_Checksum DIASourceFile::getChecksumType() const {
  44. DWORD Type;
  45. HRESULT Result = SourceFile->get_checksumType(&Type);
  46. if (S_OK != Result)
  47. return PDB_Checksum::None;
  48. return static_cast<PDB_Checksum>(Type);
  49. }
  50. std::unique_ptr<IPDBEnumSymbols> DIASourceFile::getCompilands() const {
  51. CComPtr<IDiaEnumSymbols> DiaEnumerator;
  52. HRESULT Result = SourceFile->get_compilands(&DiaEnumerator);
  53. if (S_OK != Result)
  54. return nullptr;
  55. return std::unique_ptr<IPDBEnumSymbols>(
  56. new DIAEnumSymbols(Session, DiaEnumerator));
  57. }