mirror of
https://github.com/bminor/binutils-gdb.git
synced 2025-12-27 01:28:46 +00:00
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 <lihui@loongson.cn>
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
117 lines
3.8 KiB
C
117 lines
3.8 KiB
C
/* Native-dependent code for GNU/Linux on LoongArch processors.
|
|
|
|
Copyright (C) 2024 Free Software Foundation, Inc.
|
|
Contributed by Loongson Ltd.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef GDB_NAT_LOONGARCH_LINUX_HW_POINT_H
|
|
#define GDB_NAT_LOONGARCH_LINUX_HW_POINT_H
|
|
|
|
#include "gdbsupport/break-common.h" /* For enum target_hw_bp_type. */
|
|
|
|
#include "nat/loongarch-hw-point.h"
|
|
|
|
struct loongarch_user_watch_state {
|
|
uint64_t dbg_info;
|
|
struct {
|
|
uint64_t addr;
|
|
uint64_t mask;
|
|
uint32_t ctrl;
|
|
uint32_t pad;
|
|
} dbg_regs[14];
|
|
};
|
|
|
|
|
|
/* Macros to extract fields from the hardware debug information word. */
|
|
#define LOONGARCH_DEBUG_NUM_SLOTS(x) ((x) & 0xffff)
|
|
|
|
/* Each bit of a variable of this type is used to indicate whether a
|
|
hardware breakpoint or watchpoint setting has been changed since
|
|
the last update.
|
|
|
|
Bit N corresponds to the Nth hardware breakpoint or watchpoint
|
|
setting which is managed in loongarch_debug_reg_state, where N is
|
|
valid between 0 and the total number of the hardware breakpoint or
|
|
watchpoint debug registers minus 1.
|
|
|
|
When bit N is 1, the corresponding breakpoint or watchpoint setting
|
|
has changed, and therefore the corresponding hardware debug
|
|
register needs to be updated via the ptrace interface.
|
|
|
|
In the per-thread arch-specific data area, we define two such
|
|
variables for per-thread hardware breakpoint and watchpoint
|
|
settings respectively.
|
|
|
|
This type is part of the mechanism which helps reduce the number of
|
|
ptrace calls to the kernel, i.e. avoid asking the kernel to write
|
|
to the debug registers with unchanged values. */
|
|
|
|
typedef ULONGEST dr_changed_t;
|
|
|
|
/* Set each of the lower M bits of X to 1; assert X is wide enough. */
|
|
|
|
#define DR_MARK_ALL_CHANGED(x, m) \
|
|
do \
|
|
{ \
|
|
gdb_assert (sizeof ((x)) * 8 >= (m)); \
|
|
(x) = (((dr_changed_t)1 << (m)) - 1); \
|
|
} while (0)
|
|
|
|
#define DR_MARK_N_CHANGED(x, n) \
|
|
do \
|
|
{ \
|
|
(x) |= ((dr_changed_t)1 << (n)); \
|
|
} while (0)
|
|
|
|
#define DR_CLEAR_CHANGED(x) \
|
|
do \
|
|
{ \
|
|
(x) = 0; \
|
|
} while (0)
|
|
|
|
#define DR_HAS_CHANGED(x) ((x) != 0)
|
|
#define DR_N_HAS_CHANGED(x, n) ((x) & ((dr_changed_t)1 << (n)))
|
|
|
|
/* Per-thread arch-specific data we want to keep. */
|
|
|
|
struct arch_lwp_info
|
|
{
|
|
/* When bit N is 1, it indicates the Nth hardware breakpoint or
|
|
watchpoint register pair needs to be updated when the thread is
|
|
resumed; see loongarch_linux_prepare_to_resume. */
|
|
dr_changed_t dr_changed_bp;
|
|
dr_changed_t dr_changed_wp;
|
|
};
|
|
|
|
/* Call ptrace to set the thread TID's hardware breakpoint/watchpoint
|
|
registers with data from *STATE. */
|
|
|
|
void loongarch_linux_set_debug_regs (struct loongarch_debug_reg_state *state,
|
|
int tid, int watchpoint);
|
|
|
|
/* Get the hardware debug register capacity information from the
|
|
process represented by TID. */
|
|
|
|
void loongarch_linux_get_debug_reg_capacity (int tid);
|
|
|
|
/* Return the debug register state for process PID. If no existing
|
|
state is found for this process, create new state. */
|
|
|
|
struct loongarch_debug_reg_state *loongarch_get_debug_reg_state (pid_t pid);
|
|
|
|
#endif /* GDB_NAT_LOONGARCH_LINUX_HW_POINT_H */
|