NativeSession.h 5.8 KB

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