diff options
Diffstat (limited to 'include/lldb/Host/common/NativeProcessProtocol.h')
-rw-r--r-- | include/lldb/Host/common/NativeProcessProtocol.h | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/include/lldb/Host/common/NativeProcessProtocol.h b/include/lldb/Host/common/NativeProcessProtocol.h index d96835d75839..cb3b18eb0a3d 100644 --- a/include/lldb/Host/common/NativeProcessProtocol.h +++ b/include/lldb/Host/common/NativeProcessProtocol.h @@ -25,6 +25,8 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" +#include <mutex> +#include <unordered_map> #include <vector> namespace lldb_private { @@ -35,8 +37,6 @@ class ResumeActionList; // NativeProcessProtocol //------------------------------------------------------------------ class NativeProcessProtocol { - friend class SoftwareBreakpoint; - public: virtual ~NativeProcessProtocol() {} @@ -84,8 +84,8 @@ public: virtual Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read) = 0; - virtual Status ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, - size_t size, size_t &bytes_read) = 0; + Status ReadMemoryWithoutTrap(lldb::addr_t addr, void *buf, size_t size, + size_t &bytes_read); virtual Status WriteMemory(lldb::addr_t addr, const void *buf, size_t size, size_t &bytes_written) = 0; @@ -111,10 +111,6 @@ public: virtual Status RemoveBreakpoint(lldb::addr_t addr, bool hardware = false); - virtual Status EnableBreakpoint(lldb::addr_t addr); - - virtual Status DisableBreakpoint(lldb::addr_t addr); - //---------------------------------------------------------------------- // Hardware Breakpoint functions //---------------------------------------------------------------------- @@ -402,6 +398,13 @@ public: } protected: + struct SoftwareBreakpoint { + uint32_t ref_count; + llvm::SmallVector<uint8_t, 4> saved_opcodes; + llvm::ArrayRef<uint8_t> breakpoint_opcodes; + }; + + std::unordered_map<lldb::addr_t, SoftwareBreakpoint> m_software_breakpoints; lldb::pid_t m_pid; std::vector<std::unique_ptr<NativeThreadProtocol>> m_threads; @@ -415,7 +418,6 @@ protected: std::recursive_mutex m_delegates_mutex; std::vector<NativeDelegate *> m_delegates; - NativeBreakpointList m_breakpoint_list; NativeWatchpointList m_watchpoint_list; HardwareBreakpointMap m_hw_breakpoints_map; int m_terminal_fd; @@ -446,12 +448,23 @@ protected: // ----------------------------------------------------------- Internal // interface for software breakpoints // ----------------------------------------------------------- + Status SetSoftwareBreakpoint(lldb::addr_t addr, uint32_t size_hint); + Status RemoveSoftwareBreakpoint(lldb::addr_t addr); + + virtual llvm::Expected<llvm::ArrayRef<uint8_t>> + GetSoftwareBreakpointTrapOpcode(size_t size_hint); + + /// Return the offset of the PC relative to the software breakpoint that was hit. If an + /// architecture (e.g. arm) reports breakpoint hits before incrementing the PC, this offset + /// will be 0. If an architecture (e.g. intel) reports breakpoints hits after incrementing the + /// PC, this offset will be the size of the breakpoint opcode. + virtual size_t GetSoftwareBreakpointPCOffset(); - virtual Status - GetSoftwareBreakpointTrapOpcode(size_t trap_opcode_size_hint, - size_t &actual_opcode_size, - const uint8_t *&trap_opcode_bytes) = 0; + // Adjust the thread's PC after hitting a software breakpoint. On + // architectures where the PC points after the breakpoint instruction, this + // resets it to point to the breakpoint itself. + void FixupBreakpointPCAsNeeded(NativeThreadProtocol &thread); // ----------------------------------------------------------- /// Notify the delegate that an exec occurred. @@ -465,6 +478,8 @@ protected: private: void SynchronouslyNotifyProcessStateChanged(lldb::StateType state); + llvm::Expected<SoftwareBreakpoint> + EnableSoftwareBreakpoint(lldb::addr_t addr, uint32_t size_hint); }; } // namespace lldb_private |