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 <cstdio>
20#include <mach/mach.h>
21
22struct DNBRegisterValue;
23struct DNBRegisterSetInfo;
24class DNBArchProtocol;
25class MachThread;
26
27typedef DNBArchProtocol *(*DNBArchCallbackCreate)(MachThread *thread);
28typedef const DNBRegisterSetInfo *(*DNBArchCallbackGetRegisterSetInfo)(
29 nub_size_t *num_reg_sets);
30typedef const uint8_t *(*DNBArchCallbackGetBreakpointOpcode)(
31 nub_size_t byte_size);
32
33typedef struct DNBArchPluginInfoTag {
34 uint32_t cpu_type;
35 DNBArchCallbackCreate Create;
36 DNBArchCallbackGetRegisterSetInfo GetRegisterSetInfo;
37 DNBArchCallbackGetBreakpointOpcode GetBreakpointOpcode;
38} DNBArchPluginInfo;
39
40class DNBArchProtocol {
41public:
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 GetCPUType();
53 static uint32_t GetCPUSubType();
54
55 static bool SetArchitecture(uint32_t cpu_type, uint32_t cpu_subtype = 0);
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 bool also_set_on_task) {
84 return INVALID_NUB_HW_INDEX;
85 }
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;
90 }
91 virtual bool DisableHardwareBreakpoint(uint32_t hw_index,
92 bool also_set_on_task) {
93 return false;
94 }
95 virtual bool DisableHardwareWatchpoint(uint32_t hw_index,
96 bool also_set_on_task) {
97 return false;
98 }
99 virtual uint32_t GetHardwareWatchpointHit(nub_addr_t &addr) {
100 return INVALID_NUB_HW_INDEX;
101 }
102 virtual bool StepNotComplete() { return false; }
103
104protected:
105 friend class MachThread;
106
107 uint32_t GetNextRegisterStateSaveID() { return ++m_save_id; }
108
109 enum {
110 Trans_Pending =
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.
116 };
117 virtual bool StartTransForHWP() { return true; }
118 virtual bool RollbackTransForHWP() { return true; }
119 virtual bool FinishTransForHWP() { return true; }
120
121 uint32_t m_save_id; // An always incrementing integer ID used with
122 // SaveRegisterState/RestoreRegisterState
123};
124
125#include "MacOSX/arm64/DNBArchImplARM64.h"
126#include "MacOSX/x86_64/DNBArchImplX86_64.h"
127
128#endif
129

source code of lldb/tools/debugserver/source/DNBArch.h