SymbolizableObjectFile.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //===- SymbolizableObjectFile.h ---------------------------------*- 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. //
  9. // This file declares the SymbolizableObjectFile class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
  13. #define LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
  14. #include "llvm/ADT/StringRef.h"
  15. #include "llvm/DebugInfo/DIContext.h"
  16. #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
  17. #include "llvm/Support/Error.h"
  18. #include <cstdint>
  19. #include <memory>
  20. #include <string>
  21. #include <utility>
  22. #include <vector>
  23. namespace llvm {
  24. class DataExtractor;
  25. namespace symbolize {
  26. class SymbolizableObjectFile : public SymbolizableModule {
  27. public:
  28. static Expected<std::unique_ptr<SymbolizableObjectFile>>
  29. create(const object::ObjectFile *Obj, std::unique_ptr<DIContext> DICtx,
  30. bool UntagAddresses);
  31. DILineInfo symbolizeCode(object::SectionedAddress ModuleOffset,
  32. DILineInfoSpecifier LineInfoSpecifier,
  33. bool UseSymbolTable) const override;
  34. DIInliningInfo symbolizeInlinedCode(object::SectionedAddress ModuleOffset,
  35. DILineInfoSpecifier LineInfoSpecifier,
  36. bool UseSymbolTable) const override;
  37. DIGlobal symbolizeData(object::SectionedAddress ModuleOffset) const override;
  38. std::vector<DILocal>
  39. symbolizeFrame(object::SectionedAddress ModuleOffset) const override;
  40. // Return true if this is a 32-bit x86 PE COFF module.
  41. bool isWin32Module() const override;
  42. // Returns the preferred base of the module, i.e. where the loader would place
  43. // it in memory assuming there were no conflicts.
  44. uint64_t getModulePreferredBase() const override;
  45. private:
  46. bool shouldOverrideWithSymbolTable(FunctionNameKind FNKind,
  47. bool UseSymbolTable) const;
  48. bool getNameFromSymbolTable(uint64_t Address, std::string &Name,
  49. uint64_t &Addr, uint64_t &Size,
  50. std::string &FileName) const;
  51. // For big-endian PowerPC64 ELF, OpdAddress is the address of the .opd
  52. // (function descriptor) section and OpdExtractor refers to its contents.
  53. Error addSymbol(const object::SymbolRef &Symbol, uint64_t SymbolSize,
  54. DataExtractor *OpdExtractor = nullptr,
  55. uint64_t OpdAddress = 0);
  56. Error addCoffExportSymbols(const object::COFFObjectFile *CoffObj);
  57. /// Search for the first occurence of specified Address in ObjectFile.
  58. uint64_t getModuleSectionIndexForAddress(uint64_t Address) const;
  59. const object::ObjectFile *Module;
  60. std::unique_ptr<DIContext> DebugInfoContext;
  61. bool UntagAddresses;
  62. struct SymbolDesc {
  63. uint64_t Addr;
  64. // If size is 0, assume that symbol occupies the whole memory range up to
  65. // the following symbol.
  66. uint64_t Size;
  67. StringRef Name;
  68. // Non-zero if this is an ELF local symbol. See the comment in
  69. // getNameFromSymbolTable.
  70. uint32_t ELFLocalSymIdx;
  71. bool operator<(const SymbolDesc &RHS) const {
  72. return Addr != RHS.Addr ? Addr < RHS.Addr : Size < RHS.Size;
  73. }
  74. };
  75. std::vector<SymbolDesc> Symbols;
  76. // (index, filename) pairs of ELF STT_FILE symbols.
  77. std::vector<std::pair<uint32_t, StringRef>> FileSymbols;
  78. SymbolizableObjectFile(const object::ObjectFile *Obj,
  79. std::unique_ptr<DIContext> DICtx,
  80. bool UntagAddresses);
  81. };
  82. } // end namespace symbolize
  83. } // end namespace llvm
  84. #endif // LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H