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 
17 using namespace lldb;
18 using 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  DataBufferSP reg_data_sp(
36  new DataBufferHeap(reg_infos.GetRegisterDataByteSize(), 0));
37  m_reg_data.SetData(reg_data_sp);
38 }
39 
40 // Destructor
42 
45  SetAllRegisterValid(false);
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 
58 const RegisterInfo *RegisterContextMemory::GetRegisterInfoAtIndex(size_t reg) {
60 }
61 
64 }
65 
66 const RegisterSet *RegisterContextMemory::GetRegisterSet(size_t reg_set) {
67  return m_reg_infos.GetRegisterSet(reg_set);
68 }
69 
71  lldb::RegisterKind kind, uint32_t num) {
73 }
74 
75 bool RegisterContextMemory::ReadRegister(const RegisterInfo *reg_info,
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 
89 bool RegisterContextMemory::WriteRegister(const RegisterInfo *reg_info,
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 
102 bool RegisterContextMemory::ReadAllRegisterValues(DataBufferSP &data_sp) {
104  ProcessSP process_sp(CalculateProcess());
105  if (process_sp) {
106  Status error;
107  if (process_sp->ReadMemory(m_reg_data_addr, data_sp->GetBytes(),
108  data_sp->GetByteSize(),
109  error) == data_sp->GetByteSize()) {
110  SetAllRegisterValid(true);
111  return true;
112  }
113  }
114  }
115  return false;
116 }
117 
119  const DataBufferSP &data_sp) {
121  ProcessSP process_sp(CalculateProcess());
122  if (process_sp) {
123  Status error;
124  SetAllRegisterValid(false);
125  if (process_sp->WriteMemory(m_reg_data_addr, data_sp->GetBytes(),
126  data_sp->GetByteSize(),
127  error) == data_sp->GetByteSize())
128  return true;
129  }
130  }
131  return false;
132 }
133 
135  const lldb::DataBufferSP &data_sp) {
136  m_reg_data.SetData(data_sp);
137  SetAllRegisterValid(true);
138 }
RegisterContextMemory::GetRegisterSet
const lldb_private::RegisterSet * GetRegisterSet(size_t reg_set) override
Definition: RegisterContextMemory.cpp:66
lldb_private::DataExtractor::GetSharedDataBuffer
lldb::DataBufferSP & GetSharedDataBuffer()
Definition: DataExtractor.h:807
RegisterContextMemory::ReadAllRegisterValues
bool ReadAllRegisterValues(lldb::DataBufferSP &data_sp) override
Definition: RegisterContextMemory.cpp:102
lldb_private::RegisterValue
Definition: RegisterValue.h:28
lldb_private::RegisterContext::WriteRegisterValueToMemory
virtual Status WriteRegisterValueToMemory(const lldb_private::RegisterInfo *reg_info, lldb::addr_t dst_addr, uint32_t dst_len, const RegisterValue &reg_value)
Definition: RegisterContext.cpp:368
RegisterContextMemory.h
RegisterContextMemory::ConvertRegisterKindToRegisterNumber
uint32_t ConvertRegisterKindToRegisterNumber(lldb::RegisterKind kind, uint32_t num) override
Convert from a given register numbering scheme to the lldb register numbering scheme.
Definition: RegisterContextMemory.cpp:70
RegisterContextMemory::SetAllRegisterValid
void SetAllRegisterValid(bool b)
Definition: RegisterContextMemory.cpp:48
RegisterValue.h
RegisterContextMemory::SetAllRegisterData
void SetAllRegisterData(const lldb::DataBufferSP &data_sp)
Definition: RegisterContextMemory.cpp:134
RegisterContextMemory::ReadRegister
bool ReadRegister(const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &reg_value) override
Definition: RegisterContextMemory.cpp:75
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::DataExtractor::SetData
lldb::offset_t SetData(const void *bytes, lldb::offset_t length, lldb::ByteOrder byte_order)
Set data with a buffer that is caller owned.
Definition: DataExtractor.cpp:225
Process.h
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
lldb_private::Status::Success
bool Success() const
Test for success condition.
Definition: Status.cpp:288
lldb_private::RegisterContext::CalculateProcess
lldb::ProcessSP CalculateProcess() override
Definition: RegisterContext.cpp:431
lldb::eRegisterKindLLDB
@ eRegisterKindLLDB
lldb's internal register numbers
Definition: lldb-enumerations.h:234
lldb_private::DynamicRegisterInfo::GetNumRegisterSets
size_t GetNumRegisterSets() const
Definition: DynamicRegisterInfo.cpp:705
lldb_private::Thread
Definition: Thread.h:60
Thread.h
lldb_private::RegisterContext
Definition: RegisterContext.h:17
RegisterContextMemory::GetRegisterSetCount
size_t GetRegisterSetCount() override
Definition: RegisterContextMemory.cpp:62
lldb_private::DynamicRegisterInfo::GetRegisterInfoAtIndex
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(uint32_t i) const
Definition: DynamicRegisterInfo.cpp:712
lldb::RegisterKind
RegisterKind
Register numbering types.
Definition: lldb-enumerations.h:227
RegisterContextMemory::WriteRegister
bool WriteRegister(const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &reg_value) override
Definition: RegisterContextMemory.cpp:89
lldb_private::RegisterValue::SetValueFromData
Status SetValueFromData(const RegisterInfo *reg_info, DataExtractor &data, lldb::offset_t offset, bool partial_data_ok)
Definition: RegisterValue.cpp:172
lldb_private::Status
Definition: Status.h:44
uint32_t
RegisterContextMemory::m_reg_data
lldb_private::DataExtractor m_reg_data
Definition: RegisterContextMemory.h:64
RegisterContextMemory::InvalidateAllRegisters
void InvalidateAllRegisters() override
Definition: RegisterContextMemory.cpp:43
RegisterContextMemory::WriteAllRegisterValues
bool WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override
Definition: RegisterContextMemory.cpp:118
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:86
lldb_private::DynamicRegisterInfo::GetRegisterDataByteSize
size_t GetRegisterDataByteSize() const
Definition: DynamicRegisterInfo.cpp:707
RegisterContextMemory::GetRegisterCount
size_t GetRegisterCount() override
Definition: RegisterContextMemory.cpp:54
Status.h
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
RegisterContextMemory::RegisterContextMemory
RegisterContextMemory(lldb_private::Thread &thread, uint32_t concrete_frame_idx, lldb_private::DynamicRegisterInfo &reg_info, lldb::addr_t reg_data_addr)
Definition: RegisterContextMemory.cpp:21
RegisterContextMemory::~RegisterContextMemory
~RegisterContextMemory() override
lldb_private::DynamicRegisterInfo::GetNumRegisters
size_t GetNumRegisters() const
Definition: DynamicRegisterInfo.cpp:703
lldb_private::DynamicRegisterInfo
Definition: DynamicRegisterInfo.h:21
lldb_private::DataBufferHeap
Definition: DataBufferHeap.h:30
lldb
Definition: SBAddress.h:15
RegisterContextMemory::m_reg_valid
std::vector< bool > m_reg_valid
Definition: RegisterContextMemory.h:63
lldb_private::DynamicRegisterInfo::GetRegisterSet
const lldb_private::RegisterSet * GetRegisterSet(uint32_t i) const
Definition: DynamicRegisterInfo.cpp:726
DataBufferHeap.h
RegisterContextMemory::m_reg_data_addr
lldb::addr_t m_reg_data_addr
Definition: RegisterContextMemory.h:65
lldb_private::DynamicRegisterInfo::ConvertRegisterKindToRegisterNumber
uint32_t ConvertRegisterKindToRegisterNumber(uint32_t kind, uint32_t num) const
Definition: DynamicRegisterInfo.cpp:749
RegisterContextMemory::m_reg_infos
lldb_private::DynamicRegisterInfo & m_reg_infos
Definition: RegisterContextMemory.h:62
RegisterContextMemory::GetRegisterInfoAtIndex
const lldb_private::RegisterInfo * GetRegisterInfoAtIndex(size_t reg) override
Definition: RegisterContextMemory.cpp:58