LLDB mainline
NativeRegisterContextFreeBSD_arm.cpp
Go to the documentation of this file.
1//===-- NativeRegisterContextFreeBSD_arm.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
9#if defined(__arm__)
10
12
15#include "lldb/Utility/Status.h"
16
19
20// clang-format off
21#include <sys/param.h>
22#include <sys/ptrace.h>
23#include <sys/types.h>
24// clang-format on
25
26using namespace lldb;
27using namespace lldb_private;
28using namespace lldb_private::process_freebsd;
29
32 const ArchSpec &target_arch, NativeThreadFreeBSD &native_thread) {
33 return new NativeRegisterContextFreeBSD_arm(target_arch, native_thread);
34}
35
36NativeRegisterContextFreeBSD_arm::NativeRegisterContextFreeBSD_arm(
37 const ArchSpec &target_arch, NativeThreadFreeBSD &native_thread)
39 new RegisterInfo_arm(target_arch)) {}
40
41RegisterInfo_arm &NativeRegisterContextFreeBSD_arm::GetRegisterInfo() const {
42 return static_cast<RegisterInfo_arm &>(*m_register_info_interface_up);
43}
44
45uint32_t NativeRegisterContextFreeBSD_arm::GetRegisterSetCount() const {
46 return GetRegisterInfo().GetRegisterSetCount();
47}
48
49const RegisterSet *
50NativeRegisterContextFreeBSD_arm::GetRegisterSet(uint32_t set_index) const {
51 return GetRegisterInfo().GetRegisterSet(set_index);
52}
53
54uint32_t NativeRegisterContextFreeBSD_arm::GetUserRegisterCount() const {
55 uint32_t count = 0;
56 for (uint32_t set_index = 0; set_index < GetRegisterSetCount(); ++set_index)
57 count += GetRegisterSet(set_index)->num_registers;
58 return count;
59}
60
61Status NativeRegisterContextFreeBSD_arm::ReadRegisterSet(uint32_t set) {
62 switch (set) {
64 return NativeProcessFreeBSD::PtraceWrapper(PT_GETREGS, m_thread.GetID(),
65 m_reg_data.data());
68 PT_GETVFPREGS, m_thread.GetID(),
69 m_reg_data.data() + sizeof(RegisterInfo_arm::GPR));
70 }
71 llvm_unreachable("NativeRegisterContextFreeBSD_arm::ReadRegisterSet");
72}
73
74Status NativeRegisterContextFreeBSD_arm::WriteRegisterSet(uint32_t set) {
75 switch (set) {
77 return NativeProcessFreeBSD::PtraceWrapper(PT_SETREGS, m_thread.GetID(),
78 m_reg_data.data());
81 PT_SETVFPREGS, m_thread.GetID(),
82 m_reg_data.data() + sizeof(RegisterInfo_arm::GPR));
83 }
84 llvm_unreachable("NativeRegisterContextFreeBSD_arm::WriteRegisterSet");
85}
86
88NativeRegisterContextFreeBSD_arm::ReadRegister(const RegisterInfo *reg_info,
89 RegisterValue &reg_value) {
91
92 if (!reg_info) {
93 error = Status::FromErrorString("reg_info NULL");
94 return error;
95 }
96
97 const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
98
99 if (reg == LLDB_INVALID_REGNUM)
101 "no lldb regnum for %s",
102 reg_info && reg_info->name ? reg_info->name : "<unknown register>");
103
104 uint32_t set = GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg);
105 error = ReadRegisterSet(set);
106 if (error.Fail())
107 return error;
108
109 assert(reg_info->byte_offset + reg_info->byte_size <= m_reg_data.size());
110 reg_value.SetBytes(m_reg_data.data() + reg_info->byte_offset,
112 return error;
113}
114
115Status NativeRegisterContextFreeBSD_arm::WriteRegister(
116 const RegisterInfo *reg_info, const RegisterValue &reg_value) {
118
119 if (!reg_info)
120 return Status::FromErrorString("reg_info NULL");
121
122 const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];
123
124 if (reg == LLDB_INVALID_REGNUM)
126 "no lldb regnum for %s",
127 reg_info && reg_info->name ? reg_info->name : "<unknown register>");
128
129 uint32_t set = GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg);
130 error = ReadRegisterSet(set);
131 if (error.Fail())
132 return error;
133
134 assert(reg_info->byte_offset + reg_info->byte_size <= m_reg_data.size());
135 ::memcpy(m_reg_data.data() + reg_info->byte_offset, reg_value.GetBytes(),
136 reg_info->byte_size);
137
138 return WriteRegisterSet(set);
139}
140
141Status NativeRegisterContextFreeBSD_arm::ReadAllRegisterValues(
144
145 error = ReadRegisterSet(RegisterInfo_arm::GPRegSet);
146 if (error.Fail())
147 return error;
148
149 error = ReadRegisterSet(RegisterInfo_arm::FPRegSet);
150 if (error.Fail())
151 return error;
152
153 data_sp.reset(new DataBufferHeap(m_reg_data.size(), 0));
154 uint8_t *dst = data_sp->GetBytes();
155 ::memcpy(dst, m_reg_data.data(), m_reg_data.size());
156
157 return error;
158}
159
160Status NativeRegisterContextFreeBSD_arm::WriteAllRegisterValues(
161 const lldb::DataBufferSP &data_sp) {
163
164 if (!data_sp) {
166 "NativeRegisterContextFreeBSD_arm::%s invalid data_sp provided",
167 __FUNCTION__);
168 return error;
169 }
170
171 if (data_sp->GetByteSize() != m_reg_data.size()) {
173 "NativeRegisterContextFreeBSD_arm::%s data_sp contained mismatched "
174 "data size, expected %" PRIu64 ", actual %" PRIu64,
175 __FUNCTION__, m_reg_data.size(), data_sp->GetByteSize());
176 return error;
177 }
178
179 const uint8_t *src = data_sp->GetBytes();
180 if (src == nullptr) {
182 "NativeRegisterContextFreeBSD_arm::%s "
183 "DataBuffer::GetBytes() returned a null "
184 "pointer",
185 __FUNCTION__);
186 return error;
187 }
188 ::memcpy(m_reg_data.data(), src, m_reg_data.size());
189
190 error = WriteRegisterSet(RegisterInfo_arm::GPRegSet);
191 if (error.Fail())
192 return error;
193
194 return WriteRegisterSet(RegisterInfo_arm::FPRegSet);
195}
196
197llvm::Error NativeRegisterContextFreeBSD_arm::CopyHardwareWatchpointsFrom(
199 return llvm::Error::success();
200}
201
202#endif // defined (__arm__)
static llvm::raw_ostream & error(Stream &strm)
size_t GetRegisterSetCount() const override
An architecture specification class.
Definition ArchSpec.h:32
A subclass of DataBuffer that stores a data buffer on the heap.
void SetBytes(const void *bytes, size_t length, lldb::ByteOrder byte_order)
const void * GetBytes() const
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr=nullptr, int data=0, int *result=nullptr)
static NativeRegisterContextFreeBSD * CreateHostNativeRegisterContextFreeBSD(const ArchSpec &target_arch, NativeThreadFreeBSD &native_thread)
#define LLDB_INVALID_REGNUM
lldb::ByteOrder InlHostByteOrder()
Definition Endian.h:25
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
std::shared_ptr< lldb_private::WritableDataBuffer > WritableDataBufferSP
@ 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.
const char * name
Name of this register, can't be NULL.
Registers are grouped into register sets.
size_t num_registers
The number of registers in REGISTERS array below.