From: Hui Li Date: Tue, 11 Feb 2025 12:18:28 +0000 (+0800) Subject: gdb: LoongArch: Extend the maximum number of hardware watchpoints X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=405836704bd4ce297194e12cfe11a08fe89d03f9;p=thirdparty%2Fbinutils-gdb.git gdb: LoongArch: Extend the maximum number of hardware 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 hardware watchpoints from 8 to 14. 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. Modify the struct loongarch_user_watch_state in GDB which is same with the uapi struct user_watch_state_v2. 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. BTW, LLDB also made this change in the related commit ff79d83caeee ("[LLDB][LoongArch] Extend the maximum number of watchpoints") [3] [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 [3] https://github.com/llvm/llvm-project/commit/ff79d83caeee Signed-off-by: Hui Li Signed-off-by: Tiezhu Yang --- diff --git a/gdb/nat/loongarch-hw-point.h b/gdb/nat/loongarch-hw-point.h index 3098752043a..3d3d2c1f4e5 100644 --- a/gdb/nat/loongarch-hw-point.h +++ b/gdb/nat/loongarch-hw-point.h @@ -33,8 +33,8 @@ Neither of these values may exceed the width of dr_changed_t measured in bits. */ -#define LOONGARCH_HBP_MAX_NUM 8 -#define LOONGARCH_HWP_MAX_NUM 8 +#define LOONGARCH_HBP_MAX_NUM 14 +#define LOONGARCH_HWP_MAX_NUM 14 /* The maximum length of a memory region that can be watched by one diff --git a/gdb/nat/loongarch-linux-hw-point.h b/gdb/nat/loongarch-linux-hw-point.h index 3efc9a7381f..d8b8feb638d 100644 --- a/gdb/nat/loongarch-linux-hw-point.h +++ b/gdb/nat/loongarch-linux-hw-point.h @@ -32,7 +32,7 @@ struct loongarch_user_watch_state { uint64_t mask; uint32_t ctrl; uint32_t pad; - } dbg_regs[8]; + } dbg_regs[14]; };