Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Process/FreeBSD/NativeRegisterContextFreeBSD_arm.cpp
96379 views
//===-- NativeRegisterContextFreeBSD_arm.cpp ------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#if defined(__arm__)910#include "NativeRegisterContextFreeBSD_arm.h"1112#include "lldb/Utility/DataBufferHeap.h"13#include "lldb/Utility/RegisterValue.h"14#include "lldb/Utility/Status.h"1516#include "Plugins/Process/FreeBSD/NativeProcessFreeBSD.h"17#include "Plugins/Process/Utility/RegisterInfoPOSIX_arm.h"1819// clang-format off20#include <sys/param.h>21#include <sys/ptrace.h>22#include <sys/types.h>23// clang-format on2425using namespace lldb;26using namespace lldb_private;27using namespace lldb_private::process_freebsd;2829NativeRegisterContextFreeBSD *30NativeRegisterContextFreeBSD::CreateHostNativeRegisterContextFreeBSD(31const ArchSpec &target_arch, NativeThreadFreeBSD &native_thread) {32return new NativeRegisterContextFreeBSD_arm(target_arch, native_thread);33}3435NativeRegisterContextFreeBSD_arm::NativeRegisterContextFreeBSD_arm(36const ArchSpec &target_arch, NativeThreadFreeBSD &native_thread)37: NativeRegisterContextRegisterInfo(38native_thread, new RegisterInfoPOSIX_arm(target_arch)) {}3940RegisterInfoPOSIX_arm &41NativeRegisterContextFreeBSD_arm::GetRegisterInfo() const {42return static_cast<RegisterInfoPOSIX_arm &>(*m_register_info_interface_up);43}4445uint32_t NativeRegisterContextFreeBSD_arm::GetRegisterSetCount() const {46return GetRegisterInfo().GetRegisterSetCount();47}4849const RegisterSet *50NativeRegisterContextFreeBSD_arm::GetRegisterSet(uint32_t set_index) const {51return GetRegisterInfo().GetRegisterSet(set_index);52}5354uint32_t NativeRegisterContextFreeBSD_arm::GetUserRegisterCount() const {55uint32_t count = 0;56for (uint32_t set_index = 0; set_index < GetRegisterSetCount(); ++set_index)57count += GetRegisterSet(set_index)->num_registers;58return count;59}6061Status NativeRegisterContextFreeBSD_arm::ReadRegisterSet(uint32_t set) {62switch (set) {63case RegisterInfoPOSIX_arm::GPRegSet:64return NativeProcessFreeBSD::PtraceWrapper(PT_GETREGS, m_thread.GetID(),65m_reg_data.data());66case RegisterInfoPOSIX_arm::FPRegSet:67return NativeProcessFreeBSD::PtraceWrapper(68PT_GETVFPREGS, m_thread.GetID(),69m_reg_data.data() + sizeof(RegisterInfoPOSIX_arm::GPR));70}71llvm_unreachable("NativeRegisterContextFreeBSD_arm::ReadRegisterSet");72}7374Status NativeRegisterContextFreeBSD_arm::WriteRegisterSet(uint32_t set) {75switch (set) {76case RegisterInfoPOSIX_arm::GPRegSet:77return NativeProcessFreeBSD::PtraceWrapper(PT_SETREGS, m_thread.GetID(),78m_reg_data.data());79case RegisterInfoPOSIX_arm::FPRegSet:80return NativeProcessFreeBSD::PtraceWrapper(81PT_SETVFPREGS, m_thread.GetID(),82m_reg_data.data() + sizeof(RegisterInfoPOSIX_arm::GPR));83}84llvm_unreachable("NativeRegisterContextFreeBSD_arm::WriteRegisterSet");85}8687Status88NativeRegisterContextFreeBSD_arm::ReadRegister(const RegisterInfo *reg_info,89RegisterValue ®_value) {90Status error;9192if (!reg_info) {93error.SetErrorString("reg_info NULL");94return error;95}9697const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];9899if (reg == LLDB_INVALID_REGNUM)100return Status("no lldb regnum for %s", reg_info && reg_info->name101? reg_info->name102: "<unknown register>");103104uint32_t set = GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg);105error = ReadRegisterSet(set);106if (error.Fail())107return error;108109assert(reg_info->byte_offset + reg_info->byte_size <= m_reg_data.size());110reg_value.SetBytes(m_reg_data.data() + reg_info->byte_offset,111reg_info->byte_size, endian::InlHostByteOrder());112return error;113}114115Status NativeRegisterContextFreeBSD_arm::WriteRegister(116const RegisterInfo *reg_info, const RegisterValue ®_value) {117Status error;118119if (!reg_info)120return Status("reg_info NULL");121122const uint32_t reg = reg_info->kinds[lldb::eRegisterKindLLDB];123124if (reg == LLDB_INVALID_REGNUM)125return Status("no lldb regnum for %s", reg_info && reg_info->name126? reg_info->name127: "<unknown register>");128129uint32_t set = GetRegisterInfo().GetRegisterSetFromRegisterIndex(reg);130error = ReadRegisterSet(set);131if (error.Fail())132return error;133134assert(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(),136reg_info->byte_size);137138return WriteRegisterSet(set);139}140141Status NativeRegisterContextFreeBSD_arm::ReadAllRegisterValues(142lldb::WritableDataBufferSP &data_sp) {143Status error;144145error = ReadRegisterSet(RegisterInfoPOSIX_arm::GPRegSet);146if (error.Fail())147return error;148149error = ReadRegisterSet(RegisterInfoPOSIX_arm::FPRegSet);150if (error.Fail())151return error;152153data_sp.reset(new DataBufferHeap(m_reg_data.size(), 0));154uint8_t *dst = data_sp->GetBytes();155::memcpy(dst, m_reg_data.data(), m_reg_data.size());156157return error;158}159160Status NativeRegisterContextFreeBSD_arm::WriteAllRegisterValues(161const lldb::DataBufferSP &data_sp) {162Status error;163164if (!data_sp) {165error.SetErrorStringWithFormat(166"NativeRegisterContextFreeBSD_arm::%s invalid data_sp provided",167__FUNCTION__);168return error;169}170171if (data_sp->GetByteSize() != m_reg_data.size()) {172error.SetErrorStringWithFormat(173"NativeRegisterContextFreeBSD_arm::%s data_sp contained mismatched "174"data size, expected %" PRIu64 ", actual %" PRIu64,175__FUNCTION__, m_reg_data.size(), data_sp->GetByteSize());176return error;177}178179const uint8_t *src = data_sp->GetBytes();180if (src == nullptr) {181error.SetErrorStringWithFormat("NativeRegisterContextFreeBSD_arm::%s "182"DataBuffer::GetBytes() returned a null "183"pointer",184__FUNCTION__);185return error;186}187::memcpy(m_reg_data.data(), src, m_reg_data.size());188189error = WriteRegisterSet(RegisterInfoPOSIX_arm::GPRegSet);190if (error.Fail())191return error;192193return WriteRegisterSet(RegisterInfoPOSIX_arm::FPRegSet);194}195196llvm::Error NativeRegisterContextFreeBSD_arm::CopyHardwareWatchpointsFrom(197NativeRegisterContextFreeBSD &source) {198return llvm::Error::success();199}200201#endif // defined (__arm__)202203204