NativeExeSymbol.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //===- NativeExeSymbol.cpp - native impl for PDBSymbolExe -------*- C++ -*-===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "llvm/DebugInfo/PDB/Native/NativeExeSymbol.h"
  9. #include "llvm/DebugInfo/CodeView/CodeView.h"
  10. #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
  11. #include "llvm/DebugInfo/PDB/Native/DbiStream.h"
  12. #include "llvm/DebugInfo/PDB/Native/InfoStream.h"
  13. #include "llvm/DebugInfo/PDB/Native/NativeEnumModules.h"
  14. #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
  15. #include "llvm/DebugInfo/PDB/Native/PDBFile.h"
  16. #include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
  17. using namespace llvm;
  18. using namespace llvm::pdb;
  19. static DbiStream *getDbiStreamPtr(NativeSession &Session) {
  20. Expected<DbiStream &> DbiS = Session.getPDBFile().getPDBDbiStream();
  21. if (DbiS)
  22. return &DbiS.get();
  23. consumeError(DbiS.takeError());
  24. return nullptr;
  25. }
  26. NativeExeSymbol::NativeExeSymbol(NativeSession &Session, SymIndexId SymbolId)
  27. : NativeRawSymbol(Session, PDB_SymType::Exe, SymbolId),
  28. Dbi(getDbiStreamPtr(Session)) {}
  29. std::unique_ptr<IPDBEnumSymbols>
  30. NativeExeSymbol::findChildren(PDB_SymType Type) const {
  31. switch (Type) {
  32. case PDB_SymType::Compiland: {
  33. return std::unique_ptr<IPDBEnumSymbols>(new NativeEnumModules(Session));
  34. break;
  35. }
  36. case PDB_SymType::ArrayType:
  37. return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ARRAY);
  38. case PDB_SymType::Enum:
  39. return Session.getSymbolCache().createTypeEnumerator(codeview::LF_ENUM);
  40. case PDB_SymType::PointerType:
  41. return Session.getSymbolCache().createTypeEnumerator(codeview::LF_POINTER);
  42. case PDB_SymType::UDT:
  43. return Session.getSymbolCache().createTypeEnumerator(
  44. {codeview::LF_STRUCTURE, codeview::LF_CLASS, codeview::LF_UNION,
  45. codeview::LF_INTERFACE});
  46. case PDB_SymType::VTableShape:
  47. return Session.getSymbolCache().createTypeEnumerator(codeview::LF_VTSHAPE);
  48. case PDB_SymType::FunctionSig:
  49. return Session.getSymbolCache().createTypeEnumerator(
  50. {codeview::LF_PROCEDURE, codeview::LF_MFUNCTION});
  51. case PDB_SymType::Typedef:
  52. return Session.getSymbolCache().createGlobalsEnumerator(codeview::S_UDT);
  53. default:
  54. break;
  55. }
  56. return nullptr;
  57. }
  58. uint32_t NativeExeSymbol::getAge() const {
  59. auto IS = Session.getPDBFile().getPDBInfoStream();
  60. if (IS)
  61. return IS->getAge();
  62. consumeError(IS.takeError());
  63. return 0;
  64. }
  65. std::string NativeExeSymbol::getSymbolsFileName() const {
  66. return std::string(Session.getPDBFile().getFilePath());
  67. }
  68. codeview::GUID NativeExeSymbol::getGuid() const {
  69. auto IS = Session.getPDBFile().getPDBInfoStream();
  70. if (IS)
  71. return IS->getGuid();
  72. consumeError(IS.takeError());
  73. return codeview::GUID{{0}};
  74. }
  75. bool NativeExeSymbol::hasCTypes() const {
  76. auto Dbi = Session.getPDBFile().getPDBDbiStream();
  77. if (Dbi)
  78. return Dbi->hasCTypes();
  79. consumeError(Dbi.takeError());
  80. return false;
  81. }
  82. bool NativeExeSymbol::hasPrivateSymbols() const {
  83. auto Dbi = Session.getPDBFile().getPDBDbiStream();
  84. if (Dbi)
  85. return !Dbi->isStripped();
  86. consumeError(Dbi.takeError());
  87. return false;
  88. }