LLDB  mainline
RegisterContextThreadMemory.cpp
Go to the documentation of this file.
1 //===-- RegisterContextThreadMemory.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 
10 #include "lldb/Target/Process.h"
11 #include "lldb/Target/Thread.h"
12 #include "lldb/Utility/Status.h"
13 #include "lldb/lldb-private.h"
14 
16 
17 using namespace lldb;
18 using namespace lldb_private;
19 
20 RegisterContextThreadMemory::RegisterContextThreadMemory(
21  Thread &thread, lldb::addr_t register_data_addr)
22  : RegisterContext(thread, 0), m_thread_wp(thread.shared_from_this()),
23  m_reg_ctx_sp(), m_register_data_addr(register_data_addr), m_stop_id(0) {}
24 
26 
28  ThreadSP thread_sp(m_thread_wp.lock());
29  if (thread_sp) {
30  ProcessSP process_sp(thread_sp->GetProcess());
31 
32  if (process_sp) {
33  const uint32_t stop_id = process_sp->GetModID().GetStopID();
34  if (m_stop_id != stop_id) {
35  m_stop_id = stop_id;
36  m_reg_ctx_sp.reset();
37  }
38  if (!m_reg_ctx_sp) {
39  ThreadSP backing_thread_sp(thread_sp->GetBackingThread());
40  if (backing_thread_sp) {
41  m_reg_ctx_sp = backing_thread_sp->GetRegisterContext();
42  } else {
43  OperatingSystem *os = process_sp->GetOperatingSystem();
44  if (os->IsOperatingSystemPluginThread(thread_sp))
46  thread_sp.get(), m_register_data_addr);
47  }
48  }
49  } else {
50  m_reg_ctx_sp.reset();
51  }
52  } else {
53  m_reg_ctx_sp.reset();
54  }
55 }
56 
57 // Subclasses must override these functions
60  if (m_reg_ctx_sp)
61  m_reg_ctx_sp->InvalidateAllRegisters();
62 }
63 
66  if (m_reg_ctx_sp)
67  return m_reg_ctx_sp->GetRegisterCount();
68  return 0;
69 }
70 
71 const RegisterInfo *
74  if (m_reg_ctx_sp)
75  return m_reg_ctx_sp->GetRegisterInfoAtIndex(reg);
76  return NULL;
77 }
78 
81  if (m_reg_ctx_sp)
82  return m_reg_ctx_sp->GetRegisterSetCount();
83  return 0;
84 }
85 
86 const RegisterSet *RegisterContextThreadMemory::GetRegisterSet(size_t reg_set) {
88  if (m_reg_ctx_sp)
89  return m_reg_ctx_sp->GetRegisterSet(reg_set);
90  return NULL;
91 }
92 
93 bool RegisterContextThreadMemory::ReadRegister(const RegisterInfo *reg_info,
94  RegisterValue &reg_value) {
96  if (m_reg_ctx_sp)
97  return m_reg_ctx_sp->ReadRegister(reg_info, reg_value);
98  return false;
99 }
100 
102  const RegisterInfo *reg_info, const RegisterValue &reg_value) {
104  if (m_reg_ctx_sp)
105  return m_reg_ctx_sp->WriteRegister(reg_info, reg_value);
106  return false;
107 }
108 
110  lldb::DataBufferSP &data_sp) {
112  if (m_reg_ctx_sp)
113  return m_reg_ctx_sp->ReadAllRegisterValues(data_sp);
114  return false;
115 }
116 
118  const lldb::DataBufferSP &data_sp) {
120  if (m_reg_ctx_sp)
121  return m_reg_ctx_sp->WriteAllRegisterValues(data_sp);
122  return false;
123 }
124 
126  lldb::RegisterContextSP reg_ctx_sp) {
128  if (m_reg_ctx_sp)
129  return m_reg_ctx_sp->CopyFromRegisterContext(reg_ctx_sp);
130  return false;
131 }
132 
134  lldb::RegisterKind kind, uint32_t num) {
136  if (m_reg_ctx_sp)
137  return m_reg_ctx_sp->ConvertRegisterKindToRegisterNumber(kind, num);
138  return false;
139 }
140 
143  if (m_reg_ctx_sp)
144  return m_reg_ctx_sp->NumSupportedHardwareBreakpoints();
145  return false;
146 }
147 
149  size_t size) {
151  if (m_reg_ctx_sp)
152  return m_reg_ctx_sp->SetHardwareBreakpoint(addr, size);
153  return 0;
154 }
155 
158  if (m_reg_ctx_sp)
159  return m_reg_ctx_sp->ClearHardwareBreakpoint(hw_idx);
160  return false;
161 }
162 
165  if (m_reg_ctx_sp)
166  return m_reg_ctx_sp->NumSupportedHardwareWatchpoints();
167  return 0;
168 }
169 
171  size_t size,
172  bool read,
173  bool write) {
175  if (m_reg_ctx_sp)
176  return m_reg_ctx_sp->SetHardwareWatchpoint(addr, size, read, write);
177  return 0;
178 }
179 
182  if (m_reg_ctx_sp)
183  return m_reg_ctx_sp->ClearHardwareWatchpoint(hw_index);
184  return false;
185 }
186 
189  if (m_reg_ctx_sp)
190  return m_reg_ctx_sp->HardwareSingleStep(enable);
191  return false;
192 }
193 
195  const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr,
196  uint32_t src_len, RegisterValue &reg_value) {
198  if (m_reg_ctx_sp)
199  return m_reg_ctx_sp->ReadRegisterValueFromMemory(reg_info, src_addr,
200  src_len, reg_value);
201  Status error;
202  error.SetErrorString("invalid register context");
203  return error;
204 }
205 
207  const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr,
208  uint32_t dst_len, const RegisterValue &reg_value) {
210  if (m_reg_ctx_sp)
211  return m_reg_ctx_sp->WriteRegisterValueToMemory(reg_info, dst_addr, dst_len,
212  reg_value);
213  Status error;
214  error.SetErrorString("invalid register context");
215  return error;
216 }
const RegisterSet * GetRegisterSet(size_t reg_set) override
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
const RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write) override
bool CopyFromRegisterContext(lldb::RegisterContextSP context)
bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value) override
A plug-in interface definition class for halted OS helpers.
virtual lldb::RegisterContextSP CreateRegisterContextForThread(Thread *thread, lldb::addr_t reg_data_addr)=0
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
bool ClearHardwareWatchpoint(uint32_t hw_index) override
Status ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, uint32_t src_len, RegisterValue &reg_value) override
uint64_t addr_t
Definition: lldb-types.h:83
Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue &reg_value) override
Definition: SBAddress.h:15
uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override
bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
virtual bool IsOperatingSystemPluginThread(const lldb::ThreadSP &thread_sp)
bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value) override
An error handling class.
Definition: Status.h:44