Skip to content

[lldb][AArch64] Fix arm64 hardware breakpoint/watchpoint to arm32 process. #147198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@
#include <elf.h>
#include <sys/uio.h>

#if defined(__arm64__) || defined(__aarch64__)
#include "lldb/Host/linux/Ptrace.h"
#include <asm/ptrace.h>
#endif

#define REG_CONTEXT_SIZE (GetGPRSize() + sizeof(m_fpr))

#ifndef PTRACE_GETVFPREGS
#define PTRACE_GETVFPREGS 27
#define PTRACE_SETVFPREGS 28
#endif
#ifndef PTRACE_GETHBPREGS
#if defined(__arm__) && !defined(PTRACE_GETHBPREGS)
#define PTRACE_GETHBPREGS 29
#define PTRACE_SETHBPREGS 30
#endif
Expand Down Expand Up @@ -723,6 +728,7 @@ Status NativeRegisterContextLinux_arm::ReadHardwareDebugInfo() {
return Status();
}

#ifdef __arm__
unsigned int cap_val;

error = NativeProcessLinux::PtraceWrapper(PTRACE_GETHBPREGS, m_thread.GetID(),
Expand All @@ -737,12 +743,43 @@ Status NativeRegisterContextLinux_arm::ReadHardwareDebugInfo() {
m_refresh_hwdebug_info = false;

return error;
#else // __aarch64__
::pid_t tid = m_thread.GetID();

int regset = NT_ARM_HW_WATCH;
struct iovec ioVec;
struct user_hwdebug_state dreg_state;

ioVec.iov_base = &dreg_state;
ioVec.iov_len = sizeof(dreg_state);

error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, &regset,
&ioVec, ioVec.iov_len);

if (error.Fail())
return error;

m_max_hwp_supported = dreg_state.dbg_info & 0xff;

regset = NT_ARM_HW_BREAK;
error = NativeProcessLinux::PtraceWrapper(PTRACE_GETREGSET, tid, &regset,
&ioVec, ioVec.iov_len);

if (error.Fail())
return error;

m_max_hbp_supported = dreg_state.dbg_info & 0xff;
m_refresh_hwdebug_info = false;

return error;
#endif // __arm__
}

Status NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(int hwbType,
Status NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(DREGType hwbType,
int hwb_index) {
Status error;

#ifdef __arm__
lldb::addr_t *addr_buf;
uint32_t *ctrl_buf;

Expand Down Expand Up @@ -781,6 +818,40 @@ Status NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(int hwbType,
}

return error;
#else // __aarch64__
struct iovec ioVec;
struct user_hwdebug_state dreg_state;
int regset;

memset(&dreg_state, 0, sizeof(dreg_state));
ioVec.iov_base = &dreg_state;

switch (hwbType) {
case eDREGTypeWATCH:
regset = NT_ARM_HW_WATCH;
ioVec.iov_len = sizeof(dreg_state.dbg_info) + sizeof(dreg_state.pad) +
(sizeof(dreg_state.dbg_regs[0]) * m_max_hwp_supported);

for (uint32_t i = 0; i < m_max_hwp_supported; i++) {
dreg_state.dbg_regs[i].addr = m_hwp_regs[i].address;
dreg_state.dbg_regs[i].ctrl = m_hwp_regs[i].control;
}
break;
case eDREGTypeBREAK:
regset = NT_ARM_HW_BREAK;
ioVec.iov_len = sizeof(dreg_state.dbg_info) + sizeof(dreg_state.pad) +
(sizeof(dreg_state.dbg_regs[0]) * m_max_hbp_supported);

for (uint32_t i = 0; i < m_max_hbp_supported; i++) {
dreg_state.dbg_regs[i].addr = m_hbr_regs[i].address;
dreg_state.dbg_regs[i].ctrl = m_hbr_regs[i].control;
}
break;
}

return NativeProcessLinux::PtraceWrapper(PTRACE_SETREGSET, m_thread.GetID(),
&regset, &ioVec, ioVec.iov_len);
#endif // __arm__
}

uint32_t NativeRegisterContextLinux_arm::CalculateFprOffset(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class NativeRegisterContextLinux_arm : public NativeRegisterContextLinux {

Status ReadHardwareDebugInfo();

Status WriteHardwareDebugRegs(int hwbType, int hwb_index);
Status WriteHardwareDebugRegs(DREGType hwbType, int hwb_index);

uint32_t CalculateFprOffset(const RegisterInfo *reg_info) const;

Expand Down
Loading