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)(nub_size_t *num_reg_sets); 30 typedef const uint8_t * const (* DNBArchCallbackGetBreakpointOpcode)(nub_size_t byte_size); 31 32 typedef struct DNBArchPluginInfoTag 33 { 34 uint32_t cpu_type; 35 DNBArchCallbackCreate Create; 36 DNBArchCallbackGetRegisterSetInfo GetRegisterSetInfo; 37 DNBArchCallbackGetBreakpointOpcode GetBreakpointOpcode; 38 } DNBArchPluginInfo; 39 40 class DNBArchProtocol 41 { 42 public: 43 static DNBArchProtocol * 44 Create (MachThread *thread); 45 46 static const DNBRegisterSetInfo * 47 GetRegisterSetInfo (nub_size_t *num_reg_sets); 48 49 static const uint8_t * const 50 GetBreakpointOpcode (nub_size_t byte_size); 51 52 static void 53 RegisterArchPlugin (const DNBArchPluginInfo &arch_info); 54 55 static uint32_t 56 GetArchitecture (); 57 58 static bool 59 SetArchitecture (uint32_t cpu_type); 60 61 virtual bool GetRegisterValue (int set, int reg, DNBRegisterValue *value) = 0; 62 virtual bool SetRegisterValue (int set, int reg, 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, nub_size_t buf_len) = 0; 65 66 virtual kern_return_t GetRegisterState (int set, bool force) = 0; 67 virtual kern_return_t SetRegisterState (int set) = 0; 68 virtual bool RegisterSetStateIsValid (int set) const = 0; 69 70 virtual uint64_t GetPC (uint64_t failValue) = 0; // Get program counter 71 virtual kern_return_t SetPC (uint64_t value) = 0; 72 virtual uint64_t GetSP (uint64_t failValue) = 0; // Get stack pointer 73 virtual void ThreadWillResume () = 0; 74 virtual bool ThreadDidStop () = 0; NotifyException(MachException::Data & exc)75 virtual bool NotifyException (MachException::Data& exc) { return false; } NumSupportedHardwareBreakpoints()76 virtual uint32_t NumSupportedHardwareBreakpoints() { return 0; } NumSupportedHardwareWatchpoints()77 virtual uint32_t NumSupportedHardwareWatchpoints() { return 0; } EnableHardwareBreakpoint(nub_addr_t addr,nub_size_t size)78 virtual uint32_t EnableHardwareBreakpoint (nub_addr_t addr, nub_size_t size) { return INVALID_NUB_HW_INDEX; } EnableHardwareWatchpoint(nub_addr_t addr,nub_size_t size,bool read,bool write,bool also_set_on_task)79 virtual uint32_t EnableHardwareWatchpoint (nub_addr_t addr, nub_size_t size, bool read, bool write, bool also_set_on_task) { return INVALID_NUB_HW_INDEX; } DisableHardwareBreakpoint(uint32_t hw_index)80 virtual bool DisableHardwareBreakpoint (uint32_t hw_index) { return false; } DisableHardwareWatchpoint(uint32_t hw_index,bool also_set_on_task)81 virtual bool DisableHardwareWatchpoint (uint32_t hw_index, bool also_set_on_task) { return false; } GetHardwareWatchpointHit()82 virtual uint32_t GetHardwareWatchpointHit() { return INVALID_NUB_HW_INDEX; } StepNotComplete()83 virtual bool StepNotComplete () { return false; } 84 85 protected: 86 friend class MachThread; 87 88 enum 89 { 90 Trans_Pending = 0, // Transaction is pending, and checkpoint state has been snapshotted. 91 Trans_Done = 1, // Transaction is done, the current state is committed, and checkpoint state is irrelevant. 92 Trans_Rolled_Back = 2 // Transaction is done, the current state has been rolled back to the checkpoint state. 93 }; StartTransForHWP()94 virtual bool StartTransForHWP() { return true; } RollbackTransForHWP()95 virtual bool RollbackTransForHWP() { return true; } FinishTransForHWP()96 virtual bool FinishTransForHWP() { return true; } 97 }; 98 99 100 #include "MacOSX/arm/DNBArchImpl.h" 101 #include "MacOSX/i386/DNBArchImplI386.h" 102 #include "MacOSX/x86_64/DNBArchImplX86_64.h" 103 #include "MacOSX/ppc/DNBArchImpl.h" 104 105 #endif 106