SymbolizableObjectFile.h 4.0 KB

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