]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/Process/FreeBSD/RegisterContextPOSIXProcessMonitor_mips64.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / Process / FreeBSD / RegisterContextPOSIXProcessMonitor_mips64.cpp
1 //===-- RegisterContextPOSIXProcessMonitor_mips64.cpp -----------*- 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 #include "lldb/Target/Thread.h"
11 #include "lldb/Utility/DataBufferHeap.h"
12 #include "lldb/Utility/RegisterValue.h"
13
14 #include "Plugins/Process/Utility/RegisterContextPOSIX_mips64.h"
15 #include "ProcessFreeBSD.h"
16 #include "ProcessMonitor.h"
17 #include "RegisterContextPOSIXProcessMonitor_mips64.h"
18
19 using namespace lldb_private;
20 using namespace lldb;
21
22 #define REG_CONTEXT_SIZE (GetGPRSize())
23
24 RegisterContextPOSIXProcessMonitor_mips64::
25     RegisterContextPOSIXProcessMonitor_mips64(
26         Thread &thread, uint32_t concrete_frame_idx,
27         lldb_private::RegisterInfoInterface *register_info)
28     : RegisterContextPOSIX_mips64(thread, concrete_frame_idx, register_info) {}
29
30 ProcessMonitor &RegisterContextPOSIXProcessMonitor_mips64::GetMonitor() {
31   ProcessSP base = CalculateProcess();
32   ProcessFreeBSD *process = static_cast<ProcessFreeBSD *>(base.get());
33   return process->GetMonitor();
34 }
35
36 bool RegisterContextPOSIXProcessMonitor_mips64::ReadGPR() {
37   ProcessMonitor &monitor = GetMonitor();
38   return monitor.ReadGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
39 }
40
41 bool RegisterContextPOSIXProcessMonitor_mips64::ReadFPR() {
42   // XXX not yet implemented
43   return false;
44 }
45
46 bool RegisterContextPOSIXProcessMonitor_mips64::WriteGPR() {
47   ProcessMonitor &monitor = GetMonitor();
48   return monitor.WriteGPR(m_thread.GetID(), &m_gpr_mips64, GetGPRSize());
49 }
50
51 bool RegisterContextPOSIXProcessMonitor_mips64::WriteFPR() {
52   // XXX not yet implemented
53   return false;
54 }
55
56 bool RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(
57     const unsigned reg, RegisterValue &value) {
58   ProcessMonitor &monitor = GetMonitor();
59   return monitor.ReadRegisterValue(m_thread.GetID(), GetRegisterOffset(reg),
60                                    GetRegisterName(reg), GetRegisterSize(reg),
61                                    value);
62 }
63
64 bool RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(
65     const unsigned reg, const RegisterValue &value) {
66   unsigned reg_to_write = reg;
67   RegisterValue value_to_write = value;
68
69   // Check if this is a subregister of a full register.
70   const RegisterInfo *reg_info = GetRegisterInfoAtIndex(reg);
71   if (reg_info->invalidate_regs &&
72       (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM)) {
73     RegisterValue full_value;
74     uint32_t full_reg = reg_info->invalidate_regs[0];
75     const RegisterInfo *full_reg_info = GetRegisterInfoAtIndex(full_reg);
76
77     // Read the full register.
78     if (ReadRegister(full_reg_info, full_value)) {
79       Status error;
80       ByteOrder byte_order = GetByteOrder();
81       uint8_t dst[RegisterValue::kMaxRegisterByteSize];
82
83       // Get the bytes for the full register.
84       const uint32_t dest_size = full_value.GetAsMemoryData(
85           full_reg_info, dst, sizeof(dst), byte_order, error);
86       if (error.Success() && dest_size) {
87         uint8_t src[RegisterValue::kMaxRegisterByteSize];
88
89         // Get the bytes for the source data.
90         const uint32_t src_size = value.GetAsMemoryData(
91             reg_info, src, sizeof(src), byte_order, error);
92         if (error.Success() && src_size && (src_size < dest_size)) {
93           // Copy the src bytes to the destination.
94           memcpy(dst + (reg_info->byte_offset & 0x1), src, src_size);
95           // Set this full register as the value to write.
96           value_to_write.SetBytes(dst, full_value.GetByteSize(), byte_order);
97           value_to_write.SetType(full_reg_info);
98           reg_to_write = full_reg;
99         }
100       }
101     }
102   }
103
104   ProcessMonitor &monitor = GetMonitor();
105   return monitor.WriteRegisterValue(
106       m_thread.GetID(), GetRegisterOffset(reg_to_write),
107       GetRegisterName(reg_to_write), value_to_write);
108 }
109
110 bool RegisterContextPOSIXProcessMonitor_mips64::ReadRegister(
111     const RegisterInfo *reg_info, RegisterValue &value) {
112   if (!reg_info)
113     return false;
114
115   const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
116
117   if (IsFPR(reg)) {
118     if (!ReadFPR())
119       return false;
120   } else {
121     uint32_t full_reg = reg;
122     bool is_subreg = reg_info->invalidate_regs &&
123                      (reg_info->invalidate_regs[0] != LLDB_INVALID_REGNUM);
124
125     if (is_subreg) {
126       // Read the full aligned 64-bit register.
127       full_reg = reg_info->invalidate_regs[0];
128     }
129
130     bool success = ReadRegister(full_reg, value);
131
132     if (success) {
133       // If our read was not aligned (for ah,bh,ch,dh), shift our returned
134       // value one byte to the right.
135       if (is_subreg && (reg_info->byte_offset & 0x1))
136         value.SetUInt64(value.GetAsUInt64() >> 8);
137
138       // If our return byte size was greater than the return value reg size,
139       // then use the type specified by reg_info rather than the uint64_t
140       // default
141       if (value.GetByteSize() > reg_info->byte_size)
142         value.SetType(reg_info);
143     }
144     return success;
145   }
146
147   return false;
148 }
149
150 bool RegisterContextPOSIXProcessMonitor_mips64::WriteRegister(
151     const RegisterInfo *reg_info, const RegisterValue &value) {
152   const uint32_t reg = reg_info->kinds[eRegisterKindLLDB];
153
154   if (IsGPR(reg))
155     return WriteRegister(reg, value);
156
157   return false;
158 }
159
160 bool RegisterContextPOSIXProcessMonitor_mips64::ReadAllRegisterValues(
161     DataBufferSP &data_sp) {
162   bool success = false;
163   data_sp.reset(new DataBufferHeap(REG_CONTEXT_SIZE, 0));
164   if (data_sp && ReadGPR() && ReadFPR()) {
165     uint8_t *dst = data_sp->GetBytes();
166     success = dst != 0;
167
168     if (success) {
169       ::memcpy(dst, &m_gpr_mips64, GetGPRSize());
170     }
171   }
172   return success;
173 }
174
175 bool RegisterContextPOSIXProcessMonitor_mips64::WriteAllRegisterValues(
176     const DataBufferSP &data_sp) {
177   bool success = false;
178   if (data_sp && data_sp->GetByteSize() == REG_CONTEXT_SIZE) {
179     uint8_t *src = data_sp->GetBytes();
180     if (src) {
181       ::memcpy(&m_gpr_mips64, src, GetGPRSize());
182
183       if (WriteGPR()) {
184         src += GetGPRSize();
185       }
186     }
187   }
188   return success;
189 }
190
191 uint32_t RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpoint(
192     addr_t addr, size_t size, bool read, bool write) {
193   const uint32_t num_hw_watchpoints = NumSupportedHardwareWatchpoints();
194   uint32_t hw_index;
195
196   for (hw_index = 0; hw_index < num_hw_watchpoints; ++hw_index) {
197     if (IsWatchpointVacant(hw_index))
198       return SetHardwareWatchpointWithIndex(addr, size, read, write, hw_index);
199   }
200
201   return LLDB_INVALID_INDEX32;
202 }
203
204 bool RegisterContextPOSIXProcessMonitor_mips64::ClearHardwareWatchpoint(
205     uint32_t hw_index) {
206   return false;
207 }
208
209 bool RegisterContextPOSIXProcessMonitor_mips64::HardwareSingleStep(
210     bool enable) {
211   return false;
212 }
213
214 bool RegisterContextPOSIXProcessMonitor_mips64::UpdateAfterBreakpoint() {
215   // PC points one byte past the int3 responsible for the breakpoint.
216   lldb::addr_t pc;
217
218   if ((pc = GetPC()) == LLDB_INVALID_ADDRESS)
219     return false;
220
221   SetPC(pc - 1);
222   return true;
223 }
224
225 unsigned RegisterContextPOSIXProcessMonitor_mips64::GetRegisterIndexFromOffset(
226     unsigned offset) {
227   unsigned reg;
228   for (reg = 0; reg < k_num_registers_mips64; reg++) {
229     if (GetRegisterInfo()[reg].byte_offset == offset)
230       break;
231   }
232   assert(reg < k_num_registers_mips64 && "Invalid register offset.");
233   return reg;
234 }
235
236 bool RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointHit(
237     uint32_t hw_index) {
238   return false;
239 }
240
241 bool RegisterContextPOSIXProcessMonitor_mips64::ClearWatchpointHits() {
242   return false;
243 }
244
245 addr_t RegisterContextPOSIXProcessMonitor_mips64::GetWatchpointAddress(
246     uint32_t hw_index) {
247   return LLDB_INVALID_ADDRESS;
248 }
249
250 bool RegisterContextPOSIXProcessMonitor_mips64::IsWatchpointVacant(
251     uint32_t hw_index) {
252   return false;
253 }
254
255 bool RegisterContextPOSIXProcessMonitor_mips64::SetHardwareWatchpointWithIndex(
256     addr_t addr, size_t size, bool read, bool write, uint32_t hw_index) {
257   return false;
258 }
259
260 uint32_t
261 RegisterContextPOSIXProcessMonitor_mips64::NumSupportedHardwareWatchpoints() {
262   return 0;
263 }