NativeRegisterContext.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //===-- NativeRegisterContext.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. #ifndef LLDB_HOST_COMMON_NATIVEREGISTERCONTEXT_H
  9. #define LLDB_HOST_COMMON_NATIVEREGISTERCONTEXT_H
  10. #include "lldb/Host/common/NativeWatchpointList.h"
  11. #include "lldb/lldb-private.h"
  12. namespace lldb_private {
  13. class NativeThreadProtocol;
  14. enum class ExpeditedRegs { Minimal, Full };
  15. class NativeRegisterContext
  16. : public std::enable_shared_from_this<NativeRegisterContext> {
  17. public:
  18. // Constructors and Destructors
  19. NativeRegisterContext(NativeThreadProtocol &thread);
  20. virtual ~NativeRegisterContext();
  21. // void
  22. // InvalidateIfNeeded (bool force);
  23. // Subclasses must override these functions
  24. // virtual void
  25. // InvalidateAllRegisters () = 0;
  26. virtual uint32_t GetRegisterCount() const = 0;
  27. virtual uint32_t GetUserRegisterCount() const = 0;
  28. virtual const RegisterInfo *GetRegisterInfoAtIndex(uint32_t reg) const = 0;
  29. const char *GetRegisterSetNameForRegisterAtIndex(uint32_t reg_index) const;
  30. virtual uint32_t GetRegisterSetCount() const = 0;
  31. virtual const RegisterSet *GetRegisterSet(uint32_t set_index) const = 0;
  32. virtual Status ReadRegister(const RegisterInfo *reg_info,
  33. RegisterValue &reg_value) = 0;
  34. virtual Status WriteRegister(const RegisterInfo *reg_info,
  35. const RegisterValue &reg_value) = 0;
  36. virtual Status ReadAllRegisterValues(lldb::DataBufferSP &data_sp) = 0;
  37. virtual Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) = 0;
  38. uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind,
  39. uint32_t num) const;
  40. // Subclasses can override these functions if desired
  41. virtual uint32_t NumSupportedHardwareBreakpoints();
  42. virtual uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size);
  43. virtual bool ClearHardwareBreakpoint(uint32_t hw_idx);
  44. virtual Status ClearAllHardwareBreakpoints();
  45. virtual Status GetHardwareBreakHitIndex(uint32_t &bp_index,
  46. lldb::addr_t trap_addr);
  47. virtual uint32_t NumSupportedHardwareWatchpoints();
  48. virtual uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
  49. uint32_t watch_flags);
  50. virtual bool ClearHardwareWatchpoint(uint32_t hw_index);
  51. virtual Status ClearWatchpointHit(uint32_t hw_index);
  52. virtual Status ClearAllHardwareWatchpoints();
  53. virtual Status IsWatchpointHit(uint32_t wp_index, bool &is_hit);
  54. virtual Status GetWatchpointHitIndex(uint32_t &wp_index,
  55. lldb::addr_t trap_addr);
  56. virtual Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant);
  57. virtual lldb::addr_t GetWatchpointAddress(uint32_t wp_index);
  58. // MIPS Linux kernel returns a masked address (last 3bits are masked)
  59. // when a HW watchpoint is hit. However user may not have set a watchpoint on
  60. // this address. This function emulates the instruction at PC and finds the
  61. // base address used in the load/store instruction. This gives the exact
  62. // address used to read/write the variable being watched. For example: 'n' is
  63. // at 0x120010d00 and 'm' is 0x120010d04. When a watchpoint is set at 'm',
  64. // then watch exception is generated even when 'n' is read/written. This
  65. // function returns address of 'n' so that client can check whether a
  66. // watchpoint is set on this address or not.
  67. virtual lldb::addr_t GetWatchpointHitAddress(uint32_t wp_index);
  68. virtual bool HardwareSingleStep(bool enable);
  69. virtual Status
  70. ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info,
  71. lldb::addr_t src_addr, size_t src_len,
  72. RegisterValue &reg_value);
  73. virtual Status
  74. WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info,
  75. lldb::addr_t dst_addr, size_t dst_len,
  76. const RegisterValue &reg_value);
  77. // Subclasses should not override these
  78. virtual lldb::tid_t GetThreadID() const;
  79. virtual NativeThreadProtocol &GetThread() { return m_thread; }
  80. virtual std::vector<uint32_t>
  81. GetExpeditedRegisters(ExpeditedRegs expType) const;
  82. virtual bool RegisterOffsetIsDynamic() const { return false; }
  83. const RegisterInfo *GetRegisterInfoByName(llvm::StringRef reg_name,
  84. uint32_t start_idx = 0);
  85. const RegisterInfo *GetRegisterInfo(uint32_t reg_kind, uint32_t reg_num);
  86. lldb::addr_t GetPC(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
  87. virtual lldb::addr_t
  88. GetPCfromBreakpointLocation(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
  89. Status SetPC(lldb::addr_t pc);
  90. lldb::addr_t GetSP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
  91. Status SetSP(lldb::addr_t sp);
  92. lldb::addr_t GetFP(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
  93. Status SetFP(lldb::addr_t fp);
  94. const char *GetRegisterName(uint32_t reg);
  95. lldb::addr_t GetReturnAddress(lldb::addr_t fail_value = LLDB_INVALID_ADDRESS);
  96. lldb::addr_t GetFlags(lldb::addr_t fail_value = 0);
  97. lldb::addr_t ReadRegisterAsUnsigned(uint32_t reg, lldb::addr_t fail_value);
  98. lldb::addr_t ReadRegisterAsUnsigned(const RegisterInfo *reg_info,
  99. lldb::addr_t fail_value);
  100. Status WriteRegisterFromUnsigned(uint32_t reg, uint64_t uval);
  101. Status WriteRegisterFromUnsigned(const RegisterInfo *reg_info, uint64_t uval);
  102. // uint32_t
  103. // GetStopID () const
  104. // {
  105. // return m_stop_id;
  106. // }
  107. // void
  108. // SetStopID (uint32_t stop_id)
  109. // {
  110. // m_stop_id = stop_id;
  111. // }
  112. protected:
  113. // Classes that inherit from RegisterContext can see and modify these
  114. NativeThreadProtocol
  115. &m_thread; // The thread that this register context belongs to.
  116. // uint32_t m_stop_id; // The stop ID that any data in this
  117. // context is valid for
  118. private:
  119. // For RegisterContext only
  120. NativeRegisterContext(const NativeRegisterContext &) = delete;
  121. const NativeRegisterContext &
  122. operator=(const NativeRegisterContext &) = delete;
  123. };
  124. } // namespace lldb_private
  125. #endif // LLDB_HOST_COMMON_NATIVEREGISTERCONTEXT_H