1 //===-- DNBArch.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 // Created by Greg Clayton on 6/24/07. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBARCH_H 14 #define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBARCH_H 15 16 #include "DNBDefs.h" 17 #include "MacOSX/MachException.h" 18 19 #include <mach/mach.h> 20 #include <stdio.h> 21 22 struct DNBRegisterValue; 23 struct DNBRegisterSetInfo; 24 class DNBArchProtocol; 25 class MachThread; 26 27 typedef DNBArchProtocol *(*DNBArchCallbackCreate)(MachThread *thread); 28 typedef const DNBRegisterSetInfo *(*DNBArchCallbackGetRegisterSetInfo)( 29 nub_size_t *num_reg_sets); 30 typedef const uint8_t *(*DNBArchCallbackGetBreakpointOpcode)( 31 nub_size_t byte_size); 32 33 typedef struct DNBArchPluginInfoTag { 34 uint32_t cpu_type; 35 DNBArchCallbackCreate Create; 36 DNBArchCallbackGetRegisterSetInfo GetRegisterSetInfo; 37 DNBArchCallbackGetBreakpointOpcode GetBreakpointOpcode; 38 } DNBArchPluginInfo; 39 40 class DNBArchProtocol { 41 public: 42 static DNBArchProtocol *Create(MachThread *thread); 43 44 static uint32_t GetRegisterCPUType(); 45 46 static const DNBRegisterSetInfo *GetRegisterSetInfo(nub_size_t *num_reg_sets); 47 48 static const uint8_t *GetBreakpointOpcode(nub_size_t byte_size); 49 50 static void RegisterArchPlugin(const DNBArchPluginInfo &arch_info); 51 52 static uint32_t GetArchitecture(); 53 54 static bool SetArchitecture(uint32_t cpu_type); 55 56 DNBArchProtocol() : m_save_id(0) {} 57 58 virtual ~DNBArchProtocol() {} 59 virtual bool GetRegisterValue(uint32_t set, uint32_t reg, 60 DNBRegisterValue *value) = 0; 61 virtual bool SetRegisterValue(uint32_t set, uint32_t reg, 62 const DNBRegisterValue *value) = 0; 63 virtual nub_size_t GetRegisterContext(void *buf, nub_size_t buf_len) = 0; 64 virtual nub_size_t SetRegisterContext(const void *buf, 65 nub_size_t buf_len) = 0; 66 virtual uint32_t SaveRegisterState() = 0; 67 virtual bool RestoreRegisterState(uint32_t save_id) = 0; 68 69 virtual kern_return_t GetRegisterState(int set, bool force) = 0; 70 virtual kern_return_t SetRegisterState(int set) = 0; 71 virtual bool RegisterSetStateIsValid(int set) const = 0; 72 73 virtual uint64_t GetPC(uint64_t failValue) = 0; // Get program counter 74 virtual kern_return_t SetPC(uint64_t value) = 0; 75 virtual uint64_t GetSP(uint64_t failValue) = 0; // Get stack pointer 76 virtual void ThreadWillResume() = 0; 77 virtual bool ThreadDidStop() = 0; 78 virtual bool NotifyException(MachException::Data &exc) { return false; } 79 virtual uint32_t NumSupportedHardwareBreakpoints() { return 0; } 80 virtual uint32_t NumSupportedHardwareWatchpoints() { return 0; } 81 virtual uint32_t EnableHardwareBreakpoint(nub_addr_t addr, nub_size_t size, 82 bool also_set_on_task) { 83 return INVALID_NUB_HW_INDEX; 84 } 85 virtual uint32_t EnableHardwareWatchpoint(nub_addr_t addr, nub_size_t size, 86 bool read, bool write, 87 bool also_set_on_task) { 88 return INVALID_NUB_HW_INDEX; 89 } 90 virtual bool DisableHardwareBreakpoint(uint32_t hw_index, 91 bool also_set_on_task) { 92 return false; 93 } 94 virtual bool DisableHardwareWatchpoint(uint32_t hw_index, 95 bool also_set_on_task) { 96 return false; 97 } 98 virtual uint32_t GetHardwareWatchpointHit(nub_addr_t &addr) { 99 return INVALID_NUB_HW_INDEX; 100 } 101 virtual bool StepNotComplete() { return false; } 102 103 protected: 104 friend class MachThread; 105 106 uint32_t GetNextRegisterStateSaveID() { return ++m_save_id; } 107 108 enum { 109 Trans_Pending = 110 0, // Transaction is pending, and checkpoint state has been snapshotted. 111 Trans_Done = 1, // Transaction is done, the current state is committed, and 112 // checkpoint state is irrelevant. 113 Trans_Rolled_Back = 2 // Transaction is done, the current state has been 114 // rolled back to the checkpoint state. 115 }; 116 virtual bool StartTransForHWP() { return true; } 117 virtual bool RollbackTransForHWP() { return true; } 118 virtual bool FinishTransForHWP() { return true; } 119 120 uint32_t m_save_id; // An always incrementing integer ID used with 121 // SaveRegisterState/RestoreRegisterState 122 }; 123 124 #include "MacOSX/arm/DNBArchImpl.h" 125 #include "MacOSX/arm64/DNBArchImplARM64.h" 126 #include "MacOSX/i386/DNBArchImplI386.h" 127 #include "MacOSX/x86_64/DNBArchImplX86_64.h" 128 129 #endif 130