1 //===-- DNBArch.h -----------------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Created by Greg Clayton on 6/24/07.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBARCH_H
14 #define LLDB_TOOLS_DEBUGSERVER_SOURCE_DNBARCH_H
17 #include "MacOSX/MachException.h"
20 #include <mach/mach.h>
22 struct DNBRegisterValue
;
23 struct DNBRegisterSetInfo
;
24 class DNBArchProtocol
;
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
);
33 typedef struct DNBArchPluginInfoTag
{
35 DNBArchCallbackCreate Create
;
36 DNBArchCallbackGetRegisterSetInfo GetRegisterSetInfo
;
37 DNBArchCallbackGetBreakpointOpcode GetBreakpointOpcode
;
40 class DNBArchProtocol
{
42 static DNBArchProtocol
*Create(MachThread
*thread
);
44 static uint32_t GetRegisterCPUType();
46 static const DNBRegisterSetInfo
*GetRegisterSetInfo(nub_size_t
*num_reg_sets
);
48 static const uint8_t *GetBreakpointOpcode(nub_size_t byte_size
);
50 static void RegisterArchPlugin(const DNBArchPluginInfo
&arch_info
);
52 static uint32_t GetCPUType();
53 static uint32_t GetCPUSubType();
55 static bool SetArchitecture(uint32_t cpu_type
, uint32_t cpu_subtype
= 0);
57 DNBArchProtocol() : m_save_id(0) {}
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;
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;
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 bool also_set_on_task
) {
84 return INVALID_NUB_HW_INDEX
;
86 virtual uint32_t EnableHardwareWatchpoint(nub_addr_t addr
, nub_size_t size
,
87 bool read
, bool write
,
88 bool also_set_on_task
) {
89 return INVALID_NUB_HW_INDEX
;
91 virtual bool DisableHardwareBreakpoint(uint32_t hw_index
,
92 bool also_set_on_task
) {
95 virtual bool DisableHardwareWatchpoint(uint32_t hw_index
,
96 bool also_set_on_task
) {
99 virtual uint32_t GetHardwareWatchpointHit(nub_addr_t
&addr
) {
100 return INVALID_NUB_HW_INDEX
;
102 virtual bool StepNotComplete() { return false; }
105 friend class MachThread
;
107 uint32_t GetNextRegisterStateSaveID() { return ++m_save_id
; }
111 0, // Transaction is pending, and checkpoint state has been snapshotted.
112 Trans_Done
= 1, // Transaction is done, the current state is committed, and
113 // checkpoint state is irrelevant.
114 Trans_Rolled_Back
= 2 // Transaction is done, the current state has been
115 // rolled back to the checkpoint state.
117 virtual bool StartTransForHWP() { return true; }
118 virtual bool RollbackTransForHWP() { return true; }
119 virtual bool FinishTransForHWP() { return true; }
121 uint32_t m_save_id
; // An always incrementing integer ID used with
122 // SaveRegisterState/RestoreRegisterState
125 #include "MacOSX/arm64/DNBArchImplARM64.h"
126 #include "MacOSX/x86_64/DNBArchImplX86_64.h"