LLDB mainline
RegisterContextMemory.cpp
Go to the documentation of this file.
1//===-- RegisterContextMemory.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
11#include "lldb/Target/Process.h"
12#include "lldb/Target/Thread.h"
15#include "lldb/Utility/Status.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
20// RegisterContextMemory constructor
22 uint32_t concrete_frame_idx,
23 DynamicRegisterInfo &reg_infos,
24 addr_t reg_data_addr)
25 : RegisterContext(thread, concrete_frame_idx), m_reg_infos(reg_infos),
26 m_reg_valid(), m_reg_data(), m_reg_data_addr(reg_data_addr) {
27 // Resize our vector of bools to contain one bool for every register. We will
28 // use these boolean values to know when a register value is valid in
29 // m_reg_data.
30 const size_t num_regs = reg_infos.GetNumRegisters();
31 assert(num_regs > 0);
32 m_reg_valid.resize(num_regs);
33
34 // Make a heap based buffer that is big enough to store all registers
35 m_data =
36 std::make_shared<DataBufferHeap>(reg_infos.GetRegisterDataByteSize(), 0);
38}
39
40// Destructor
42
46}
47
49 std::vector<bool>::iterator pos, end = m_reg_valid.end();
50 for (pos = m_reg_valid.begin(); pos != end; ++pos)
51 *pos = b;
52}
53
56}
57
60}
61
64}
65
67 return m_reg_infos.GetRegisterSet(reg_set);
68}
69
71 lldb::RegisterKind kind, uint32_t num) {
73}
74
76 RegisterValue &reg_value) {
77 const uint32_t reg_num = reg_info->kinds[eRegisterKindLLDB];
78 if (!m_reg_valid[reg_num]) {
80 return false;
81 }
82 const bool partial_data_ok = false;
83 return reg_value
84 .SetValueFromData(*reg_info, m_reg_data, reg_info->byte_offset,
85 partial_data_ok)
86 .Success();
87}
88
90 const RegisterValue &reg_value) {
92 const uint32_t reg_num = reg_info->kinds[eRegisterKindLLDB];
93 addr_t reg_addr = m_reg_data_addr + reg_info->byte_offset;
94 Status error(WriteRegisterValueToMemory(reg_info, reg_addr,
95 reg_info->byte_size, reg_value));
96 m_reg_valid[reg_num] = false;
97 return error.Success();
98 }
99 return false;
100}
101
103 WritableDataBufferSP &data_sp) {
105 ProcessSP process_sp(CalculateProcess());
106 if (process_sp) {
108 if (process_sp->ReadMemory(m_reg_data_addr, data_sp->GetBytes(),
109 data_sp->GetByteSize(),
110 error) == data_sp->GetByteSize()) {
112 return true;
113 }
114 }
115 }
116 return false;
117}
118
120 const DataBufferSP &data_sp) {
122 ProcessSP process_sp(CalculateProcess());
123 if (process_sp) {
125 SetAllRegisterValid(false);
126 if (process_sp->WriteMemory(m_reg_data_addr, data_sp->GetBytes(),
127 data_sp->GetByteSize(),
128 error) == data_sp->GetByteSize())
129 return true;
130 }
131 }
132 return false;
133}
134
136 const lldb::DataBufferSP &data_sp) {
137 m_reg_data.SetData(data_sp);
139}
static llvm::raw_ostream & error(Stream &strm)
void SetAllRegisterData(const lldb::DataBufferSP &data_sp)
std::vector< bool > m_reg_valid
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
bool ReadAllRegisterValues(lldb::WritableDataBufferSP &data_sp) override
bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &reg_value) override
size_t GetRegisterCount() override
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
const lldb_private::RegisterSet * GetRegisterSet(size_t reg_set) override
lldb_private::DataExtractor m_reg_data
void InvalidateAllRegisters() override
lldb::WritableDataBufferSP m_data
size_t GetRegisterSetCount() override
lldb_private::DynamicRegisterInfo & m_reg_infos
bool ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &reg_value) override
~RegisterContextMemory() override
RegisterContextMemory(lldb_private::Thread &thread, uint32_t concrete_frame_idx, lldb_private::DynamicRegisterInfo &reg_info, lldb::addr_t reg_data_addr)
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
const lldb_private::RegisterSet * GetRegisterSet(uint32_t i) const
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(uint32_t i) const
uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind, uint32_t num) const
lldb::ProcessSP CalculateProcess() override
virtual Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue &reg_value)
Status SetValueFromData(const RegisterInfo &reg_info, DataExtractor &data, lldb::offset_t offset, bool partial_data_ok)
An error handling class.
Definition: Status.h:44
bool Success() const
Test for success condition.
Definition: Status.cpp:278
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
A class that represents a running process on the host machine.
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:334
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
Definition: lldb-forward.h:335
uint64_t addr_t
Definition: lldb-types.h:80
RegisterKind
Register numbering types.
@ eRegisterKindLLDB
lldb's internal register numbers
Every register is described in detail including its name, alternate name (optional),...
uint32_t byte_offset
The byte offset in the register context data where this register's value is found.
uint32_t byte_size
Size in bytes of the register.
uint32_t kinds[lldb::kNumRegisterKinds]
Holds all of the various register numbers for all register kinds.
Registers are grouped into register sets.