]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/debugserver/source/DNBArch.h
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / tools / debugserver / source / DNBArch.h
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 * (* 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 uint32_t
47     GetRegisterCPUType ();
48
49     static const DNBRegisterSetInfo * 
50     GetRegisterSetInfo (nub_size_t *num_reg_sets);
51
52     static const uint8_t *
53     GetBreakpointOpcode (nub_size_t byte_size);
54
55     static void
56     RegisterArchPlugin (const DNBArchPluginInfo &arch_info);
57
58     static uint32_t
59     GetArchitecture ();
60
61     static bool
62     SetArchitecture (uint32_t cpu_type);
63     
64     DNBArchProtocol () :
65         m_save_id(0)
66     {
67         
68     }
69     
70     virtual ~DNBArchProtocol ()
71     {
72         
73     }
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;
80
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;
84
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; }
99
100 protected:
101     friend class MachThread;
102
103     uint32_t                GetNextRegisterStateSaveID ()
104                             {
105                                 return ++m_save_id;
106                             }
107
108     enum
109     {
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.
113     };
114     virtual bool StartTransForHWP() { return true; }
115     virtual bool RollbackTransForHWP() { return true; }
116     virtual bool FinishTransForHWP() { return true; }
117     
118     uint32_t m_save_id;         // An always incrementing integer ID used with SaveRegisterState/RestoreRegisterState
119
120 };
121
122
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"
128
129 #endif