• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <mach/mach.h>
20 #include <stdio.h>
21 
22 struct DNBRegisterValue;
23 struct DNBRegisterSetInfo;
24 class DNBArchProtocol;
25 class MachThread;
26 
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);
32 
33 typedef struct DNBArchPluginInfoTag {
34   uint32_t cpu_type;
35   DNBArchCallbackCreate Create;
36   DNBArchCallbackGetRegisterSetInfo GetRegisterSetInfo;
37   DNBArchCallbackGetBreakpointOpcode GetBreakpointOpcode;
38 } DNBArchPluginInfo;
39 
40 class DNBArchProtocol {
41 public:
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 
DNBArchProtocol()57   DNBArchProtocol() : m_save_id(0) {}
58 
~DNBArchProtocol()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;
NotifyException(MachException::Data & exc)79   virtual bool NotifyException(MachException::Data &exc) { return false; }
NumSupportedHardwareBreakpoints()80   virtual uint32_t NumSupportedHardwareBreakpoints() { return 0; }
NumSupportedHardwareWatchpoints()81   virtual uint32_t NumSupportedHardwareWatchpoints() { return 0; }
EnableHardwareBreakpoint(nub_addr_t addr,nub_size_t size,bool also_set_on_task)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   }
EnableHardwareWatchpoint(nub_addr_t addr,nub_size_t size,bool read,bool write,bool also_set_on_task)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   }
DisableHardwareBreakpoint(uint32_t hw_index,bool also_set_on_task)91   virtual bool DisableHardwareBreakpoint(uint32_t hw_index,
92                                          bool also_set_on_task) {
93     return false;
94   }
DisableHardwareWatchpoint(uint32_t hw_index,bool also_set_on_task)95   virtual bool DisableHardwareWatchpoint(uint32_t hw_index,
96                                          bool also_set_on_task) {
97     return false;
98   }
GetHardwareWatchpointHit(nub_addr_t & addr)99   virtual uint32_t GetHardwareWatchpointHit(nub_addr_t &addr) {
100     return INVALID_NUB_HW_INDEX;
101   }
StepNotComplete()102   virtual bool StepNotComplete() { return false; }
103 
104 protected:
105   friend class MachThread;
106 
GetNextRegisterStateSaveID()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   };
StartTransForHWP()117   virtual bool StartTransForHWP() { return true; }
RollbackTransForHWP()118   virtual bool RollbackTransForHWP() { return true; }
FinishTransForHWP()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/arm/DNBArchImpl.h"
126 #include "MacOSX/arm64/DNBArchImplARM64.h"
127 #include "MacOSX/i386/DNBArchImplI386.h"
128 #include "MacOSX/x86_64/DNBArchImplX86_64.h"
129 
130 #endif
131