NativeSession.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- NativeSession.h - Native implementation of IPDBSession ---*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H
  14. #define LLVM_DEBUGINFO_PDB_NATIVE_NATIVESESSION_H
  15. #include "llvm/ADT/IntervalMap.h"
  16. #include "llvm/ADT/StringRef.h"
  17. #include "llvm/DebugInfo/PDB/IPDBSession.h"
  18. #include "llvm/DebugInfo/PDB/Native/SymbolCache.h"
  19. #include "llvm/DebugInfo/PDB/PDBTypes.h"
  20. #include "llvm/Support/Allocator.h"
  21. #include "llvm/Support/Error.h"
  22. namespace llvm {
  23. class MemoryBuffer;
  24. namespace pdb {
  25. class PDBFile;
  26. class NativeExeSymbol;
  27. class IPDBSourceFile;
  28. class ModuleDebugStreamRef;
  29. class PDBSymbol;
  30. class PDBSymbolCompiland;
  31. class PDBSymbolExe;
  32. template <typename ChildType> class IPDBEnumChildren;
  33. class NativeSession : public IPDBSession {
  34. struct PdbSearchOptions {
  35. StringRef ExePath;
  36. // FIXME: Add other PDB search options (_NT_SYMBOL_PATH, symsrv)
  37. };
  38. public:
  39. NativeSession(std::unique_ptr<PDBFile> PdbFile,
  40. std::unique_ptr<BumpPtrAllocator> Allocator);
  41. ~NativeSession() override;
  42. static Error createFromPdb(std::unique_ptr<MemoryBuffer> MB,
  43. std::unique_ptr<IPDBSession> &Session);
  44. static Error createFromPdbPath(StringRef PdbPath,
  45. std::unique_ptr<IPDBSession> &Session);
  46. static Error createFromExe(StringRef Path,
  47. std::unique_ptr<IPDBSession> &Session);
  48. static Expected<std::string> searchForPdb(const PdbSearchOptions &Opts);
  49. uint64_t getLoadAddress() const override;
  50. bool setLoadAddress(uint64_t Address) override;
  51. std::unique_ptr<PDBSymbolExe> getGlobalScope() override;
  52. std::unique_ptr<PDBSymbol> getSymbolById(SymIndexId SymbolId) const override;
  53. bool addressForVA(uint64_t VA, uint32_t &Section,
  54. uint32_t &Offset) const override;
  55. bool addressForRVA(uint32_t RVA, uint32_t &Section,
  56. uint32_t &Offset) const override;
  57. std::unique_ptr<PDBSymbol> findSymbolByAddress(uint64_t Address,
  58. PDB_SymType Type) override;
  59. std::unique_ptr<PDBSymbol> findSymbolByRVA(uint32_t RVA,
  60. PDB_SymType Type) override;
  61. std::unique_ptr<PDBSymbol> findSymbolBySectOffset(uint32_t Sect,
  62. uint32_t Offset,
  63. PDB_SymType Type) override;
  64. std::unique_ptr<IPDBEnumLineNumbers>
  65. findLineNumbers(const PDBSymbolCompiland &Compiland,
  66. const IPDBSourceFile &File) const override;
  67. std::unique_ptr<IPDBEnumLineNumbers>
  68. findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override;
  69. std::unique_ptr<IPDBEnumLineNumbers>
  70. findLineNumbersByRVA(uint32_t RVA, uint32_t Length) const override;
  71. std::unique_ptr<IPDBEnumLineNumbers>
  72. findLineNumbersBySectOffset(uint32_t Section, uint32_t Offset,
  73. uint32_t Length) const override;
  74. std::unique_ptr<IPDBEnumSourceFiles>
  75. findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,
  76. PDB_NameSearchFlags Flags) const override;
  77. std::unique_ptr<IPDBSourceFile>
  78. findOneSourceFile(const PDBSymbolCompiland *Compiland,
  79. llvm::StringRef Pattern,
  80. PDB_NameSearchFlags Flags) const override;
  81. std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
  82. findCompilandsForSourceFile(llvm::StringRef Pattern,
  83. PDB_NameSearchFlags Flags) const override;
  84. std::unique_ptr<PDBSymbolCompiland>
  85. findOneCompilandForSourceFile(llvm::StringRef Pattern,
  86. PDB_NameSearchFlags Flags) const override;
  87. std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override;
  88. std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
  89. const PDBSymbolCompiland &Compiland) const override;
  90. std::unique_ptr<IPDBSourceFile>
  91. getSourceFileById(uint32_t FileId) const override;
  92. std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override;
  93. std::unique_ptr<IPDBEnumTables> getEnumTables() const override;
  94. std::unique_ptr<IPDBEnumInjectedSources> getInjectedSources() const override;
  95. std::unique_ptr<IPDBEnumSectionContribs> getSectionContribs() const override;
  96. std::unique_ptr<IPDBEnumFrameData> getFrameData() const override;
  97. PDBFile &getPDBFile() { return *Pdb; }
  98. const PDBFile &getPDBFile() const { return *Pdb; }
  99. NativeExeSymbol &getNativeGlobalScope() const;
  100. SymbolCache &getSymbolCache() { return Cache; }
  101. const SymbolCache &getSymbolCache() const { return Cache; }
  102. uint32_t getRVAFromSectOffset(uint32_t Section, uint32_t Offset) const;
  103. uint64_t getVAFromSectOffset(uint32_t Section, uint32_t Offset) const;
  104. bool moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const;
  105. bool moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset,
  106. uint16_t &ModuleIndex) const;
  107. Expected<ModuleDebugStreamRef> getModuleDebugStream(uint32_t Index) const;
  108. private:
  109. void initializeExeSymbol();
  110. void parseSectionContribs();
  111. std::unique_ptr<PDBFile> Pdb;
  112. std::unique_ptr<BumpPtrAllocator> Allocator;
  113. SymbolCache Cache;
  114. SymIndexId ExeSymbol = 0;
  115. uint64_t LoadAddress = 0;
  116. /// Map from virtual address to module index.
  117. using IMap =
  118. IntervalMap<uint64_t, uint16_t, 8, IntervalMapHalfOpenInfo<uint64_t>>;
  119. IMap::Allocator IMapAllocator;
  120. IMap AddrToModuleIndex;
  121. };
  122. } // namespace pdb
  123. } // namespace llvm
  124. #endif
  125. #ifdef __GNUC__
  126. #pragma GCC diagnostic pop
  127. #endif