Skip to content

Commit 7f23aae

Browse files
committed
[LLDB][LoongArch] Extend the maximum number of watchpoints
The maximum number of load/store watchpoints and fetch instruction watchpoints is 14 each according to LoongArch Reference Manual [1], so extend the maximum number of watchpoints from 8 to 14 for ptrace. A new struct user_watch_state_v2 was added into uapi in the related kernel commit 531936dee53e ("LoongArch: Extend the maximum number of watchpoints") [2], but there may be no struct user_watch_state_v2 in the system header in time. In order to avoid undefined or redefined error, just add a new struct loongarch_user_watch_state in LLDB which is same with the uapi struct user_watch_state_v2, then replace the current user_watch_state with loongarch_user_watch_state. As far as I can tell, the only users for this struct in the userspace are GDB and LLDB, there are no any problems of software compatibility between the application and kernel according to the analysis. The compatibility problem has been considered while developing and testing. When the applications in the userspace get watchpoint state, the length will be specified which is no bigger than the sizeof struct user_watch_state or user_watch_state_v2, the actual length is assigned as the minimal value of the application and kernel in the generic code of ptrace: ``` kernel/ptrace.c: ptrace_regset(): kiov->iov_len = min(kiov->iov_len, (__kernel_size_t) (regset->n * regset->size)); if (req == PTRACE_GETREGSET) return copy_regset_to_user(task, view, regset_no, 0, kiov->iov_len, kiov->iov_base); else return copy_regset_from_user(task, view, regset_no, 0, kiov->iov_len, kiov->iov_base); ``` For example, there are four kind of combinations, all of them work well. (1) "older kernel + older app", the actual length is 8+(8+8+4+4)*8=200; (2) "newer kernel + newer app", the actual length is 8+(8+8+4+4)*14=344; (3) "older kernel + newer app", the actual length is 8+(8+8+4+4)*8=200; (4) "newer kernel + older app", the actual length is 8+(8+8+4+4)*8=200. [1] https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#control-and-status-registers-related-to-watchpoints [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=531936dee53e Signed-off-by: Tiezhu Yang <[email protected]>
1 parent 83783e8 commit 7f23aae

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@
5050
#define REG_CONTEXT_SIZE \
5151
(GetGPRSize() + GetFPRSize() + sizeof(m_lsx) + sizeof(m_lasx))
5252

53+
// In order to avoid undefined or redefined error, just add a new struct
54+
// loongarch_user_watch_state in LLDB which is same with the uapi struct
55+
// user_watch_state_v2.
56+
struct loongarch_user_watch_state {
57+
uint64_t dbg_info;
58+
struct {
59+
uint64_t addr;
60+
uint64_t mask;
61+
uint32_t ctrl;
62+
uint32_t pad;
63+
} dbg_regs[14];
64+
};
65+
5366
using namespace lldb;
5467
using namespace lldb_private;
5568
using namespace lldb_private::process_linux;
@@ -539,7 +552,7 @@ llvm::Error NativeRegisterContextLinux_loongarch64::ReadHardwareDebugInfo() {
539552

540553
int regset = NT_LOONGARCH_HW_WATCH;
541554
struct iovec ioVec;
542-
struct user_watch_state dreg_state;
555+
struct loongarch_user_watch_state dreg_state;
543556
Status error;
544557

545558
ioVec.iov_base = &dreg_state;
@@ -567,7 +580,7 @@ llvm::Error NativeRegisterContextLinux_loongarch64::ReadHardwareDebugInfo() {
567580
llvm::Error NativeRegisterContextLinux_loongarch64::WriteHardwareDebugRegs(
568581
DREGType hwbType) {
569582
struct iovec ioVec;
570-
struct user_watch_state dreg_state;
583+
struct loongarch_user_watch_state dreg_state;
571584
int regset;
572585

573586
memset(&dreg_state, 0, sizeof(dreg_state));

0 commit comments

Comments
 (0)