From 4ff0d3d82d37a57507c147886ce9f9bfb7495b99 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 20 May 2014 18:24:27 +0100 Subject: [PATCH] [GDBserver][AArch64] Make watchpoint support use target_hw_bp_type. This makes linux-aarch64-low.c use target_hw_bp_type, like gdb's aarch64-linux-nat.c. The original motivation is decoupling insert_point/remove_point from Z packet numbers, but I think making the files a little bit more similar is a good thing on its own right. Ideally we'd merge these files even... The aarch64_point_encode_ctrl_reg change is taken straight from GDB's copy. I confirmed with a cross compiler that this builds, but it's otherwise untested. gdb/gdbserver/ 2014-05-20 Pedro Alves * linux-aarch64-low.c: Include break-common.h. (enum target_point_type): Delete. (Z_packet_to_point_type): Rename to ... (Z_packet_to_target_hw_bp_type): ... this, and return a target_hw_bp_type instead. (aarch64_show_debug_reg_state): Take an enum target_hw_bp_type instead of an enum target_point_type. (aarch64_point_encode_ctrl_reg): Likewise. Compute type mask from breakpoint type. (aarch64_dr_state_insert_one_point) (aarch64_dr_state_remove_one_point, aarch64_handle_breakpoint) (aarch64_handle_aligned_watchpoint) (aarch64_handle_unaligned_watchpoint, aarch64_handle_watchpoint): Take an enum target_hw_bp_type instead of an enum target_point_type. (aarch64_supports_z_point_type): New function. (aarch64_insert_point, aarch64_remove_point): Use it. Adjust to use Z_packet_to_target_hw_bp_type. --- gdb/gdbserver/ChangeLog | 21 ++++++++ gdb/gdbserver/linux-aarch64-low.c | 100 +++++++++++++++++++++++--------------- 2 files changed, 82 insertions(+), 39 deletions(-) diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog index d169be2..ef54cf9 100644 --- a/gdb/gdbserver/ChangeLog +++ b/gdb/gdbserver/ChangeLog @@ -1,3 +1,24 @@ +2014-05-20 Pedro Alves + + * linux-aarch64-low.c: Include break-common.h. + (enum target_point_type): Delete. + (Z_packet_to_point_type): Rename to ... + (Z_packet_to_target_hw_bp_type): ... this, and return a + target_hw_bp_type instead. + (aarch64_show_debug_reg_state): Take an enum target_hw_bp_type + instead of an enum target_point_type. + (aarch64_point_encode_ctrl_reg): Likewise. Compute type mask from + breakpoint type. + (aarch64_dr_state_insert_one_point) + (aarch64_dr_state_remove_one_point, aarch64_handle_breakpoint) + (aarch64_handle_aligned_watchpoint) + (aarch64_handle_unaligned_watchpoint, aarch64_handle_watchpoint): + Take an enum target_hw_bp_type instead of an enum + target_point_type. + (aarch64_supports_z_point_type): New function. + (aarch64_insert_point, aarch64_remove_point): Use it. Adjust to + use Z_packet_to_target_hw_bp_type. + 2014-05-20 Joel Brobecker * configure.ac: Only use -Werror by default when DEVELOPMENT diff --git a/gdb/gdbserver/linux-aarch64-low.c b/gdb/gdbserver/linux-aarch64-low.c index 627ade3..8b32d79 100644 --- a/gdb/gdbserver/linux-aarch64-low.c +++ b/gdb/gdbserver/linux-aarch64-low.c @@ -29,6 +29,7 @@ #include #include "gdb_proc_service.h" +#include "break-common.h" /* Defined in auto-generated files. */ void init_registers_aarch64 (void); @@ -208,36 +209,20 @@ struct arch_lwp_info static int aarch64_num_bp_regs; static int aarch64_num_wp_regs; -/* Hardware breakpoint/watchpoint types. - The values map to their encodings in the bit 4 and bit 3 of the - hardware breakpoint/watchpoint control registers. */ - -enum target_point_type -{ - hw_execute = 0, /* Execute HW breakpoint */ - hw_read = 1, /* Read HW watchpoint */ - hw_write = 2, /* Common HW watchpoint */ - hw_access = 3, /* Access HW watchpoint */ - point_type_unsupported -}; - #define Z_PACKET_SW_BP '0' #define Z_PACKET_HW_BP '1' #define Z_PACKET_WRITE_WP '2' #define Z_PACKET_READ_WP '3' #define Z_PACKET_ACCESS_WP '4' -/* Map the protocol breakpoint/watchpoint type TYPE to - enum target_point_type. */ +/* Map the protocol breakpoint/watchpoint type TYPE to enum + target_hw_bp_type. */ -static enum target_point_type -Z_packet_to_point_type (char type) +static enum target_hw_bp_type +Z_packet_to_target_hw_bp_type (char type) { switch (type) { - case Z_PACKET_SW_BP: - /* Leave the handling of the sw breakpoint with the gdb client. */ - return point_type_unsupported; case Z_PACKET_HW_BP: return hw_execute; case Z_PACKET_WRITE_WP: @@ -247,7 +232,7 @@ Z_packet_to_point_type (char type) case Z_PACKET_ACCESS_WP: return hw_access; default: - return point_type_unsupported; + fatal ("bad watchpoint type %c", type); } } @@ -358,7 +343,7 @@ aarch64_breakpoint_at (CORE_ADDR where) static void aarch64_show_debug_reg_state (struct aarch64_debug_reg_state *state, const char *func, CORE_ADDR addr, - int len, enum target_point_type type) + int len, enum target_hw_bp_type type) { int i; @@ -448,12 +433,31 @@ aarch64_watchpoint_length (unsigned int ctrl) breakpoint/watchpoint control register. */ static unsigned int -aarch64_point_encode_ctrl_reg (enum target_point_type type, int len) +aarch64_point_encode_ctrl_reg (enum target_hw_bp_type type, int len) { - unsigned int ctrl; + unsigned int ctrl, ttype; /* type */ - ctrl = type << 3; + switch (type) + { + case hw_write: + ttype = 2; + break; + case hw_read: + ttype = 1; + break; + case hw_access: + ttype = 3; + break; + case hw_execute: + ttype = 0; + break; + default: + perror_with_name (_("Unrecognized breakpoint/watchpoint type")); + } + + /* type */ + ctrl = ttype << 3; /* length bitmask */ ctrl |= ((1 << len) - 1) << 5; /* enabled at el0 */ @@ -749,7 +753,7 @@ aarch64_get_debug_reg_state () static int aarch64_dr_state_insert_one_point (struct aarch64_debug_reg_state *state, - enum target_point_type type, + enum target_hw_bp_type type, CORE_ADDR addr, int len) { int i, idx, num_regs, is_watchpoint; @@ -822,7 +826,7 @@ aarch64_dr_state_insert_one_point (struct aarch64_debug_reg_state *state, static int aarch64_dr_state_remove_one_point (struct aarch64_debug_reg_state *state, - enum target_point_type type, + enum target_hw_bp_type type, CORE_ADDR addr, int len) { int i, num_regs, is_watchpoint; @@ -876,7 +880,7 @@ aarch64_dr_state_remove_one_point (struct aarch64_debug_reg_state *state, } static int -aarch64_handle_breakpoint (enum target_point_type type, CORE_ADDR addr, +aarch64_handle_breakpoint (enum target_hw_bp_type type, CORE_ADDR addr, int len, int is_insert) { struct aarch64_debug_reg_state *state; @@ -898,7 +902,7 @@ aarch64_handle_breakpoint (enum target_point_type type, CORE_ADDR addr, from that it is an aligned watchpoint to be handled. */ static int -aarch64_handle_aligned_watchpoint (enum target_point_type type, +aarch64_handle_aligned_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr, int len, int is_insert) { struct aarch64_debug_reg_state *state; @@ -919,7 +923,7 @@ aarch64_handle_aligned_watchpoint (enum target_point_type type, Return 0 if succeed. */ static int -aarch64_handle_unaligned_watchpoint (enum target_point_type type, +aarch64_handle_unaligned_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr, int len, int is_insert) { struct aarch64_debug_reg_state *state @@ -956,7 +960,7 @@ aarch64_handle_unaligned_watchpoint (enum target_point_type type, } static int -aarch64_handle_watchpoint (enum target_point_type type, CORE_ADDR addr, +aarch64_handle_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr, int len, int is_insert) { if (aarch64_point_is_aligned (1 /* is_watchpoint */ , addr, len)) @@ -965,6 +969,22 @@ aarch64_handle_watchpoint (enum target_point_type type, CORE_ADDR addr, return aarch64_handle_unaligned_watchpoint (type, addr, len, is_insert); } +static int +aarch64_supports_z_point_type (char z_type) +{ + switch (z_type) + { + case Z_PACKET_HW_BP: + case Z_PACKET_WRITE_WP: + case Z_PACKET_READ_WP: + case Z_PACKET_ACCESS_WP: + return 1; + default: + /* Leave the handling of sw breakpoints with the gdb client. */ + return 0; + } +} + /* Insert a hardware breakpoint/watchpoint. It actually only records the info of the to-be-inserted bp/wp; the actual insertion will happen when threads are resumed. @@ -977,16 +997,17 @@ static int aarch64_insert_point (char type, CORE_ADDR addr, int len) { int ret; - enum target_point_type targ_type; + enum target_hw_bp_type targ_type; + + if (!aarch64_supports_z_point_type (type)) + return 1; if (debug_hw_points) fprintf (stderr, "insert_point on entry (addr=0x%08lx, len=%d)\n", (unsigned long) addr, len); /* Determine the type from the packet. */ - targ_type = Z_packet_to_point_type (type); - if (targ_type == point_type_unsupported) - return 1; + targ_type = Z_packet_to_target_hw_bp_type (type); if (targ_type != hw_execute) ret = @@ -1014,16 +1035,17 @@ static int aarch64_remove_point (char type, CORE_ADDR addr, int len) { int ret; - enum target_point_type targ_type; + enum target_hw_bp_type targ_type; + + if (!aarch64_supports_z_point_type (type)) + return 1; if (debug_hw_points) fprintf (stderr, "remove_point on entry (addr=0x%08lx, len=%d)\n", (unsigned long) addr, len); /* Determine the type from the packet. */ - targ_type = Z_packet_to_point_type (type); - if (targ_type == point_type_unsupported) - return 1; + targ_type = Z_packet_to_target_hw_bp_type (type); /* Set up state pointers. */ if (targ_type != hw_execute) -- 2.7.4