LLDB mainline
NativeRegisterContextLinux_arm64dbreg.cpp
Go to the documentation of this file.
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9#if defined(__arm64__) || defined(__aarch64__)
10
13
14#include <asm/ptrace.h>
15// System includes - They have to be included after framework includes because
16// they define some macros which collide with variable names in other modules
17#include <sys/uio.h>
18// NT_PRSTATUS and NT_FPREGSET definition
19#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;
30
31 ioVec.iov_base = &dreg_state;
32 ioVec.iov_len = sizeof(dreg_state);
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
44 ::pid_t tid, uint32_t &max_hwp_supported, uint32_t &max_hbp_supported) {
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
55 int hwbType, ::pid_t tid, uint32_t max_supported,
56 const std::array<NativeRegisterContextDBReg::DREG, 16> &regs) {
57 int regset = hwbType == NativeRegisterContextDBReg::eDREGTypeWATCH
58 ? NT_ARM_HW_WATCH
59 : 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
74 &ioVec, ioVec.iov_len);
75}
76
77#endif // defined (__arm64__) || defined (__aarch64__)
static llvm::raw_ostream & error(Stream &strm)
#define PTRACE_SETREGSET
Definition Ptrace.h:39
#define PTRACE_GETREGSET
Definition Ptrace.h:36
static Status PtraceWrapper(int req, lldb::pid_t pid, void *addr=nullptr, void *data=nullptr, size_t data_size=0, long *result=nullptr)
}
Status WriteHardwareDebugRegs(int hwbType, ::pid_t tid, uint32_t max_supported, const std::array< NativeRegisterContextDBReg::DREG, 16 > &regs)
Status ReadHardwareDebugInfo(::pid_t tid, uint32_t &max_hwp_supported, uint32_t &max_hbp_supported)
A class that represents a running process on the host machine.
uint64_t pid_t
Definition lldb-types.h:83