39edd165f4
Nowadays, if user requests HW watchpoint to monitor a large memory area or unaligned area, aarch64 GDB will split into multiple aligned areas, and use multiple debugging registers to watch them. However, the registers are not updated in a transaction way. GDBserver doesn't revert updates in previous iterations if some debugging registers fail to update due to some reason, like no free debugging registers available, in the latter iteration. For example, if we have a char buf[34], and watch buf in gdb, (gdb) watch buf Hardware watchpoint 2: buf (gdb) c Continuing. infrun: clear_proceed_status_thread (Thread 13466) infrun: proceed (addr=0xffffffffffffffff, signal=GDB_SIGNAL_DEFAULT) infrun: step-over queue now empty infrun: resuming [Thread 13466] for step-over Sending packet: $m410838,22#35...Packet received: 00000000000000000000000000000000000000000000000000000000000000000000 infrun: skipping breakpoint: stepping past insn at: 0x400524 infrun: skipping breakpoint: stepping past insn at: 0x400524 Sending packet: $Z2,410838,22#80...Packet received: E01 <----- [1] Packet Z2 (write-watchpoint) is supported Sending packet: $Z0,7fb7fe0a8c,4#43...Packet received: OK Warning: Could not insert hardware watchpoint 2. Could not insert hardware breakpoints: You may have requested too many hardware breakpoints/watchpoints. GDB receives E01 for Z2 packet [1] but GDBserver updates the debugging register status, insert_point (addr=0x00410838, len=34, type=hw-write-watchpoint): BREAKPOINTs: BP0: addr=0x0, ctrl=0x00000000, ref.count=0 BP1: addr=0x0, ctrl=0x00000000, ref.count=0 BP2: addr=0x0, ctrl=0x00000000, ref.count=0 BP3: addr=0x0, ctrl=0x00000000, ref.count=0 BP4: addr=0x0, ctrl=0x00000000, ref.count=0 BP5: addr=0x0, ctrl=0x00000000, ref.count=0 WATCHPOINTs: WP0: addr=0x410850, ctrl=0x00001ff5, ref.count=1 WP1: addr=0x410848, ctrl=0x00001ff5, ref.count=1 WP2: addr=0x410840, ctrl=0x00001ff5, ref.count=1 WP3: addr=0x410838, ctrl=0x00001ff5, ref.count=1 four debugging registers can not monitor 34-byte long area, so the last iteration of updating debugging register state fails but previous iterations succeed. This makes GDB think no HW watchpoint is inserted but some debugging registers are used. This problem was exposed by "watch buf" gdb.base/watchpoint.exp with aarch64 GDBserver debugging arm 32-bit program. The buf is 30-byte long but 4-byte aligned, and four debugging registers can't cover 34-byte (extend 4 bytes to be 8-byte aligned) area. However, this problem does exist on non-multi-arch debugging scenario as well. This patch moves code in aarch64_linux_region_ok_for_hw_watchpoint to aarch64_linux_region_ok_for_watchpoint in nat/aarch64-linux-hw-point.c. Then, checks with aarch64_linux_region_ok_for_watchpoint, like what we are doing in GDB. If the region is OK, call aarch64_handle_watchpoint. Regression tested on aarch64 with both 64-bit program and 32-bit program. Some fails in gdb.base/watchpoint.exp are fixed. gdb: 2015-09-03 Yao Qi <yao.qi@linaro.org> * aarch64-linux-nat.c (aarch64_linux_region_ok_for_hw_watchpoint): Move code to aarch64_linux_region_ok_for_watchpoint. Call aarch64_linux_region_ok_for_watchpoint. * nat/aarch64-linux-hw-point.c (aarch64_linux_region_ok_for_watchpoint): New function. * nat/aarch64-linux-hw-point.h (aarch64_linux_region_ok_for_watchpoint): Declare it. gdb/gdbserver: 2015-09-03 Yao Qi <yao.qi@linaro.org> * linux-aarch64-low.c (aarch64_insert_point): Call aarch64_handle_watchpoint if aarch64_linux_region_ok_for_watchpoint returns true.
187 lines
6.7 KiB
C
187 lines
6.7 KiB
C
/* Copyright (C) 2009-2015 Free Software Foundation, Inc.
|
|
Contributed by ARM 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 AARCH64_LINUX_HW_POINT_H
|
|
#define AARCH64_LINUX_HW_POINT_H 1
|
|
|
|
/* Macro definitions, data structures, and code for the hardware
|
|
breakpoint and hardware watchpoint support follow. We use the
|
|
following abbreviations throughout the code:
|
|
|
|
hw - hardware
|
|
bp - breakpoint
|
|
wp - watchpoint */
|
|
|
|
/* Maximum number of hardware breakpoint and watchpoint registers.
|
|
Neither of these values may exceed the width of dr_changed_t
|
|
measured in bits. */
|
|
|
|
#define AARCH64_HBP_MAX_NUM 16
|
|
#define AARCH64_HWP_MAX_NUM 16
|
|
|
|
/* Alignment requirement in bytes for addresses written to
|
|
hardware breakpoint and watchpoint value registers.
|
|
|
|
A ptrace call attempting to set an address that does not meet the
|
|
alignment criteria will fail. Limited support has been provided in
|
|
this port for unaligned watchpoints, such that from a GDB user
|
|
perspective, an unaligned watchpoint may be requested.
|
|
|
|
This is achieved by minimally enlarging the watched area to meet the
|
|
alignment requirement, and if necessary, splitting the watchpoint
|
|
over several hardware watchpoint registers. */
|
|
|
|
#define AARCH64_HBP_ALIGNMENT 4
|
|
#define AARCH64_HWP_ALIGNMENT 8
|
|
|
|
/* The maximum length of a memory region that can be watched by one
|
|
hardware watchpoint register. */
|
|
|
|
#define AARCH64_HWP_MAX_LEN_PER_REG 8
|
|
|
|
/* ptrace hardware breakpoint resource info is formatted as follows:
|
|
|
|
31 24 16 8 0
|
|
+---------------+--------------+---------------+---------------+
|
|
| RESERVED | RESERVED | DEBUG_ARCH | NUM_SLOTS |
|
|
+---------------+--------------+---------------+---------------+ */
|
|
|
|
|
|
/* Macros to extract fields from the hardware debug information word. */
|
|
#define AARCH64_DEBUG_NUM_SLOTS(x) ((x) & 0xff)
|
|
#define AARCH64_DEBUG_ARCH(x) (((x) >> 8) & 0xff)
|
|
|
|
/* Macro for the expected version of the ARMv8-A debug architecture. */
|
|
#define AARCH64_DEBUG_ARCH_V8 0x6
|
|
|
|
/* ptrace expects control registers to be formatted as follows:
|
|
|
|
31 13 5 3 1 0
|
|
+--------------------------------+----------+------+------+----+
|
|
| RESERVED (SBZ) | LENGTH | TYPE | PRIV | EN |
|
|
+--------------------------------+----------+------+------+----+
|
|
|
|
The TYPE field is ignored for breakpoints. */
|
|
|
|
#define DR_CONTROL_ENABLED(ctrl) (((ctrl) & 0x1) == 1)
|
|
#define DR_CONTROL_LENGTH(ctrl) (((ctrl) >> 5) & 0xff)
|
|
|
|
/* 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 aarch64_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)))
|
|
|
|
/* Structure for managing the hardware breakpoint/watchpoint resources.
|
|
DR_ADDR_* stores the address, DR_CTRL_* stores the control register
|
|
content, and DR_REF_COUNT_* counts the numbers of references to the
|
|
corresponding bp/wp, by which way the limited hardware resources
|
|
are not wasted on duplicated bp/wp settings (though so far gdb has
|
|
done a good job by not sending duplicated bp/wp requests). */
|
|
|
|
struct aarch64_debug_reg_state
|
|
{
|
|
/* hardware breakpoint */
|
|
CORE_ADDR dr_addr_bp[AARCH64_HBP_MAX_NUM];
|
|
unsigned int dr_ctrl_bp[AARCH64_HBP_MAX_NUM];
|
|
unsigned int dr_ref_count_bp[AARCH64_HBP_MAX_NUM];
|
|
|
|
/* hardware watchpoint */
|
|
CORE_ADDR dr_addr_wp[AARCH64_HWP_MAX_NUM];
|
|
unsigned int dr_ctrl_wp[AARCH64_HWP_MAX_NUM];
|
|
unsigned int dr_ref_count_wp[AARCH64_HWP_MAX_NUM];
|
|
};
|
|
|
|
/* 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 aarch64_linux_prepare_to_resume. */
|
|
dr_changed_t dr_changed_bp;
|
|
dr_changed_t dr_changed_wp;
|
|
};
|
|
|
|
extern int aarch64_num_bp_regs;
|
|
extern int aarch64_num_wp_regs;
|
|
|
|
unsigned int aarch64_watchpoint_length (unsigned int ctrl);
|
|
|
|
int aarch64_handle_breakpoint (enum target_hw_bp_type type, CORE_ADDR addr,
|
|
int len, int is_insert,
|
|
struct aarch64_debug_reg_state *state);
|
|
int aarch64_handle_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr,
|
|
int len, int is_insert,
|
|
struct aarch64_debug_reg_state *state);
|
|
|
|
void aarch64_linux_set_debug_regs (const struct aarch64_debug_reg_state *state,
|
|
int tid, int watchpoint);
|
|
|
|
void aarch64_show_debug_reg_state (struct aarch64_debug_reg_state *state,
|
|
const char *func, CORE_ADDR addr,
|
|
int len, enum target_hw_bp_type type);
|
|
|
|
void aarch64_linux_get_debug_reg_capacity (int tid);
|
|
|
|
struct aarch64_debug_reg_state *aarch64_get_debug_reg_state (pid_t pid);
|
|
|
|
int aarch64_linux_region_ok_for_watchpoint (CORE_ADDR addr, int len);
|
|
|
|
#endif /* AARCH64_LINUX_HW_POINT_H */
|