78 lines · cpp
1//===-- NativeRegisterContextLinux_arm64dbreg.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-exception6//7//===----------------------------------------------------------------------===//8 9#if defined(__arm64__) || defined(__aarch64__)10 11#include "NativeRegisterContextLinux_arm64dbreg.h"12#include "lldb/Host/linux/Ptrace.h"13 14#include <asm/ptrace.h>15// System includes - They have to be included after framework includes because16// they define some macros which collide with variable names in other modules17#include <sys/uio.h>18// NT_PRSTATUS and NT_FPREGSET definition19#include <elf.h>20 21using namespace lldb;22using namespace lldb_private;23using namespace lldb_private::process_linux;24 25static Status ReadHardwareDebugInfoHelper(int regset, ::pid_t tid,26 uint32_t &max_supported) {27 struct iovec ioVec;28 struct user_hwdebug_state dreg_state;29 Status error;30 31 ioVec.iov_base = &dreg_state;32 ioVec.iov_len = sizeof(dreg_state);33 error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, ®set,34 &ioVec, ioVec.iov_len);35 36 if (error.Fail())37 return error;38 39 max_supported = dreg_state.dbg_info & 0xff;40 return error;41}42 43Status lldb_private::process_linux::arm64::ReadHardwareDebugInfo(44 ::pid_t tid, uint32_t &max_hwp_supported, uint32_t &max_hbp_supported) {45 Status error =46 ReadHardwareDebugInfoHelper(NT_ARM_HW_WATCH, tid, max_hwp_supported);47 48 if (error.Fail())49 return error;50 51 return ReadHardwareDebugInfoHelper(NT_ARM_HW_BREAK, tid, max_hbp_supported);52}53 54Status lldb_private::process_linux::arm64::WriteHardwareDebugRegs(55 int hwbType, ::pid_t tid, uint32_t max_supported,56 const std::array<NativeRegisterContextDBReg::DREG, 16> ®s) {57 int regset = hwbType == NativeRegisterContextDBReg::eDREGTypeWATCH58 ? NT_ARM_HW_WATCH59 : NT_ARM_HW_BREAK;60 61 struct user_hwdebug_state dreg_state;62 memset(&dreg_state, 0, sizeof(dreg_state));63 for (uint32_t i = 0; i < max_supported; i++) {64 dreg_state.dbg_regs[i].addr = regs[i].address;65 dreg_state.dbg_regs[i].ctrl = regs[i].control;66 }67 68 struct iovec ioVec;69 ioVec.iov_base = &dreg_state;70 ioVec.iov_len = sizeof(dreg_state.dbg_info) + sizeof(dreg_state.pad) +71 (sizeof(dreg_state.dbg_regs[0]) * max_supported);72 73 return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, tid, ®set,74 &ioVec, ioVec.iov_len);75}76 77#endif // defined (__arm64__) || defined (__aarch64__)78