FuncUnwinders.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #ifndef LLDB_SYMBOL_FUNCUNWINDERS_H
  2. #define LLDB_SYMBOL_FUNCUNWINDERS_H
  3. #include "lldb/Core/AddressRange.h"
  4. #include "lldb/lldb-private-enumerations.h"
  5. #include <mutex>
  6. #include <vector>
  7. namespace lldb_private {
  8. class UnwindTable;
  9. class FuncUnwinders {
  10. public:
  11. // FuncUnwinders objects are used to track UnwindPlans for a function (named
  12. // or not - really just an address range)
  13. // We'll record four different UnwindPlans for each address range:
  14. //
  15. // 1. Unwinding from a call site (a valid exception throw location)
  16. // This is often sourced from the eh_frame exception handling info
  17. // 2. Unwinding from a non-call site (any location in the function)
  18. // This is often done by analyzing the function prologue assembly
  19. // language instructions
  20. // 3. A fast unwind method for this function which only retrieves a
  21. // limited set of registers necessary to walk the stack
  22. // 4. An architectural default unwind plan when none of the above are
  23. // available for some reason.
  24. // Additionally, FuncUnwinds object can be asked where the prologue
  25. // instructions are finished for migrating breakpoints past the stack frame
  26. // setup instructions when we don't have line table information.
  27. FuncUnwinders(lldb_private::UnwindTable &unwind_table, AddressRange range);
  28. ~FuncUnwinders();
  29. lldb::UnwindPlanSP GetUnwindPlanAtCallSite(Target &target, Thread &thread);
  30. lldb::UnwindPlanSP GetUnwindPlanAtNonCallSite(Target &target,
  31. lldb_private::Thread &thread);
  32. lldb::UnwindPlanSP GetUnwindPlanFastUnwind(Target &target,
  33. lldb_private::Thread &thread);
  34. lldb::UnwindPlanSP
  35. GetUnwindPlanArchitectureDefault(lldb_private::Thread &thread);
  36. lldb::UnwindPlanSP
  37. GetUnwindPlanArchitectureDefaultAtFunctionEntry(lldb_private::Thread &thread);
  38. Address &GetFirstNonPrologueInsn(Target &target);
  39. const Address &GetFunctionStartAddress() const;
  40. bool ContainsAddress(const Address &addr) const {
  41. return m_range.ContainsFileAddress(addr);
  42. }
  43. // A function may have a Language Specific Data Area specified -- a block of
  44. // data in
  45. // the object file which is used in the processing of an exception throw /
  46. // catch. If any of the UnwindPlans have the address of the LSDA region for
  47. // this function, this will return it.
  48. Address GetLSDAAddress(Target &target);
  49. // A function may have a Personality Routine associated with it -- used in the
  50. // processing of throwing an exception. If any of the UnwindPlans have the
  51. // address of the personality routine, this will return it. Read the target-
  52. // pointer at this address to get the personality function address.
  53. Address GetPersonalityRoutinePtrAddress(Target &target);
  54. // The following methods to retrieve specific unwind plans should rarely be
  55. // used. Instead, clients should ask for the *behavior* they are looking for,
  56. // using one of the above UnwindPlan retrieval methods.
  57. lldb::UnwindPlanSP GetAssemblyUnwindPlan(Target &target, Thread &thread);
  58. lldb::UnwindPlanSP GetObjectFileUnwindPlan(Target &target);
  59. lldb::UnwindPlanSP GetObjectFileAugmentedUnwindPlan(Target &target,
  60. Thread &thread);
  61. lldb::UnwindPlanSP GetEHFrameUnwindPlan(Target &target);
  62. lldb::UnwindPlanSP GetEHFrameAugmentedUnwindPlan(Target &target,
  63. Thread &thread);
  64. lldb::UnwindPlanSP GetDebugFrameUnwindPlan(Target &target);
  65. lldb::UnwindPlanSP GetDebugFrameAugmentedUnwindPlan(Target &target,
  66. Thread &thread);
  67. lldb::UnwindPlanSP GetCompactUnwindUnwindPlan(Target &target);
  68. lldb::UnwindPlanSP GetArmUnwindUnwindPlan(Target &target);
  69. lldb::UnwindPlanSP GetSymbolFileUnwindPlan(Thread &thread);
  70. lldb::UnwindPlanSP GetArchDefaultUnwindPlan(Thread &thread);
  71. lldb::UnwindPlanSP GetArchDefaultAtFuncEntryUnwindPlan(Thread &thread);
  72. private:
  73. lldb::UnwindAssemblySP GetUnwindAssemblyProfiler(Target &target);
  74. // Do a simplistic comparison for the register restore rule for getting the
  75. // caller's pc value on two UnwindPlans -- returns LazyBoolYes if they have
  76. // the same unwind rule for the pc, LazyBoolNo if they do not have the same
  77. // unwind rule for the pc, and LazyBoolCalculate if it was unable to
  78. // determine this for some reason.
  79. lldb_private::LazyBool CompareUnwindPlansForIdenticalInitialPCLocation(
  80. Thread &thread, const lldb::UnwindPlanSP &a, const lldb::UnwindPlanSP &b);
  81. UnwindTable &m_unwind_table;
  82. AddressRange m_range;
  83. std::recursive_mutex m_mutex;
  84. lldb::UnwindPlanSP m_unwind_plan_assembly_sp;
  85. lldb::UnwindPlanSP m_unwind_plan_object_file_sp;
  86. lldb::UnwindPlanSP m_unwind_plan_eh_frame_sp;
  87. lldb::UnwindPlanSP m_unwind_plan_debug_frame_sp;
  88. // augmented by assembly inspection so it's valid everywhere
  89. lldb::UnwindPlanSP m_unwind_plan_object_file_augmented_sp;
  90. lldb::UnwindPlanSP m_unwind_plan_eh_frame_augmented_sp;
  91. lldb::UnwindPlanSP m_unwind_plan_debug_frame_augmented_sp;
  92. std::vector<lldb::UnwindPlanSP> m_unwind_plan_compact_unwind;
  93. lldb::UnwindPlanSP m_unwind_plan_arm_unwind_sp;
  94. lldb::UnwindPlanSP m_unwind_plan_symbol_file_sp;
  95. lldb::UnwindPlanSP m_unwind_plan_fast_sp;
  96. lldb::UnwindPlanSP m_unwind_plan_arch_default_sp;
  97. lldb::UnwindPlanSP m_unwind_plan_arch_default_at_func_entry_sp;
  98. // Fetching the UnwindPlans can be expensive - if we've already attempted to
  99. // get one & failed, don't try again.
  100. bool m_tried_unwind_plan_assembly : 1, m_tried_unwind_plan_eh_frame : 1,
  101. m_tried_unwind_plan_object_file : 1,
  102. m_tried_unwind_plan_debug_frame : 1,
  103. m_tried_unwind_plan_object_file_augmented : 1,
  104. m_tried_unwind_plan_eh_frame_augmented : 1,
  105. m_tried_unwind_plan_debug_frame_augmented : 1,
  106. m_tried_unwind_plan_compact_unwind : 1,
  107. m_tried_unwind_plan_arm_unwind : 1, m_tried_unwind_plan_symbol_file : 1,
  108. m_tried_unwind_fast : 1, m_tried_unwind_arch_default : 1,
  109. m_tried_unwind_arch_default_at_func_entry : 1;
  110. Address m_first_non_prologue_insn;
  111. FuncUnwinders(const FuncUnwinders &) = delete;
  112. const FuncUnwinders &operator=(const FuncUnwinders &) = delete;
  113. }; // class FuncUnwinders
  114. } // namespace lldb_private
  115. #endif // LLDB_SYMBOL_FUNCUNWINDERS_H