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