Skip to content

Commit 6246600

Browse files
committed
refactor write registers
1 parent b1a421f commit 6246600

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.cpp

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -333,55 +333,40 @@ NativeRegisterContextLinux_arm::WriteHardwareDebugRegs(DREGType hwbType) {
333333
#endif // ifdef __arm__
334334
}
335335

336+
#ifdef __arm__
336337
llvm::Error
337338
NativeRegisterContextLinux_arm::WriteHardwareDebugReg(DREGType hwbType,
338339
int hwb_index) {
339340
Status error;
340341
lldb::addr_t *addr_buf;
341342
uint32_t *ctrl_buf;
343+
int addr_idx = (hwb_index << 1) + 1;
344+
int ctrl_idx = addr_idx + 1;
342345

343346
if (hwbType == NativeRegisterContextDBReg::eDREGTypeWATCH) {
347+
addr_idx *= -1;
344348
addr_buf = &m_hwp_regs[hwb_index].address;
349+
ctrl_idx *= -1;
345350
ctrl_buf = &m_hwp_regs[hwb_index].control;
346-
347-
error = NativeProcessLinux::PtraceWrapper(
348-
PTRACE_SETHBPREGS, m_thread.GetID(),
349-
(PTRACE_TYPE_ARG3)(intptr_t) - ((hwb_index << 1) + 1), addr_buf,
350-
sizeof(unsigned int));
351-
352-
if (error.Fail())
353-
return error.ToError();
354-
355-
error = NativeProcessLinux::PtraceWrapper(
356-
PTRACE_SETHBPREGS, m_thread.GetID(),
357-
(PTRACE_TYPE_ARG3)(intptr_t) - ((hwb_index << 1) + 2), ctrl_buf,
358-
sizeof(unsigned int));
359-
360-
if (error.Fail())
361-
return error.ToError();
362351
} else {
363352
addr_buf = &m_hbp_regs[hwb_index].address;
364353
ctrl_buf = &m_hbp_regs[hwb_index].control;
354+
}
365355

366-
error = NativeProcessLinux::PtraceWrapper(
367-
PTRACE_SETHBPREGS, m_thread.GetID(),
368-
(PTRACE_TYPE_ARG3)(intptr_t)((hwb_index << 1) + 1), addr_buf,
369-
sizeof(unsigned int));
370-
371-
if (error.Fail())
372-
return error.ToError();
356+
error = NativeProcessLinux::PtraceWrapper(
357+
PTRACE_SETHBPREGS, m_thread.GetID(), (PTRACE_TYPE_ARG3)(intptr_t)addr_idx,
358+
addr_buf, sizeof(unsigned int));
373359

374-
error = NativeProcessLinux::PtraceWrapper(
375-
PTRACE_SETHBPREGS, m_thread.GetID(),
376-
(PTRACE_TYPE_ARG3)(intptr_t)((hwb_index << 1) + 2), ctrl_buf,
377-
sizeof(unsigned int));
360+
if (error.Fail())
361+
return error.ToError();
378362

379-
if (error.Fail())
380-
return error.ToError();
381-
}
363+
error = NativeProcessLinux::PtraceWrapper(
364+
PTRACE_SETHBPREGS, m_thread.GetID(), (PTRACE_TYPE_ARG3)(intptr_t)ctrl_idx,
365+
ctrl_buf, sizeof(unsigned int));
382366

383367
return error.ToError();
384368
}
369+
#endif // ifdef __arm__
385370

386371
uint32_t NativeRegisterContextLinux_arm::CalculateFprOffset(
387372
const RegisterInfo *reg_info) const {

lldb/source/Plugins/Process/Linux/NativeRegisterContextLinux_arm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class NativeRegisterContextLinux_arm : public NativeRegisterContextLinux,
7777
llvm::Error ReadHardwareDebugInfo() override;
7878

7979
llvm::Error WriteHardwareDebugRegs(DREGType hwbType) override;
80-
llvm::Error WriteHardwareDebugReg(DREGType hwbType, int hwb_index) override;
80+
#ifdef __arm__
81+
llvm::Error WriteHardwareDebugReg(DREGType hwbType, int hwb_index);
82+
#endif
8183

8284
uint32_t CalculateFprOffset(const RegisterInfo *reg_info) const;
8385

lldb/source/Plugins/Process/Utility/NativeRegisterContextDBReg_arm.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ class NativeRegisterContextDBReg_arm : public NativeRegisterContextDBReg {
3636
// Break on 4 or 2 byte instructions.
3737
return size == 4 || size == 2;
3838
}
39-
40-
virtual llvm::Error WriteHardwareDebugReg(DREGType hwbType,
41-
int hwb_index) = 0;
4239
};
4340

4441
} // namespace lldb_private

0 commit comments

Comments
 (0)