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