LLDB mainline
RegisterContextThreadMemory.cpp
Go to the documentation of this file.
1//===-- RegisterContextThreadMemory.cpp -----------------------------------===//
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
17using namespace lldb;
18using namespace lldb_private;
19
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
71const RegisterInfo *
74 if (m_reg_ctx_sp)
75 return m_reg_ctx_sp->GetRegisterInfoAtIndex(reg);
76 return nullptr;
77}
78
81 if (m_reg_ctx_sp)
82 return m_reg_ctx_sp->GetRegisterSetCount();
83 return 0;
84}
85
86const RegisterSet *RegisterContextThreadMemory::GetRegisterSet(size_t reg_set) {
88 if (m_reg_ctx_sp)
89 return m_reg_ctx_sp->GetRegisterSet(reg_set);
90 return nullptr;
91}
92
93bool 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::WritableDataBufferSP &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);
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);
214 error.SetErrorString("invalid register context");
215 return error;
216}
static llvm::raw_ostream & error(Stream &strm)
A plug-in interface definition class for halted OS helpers.
virtual lldb::RegisterContextSP CreateRegisterContextForThread(Thread *thread, lldb::addr_t reg_data_addr)=0
virtual bool IsOperatingSystemPluginThread(const lldb::ThreadSP &thread_sp)
bool WriteRegister(const RegisterInfo *reg_info, const RegisterValue &reg_value) override
const RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
bool ClearHardwareWatchpoint(uint32_t hw_index) override
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size, bool read, bool write) override
Status ReadRegisterValueFromMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t src_addr, uint32_t src_len, RegisterValue &reg_value) override
bool CopyFromRegisterContext(lldb::RegisterContextSP context)
bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value) override
RegisterContextThreadMemory(Thread &thread, lldb::addr_t register_data_addr)
uint32_t SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override
Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue &reg_value) override
const RegisterSet * GetRegisterSet(size_t reg_set) override
bool ReadAllRegisterValues(lldb::WritableDataBufferSP &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.
An error handling class.
Definition: Status.h:44
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
uint64_t addr_t
Definition: lldb-types.h:83
RegisterKind
Register numbering types.