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
12
13// System includes - They have to be included after framework includes because
14// they define some macros which collide with variable names in other modules.
15#include <asm/ptrace.h>
16#include <elf.h>
17#include <sys/ptrace.h>
18#include <sys/uio.h>
19
20#ifndef PTRACE_GETREGSET
21#define PTRACE_GETREGSET 0x4204
22#endif
23
24#ifndef PTRACE_SETREGSET
25#define PTRACE_SETREGSET 0x4205
26#endif
27
28using namespace lldb;
29using namespace lldb_private;
30using namespace lldb_private::process_linux;
31
32static Status ReadHardwareDebugInfoHelper(int regset, ::pid_t tid,
33 uint32_t &max_supported) {
34 struct iovec ioVec;
35 struct user_hwdebug_state dreg_state;
37
38 ioVec.iov_base = &dreg_state;
39 ioVec.iov_len = sizeof(dreg_state);
41 &ioVec, ioVec.iov_len);
42
43 if (error.Fail())
44 return error;
45
46 max_supported = dreg_state.dbg_info & 0xff;
47 return error;
48}
49
51 ::pid_t tid, uint32_t &max_hwp_supported, uint32_t &max_hbp_supported) {
53 ReadHardwareDebugInfoHelper(NT_ARM_HW_WATCH, tid, max_hwp_supported);
54
55 if (error.Fail())
56 return error;
57
58 return ReadHardwareDebugInfoHelper(NT_ARM_HW_BREAK, tid, max_hbp_supported);
59}
60
62 int hwbType, ::pid_t tid, uint32_t max_supported,
63 const std::array<NativeRegisterContextDBReg::DREG, 16> &regs) {
64 int regset = hwbType == NativeRegisterContextDBReg::eDREGTypeWATCH
65 ? NT_ARM_HW_WATCH
66 : NT_ARM_HW_BREAK;
67
68 struct user_hwdebug_state dreg_state;
69 memset(&dreg_state, 0, sizeof(dreg_state));
70 for (uint32_t i = 0; i < max_supported; i++) {
71 dreg_state.dbg_regs[i].addr = regs[i].address;
72 dreg_state.dbg_regs[i].ctrl = regs[i].control;
73 }
74
75 struct iovec ioVec;
76 ioVec.iov_base = &dreg_state;
77 ioVec.iov_len = sizeof(dreg_state.dbg_info) + sizeof(dreg_state.pad) +
78 (sizeof(dreg_state.dbg_regs[0]) * max_supported);
79
81 &ioVec, ioVec.iov_len);
82}
83
84#endif // defined (__arm64__) || defined (__aarch64__)
static llvm::raw_ostream & error(Stream &strm)
#define PTRACE_SETREGSET
#define PTRACE_GETREGSET
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:84