1 //===-- DNBArch.h -----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Created by Greg Clayton on 6/24/07.
12 //===----------------------------------------------------------------------===//
14 #ifndef __DebugNubArch_h__
15 #define __DebugNubArch_h__
18 #include "MacOSX/MachException.h"
20 #include <mach/mach.h>
23 struct DNBRegisterValue;
24 struct DNBRegisterSetInfo;
25 class DNBArchProtocol;
28 typedef DNBArchProtocol * (* DNBArchCallbackCreate)(MachThread *thread);
29 typedef const DNBRegisterSetInfo * (* DNBArchCallbackGetRegisterSetInfo)(nub_size_t *num_reg_sets);
30 typedef const uint8_t * (* DNBArchCallbackGetBreakpointOpcode)(nub_size_t byte_size);
32 typedef struct DNBArchPluginInfoTag
35 DNBArchCallbackCreate Create;
36 DNBArchCallbackGetRegisterSetInfo GetRegisterSetInfo;
37 DNBArchCallbackGetBreakpointOpcode GetBreakpointOpcode;
43 static DNBArchProtocol *
44 Create (MachThread *thread);
47 GetRegisterCPUType ();
49 static const DNBRegisterSetInfo *
50 GetRegisterSetInfo (nub_size_t *num_reg_sets);
52 static const uint8_t *
53 GetBreakpointOpcode (nub_size_t byte_size);
56 RegisterArchPlugin (const DNBArchPluginInfo &arch_info);
62 SetArchitecture (uint32_t cpu_type);
70 virtual ~DNBArchProtocol ()
74 virtual bool GetRegisterValue (uint32_t set, uint32_t reg, DNBRegisterValue *value) = 0;
75 virtual bool SetRegisterValue (uint32_t set, uint32_t reg, const DNBRegisterValue *value) = 0;
76 virtual nub_size_t GetRegisterContext (void *buf, nub_size_t buf_len) = 0;
77 virtual nub_size_t SetRegisterContext (const void *buf, nub_size_t buf_len) = 0;
78 virtual uint32_t SaveRegisterState () = 0;
79 virtual bool RestoreRegisterState (uint32_t save_id) = 0;
81 virtual kern_return_t GetRegisterState (int set, bool force) = 0;
82 virtual kern_return_t SetRegisterState (int set) = 0;
83 virtual bool RegisterSetStateIsValid (int set) const = 0;
85 virtual uint64_t GetPC (uint64_t failValue) = 0; // Get program counter
86 virtual kern_return_t SetPC (uint64_t value) = 0;
87 virtual uint64_t GetSP (uint64_t failValue) = 0; // Get stack pointer
88 virtual void ThreadWillResume () = 0;
89 virtual bool ThreadDidStop () = 0;
90 virtual bool NotifyException (MachException::Data& exc) { return false; }
91 virtual uint32_t NumSupportedHardwareBreakpoints() { return 0; }
92 virtual uint32_t NumSupportedHardwareWatchpoints() { return 0; }
93 virtual uint32_t EnableHardwareBreakpoint (nub_addr_t addr, nub_size_t size) { return INVALID_NUB_HW_INDEX; }
94 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; }
95 virtual bool DisableHardwareBreakpoint (uint32_t hw_index) { return false; }
96 virtual bool DisableHardwareWatchpoint (uint32_t hw_index, bool also_set_on_task) { return false; }
97 virtual uint32_t GetHardwareWatchpointHit(nub_addr_t &addr) { return INVALID_NUB_HW_INDEX; }
98 virtual bool StepNotComplete () { return false; }
101 friend class MachThread;
103 uint32_t GetNextRegisterStateSaveID ()
110 Trans_Pending = 0, // Transaction is pending, and checkpoint state has been snapshotted.
111 Trans_Done = 1, // Transaction is done, the current state is committed, and checkpoint state is irrelevant.
112 Trans_Rolled_Back = 2 // Transaction is done, the current state has been rolled back to the checkpoint state.
114 virtual bool StartTransForHWP() { return true; }
115 virtual bool RollbackTransForHWP() { return true; }
116 virtual bool FinishTransForHWP() { return true; }
118 uint32_t m_save_id; // An always incrementing integer ID used with SaveRegisterState/RestoreRegisterState
123 #include "MacOSX/arm/DNBArchImpl.h"
124 #include "MacOSX/arm64/DNBArchImplARM64.h"
125 #include "MacOSX/i386/DNBArchImplI386.h"
126 #include "MacOSX/x86_64/DNBArchImplX86_64.h"
127 #include "MacOSX/ppc/DNBArchImpl.h"