aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYao Qi <yao.qi@linaro.org>2016-07-21 12:12:17 +0100
committerYao Qi <yao.qi@linaro.org>2016-07-21 12:12:17 +0100
commit9aa76cd0a7b2cfdcc9da31e7763a695fac89f569 (patch)
tree3c3da4cc2d57c58b907fbf5c45369eebe709aea2
parent811f8301f8054eb964e92af63930c4495207e7d5 (diff)
downloadgdb-9aa76cd0a7b2cfdcc9da31e7763a695fac89f569.zip
gdb-9aa76cd0a7b2cfdcc9da31e7763a695fac89f569.tar.gz
gdb-9aa76cd0a7b2cfdcc9da31e7763a695fac89f569.tar.bz2
Create sub classes of 'struct breakpoint'
Nowadays, there are three types of breakpoint in GDBserver, - gdb breakpoints, - reinsert breakpoints, used for software single step, - other breakpoints, used for tracepoint, but we only have one 'struct breakpoint' for all of them. Some fields are only useful to one type of breakpoint. For example, cond_list and command_list are only used by gdb breakpoints, while handler is only used by other breakpoints. This patch changes 'struct breakpoint' to a base class, which has fields needed by all breakpoint types, also add three sub-classes to 'struct breakpoint' to these three types of breakpoints. gdb/gdbserver: 2016-07-21 Yao Qi <yao.qi@linaro.org> * mem-break.c (struct breakpoint) <cond_list>: Remove. <command_list, handler>: Remove. (struct gdb_breakpoint): New. (struct other_breakpoint): New. (struct reinsert_breakpoint): New. (is_gdb_breakpoint): New function. (any_persistent_commands): Update command_list if is_gdb_breakpoint returns true. (set_breakpoint): Create breakpoints according to their types. (find_gdb_breakpoint): Return 'struct gdb_breakpoint *'. (set_gdb_breakpoint_1): Likewise. (set_gdb_breakpoint): Likewise. (clear_breakpoint_conditions): Change parameter type to 'struct gdb_breakpoint *'. (clear_breakpoint_commands): Likewise. (clear_breakpoint_conditions_and_commands): Likewise. (add_condition_to_breakpoint): Likewise. (add_breakpoint_condition): Likewise. (add_commands_to_breakpoint): Likewise. (check_breakpoints): Check other_breakpoint. (clone_one_breakpoint): Clone breakpopint according to its type. * mem-break.h (struct gdb_breakpoint): Declare. (set_gdb_breakpoint): Update declaration. (clear_breakpoint_conditions_and_commands): Likewise. (add_breakpoint_condition): Likewise. (add_breakpoint_commands): Likewise. * server.c (process_point_options): Change parameter type to 'struct gdb_breakpoint *'.
-rw-r--r--gdb/gdbserver/ChangeLog31
-rw-r--r--gdb/gdbserver/mem-break.c209
-rw-r--r--gdb/gdbserver/mem-break.h11
-rw-r--r--gdb/gdbserver/server.c4
4 files changed, 188 insertions, 67 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 9291179..7fae552 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,5 +1,36 @@
2016-07-21 Yao Qi <yao.qi@linaro.org>
+ * mem-break.c (struct breakpoint) <cond_list>: Remove.
+ <command_list, handler>: Remove.
+ (struct gdb_breakpoint): New.
+ (struct other_breakpoint): New.
+ (struct reinsert_breakpoint): New.
+ (is_gdb_breakpoint): New function.
+ (any_persistent_commands): Update command_list if
+ is_gdb_breakpoint returns true.
+ (set_breakpoint): Create breakpoints according to their types.
+ (find_gdb_breakpoint): Return 'struct gdb_breakpoint *'.
+ (set_gdb_breakpoint_1): Likewise.
+ (set_gdb_breakpoint): Likewise.
+ (clear_breakpoint_conditions): Change parameter type to
+ 'struct gdb_breakpoint *'.
+ (clear_breakpoint_commands): Likewise.
+ (clear_breakpoint_conditions_and_commands): Likewise.
+ (add_condition_to_breakpoint): Likewise.
+ (add_breakpoint_condition): Likewise.
+ (add_commands_to_breakpoint): Likewise.
+ (check_breakpoints): Check other_breakpoint.
+ (clone_one_breakpoint): Clone breakpopint according to its type.
+ * mem-break.h (struct gdb_breakpoint): Declare.
+ (set_gdb_breakpoint): Update declaration.
+ (clear_breakpoint_conditions_and_commands): Likewise.
+ (add_breakpoint_condition): Likewise.
+ (add_breakpoint_commands): Likewise.
+ * server.c (process_point_options): Change parameter type to
+ 'struct gdb_breakpoint *'.
+
+2016-07-21 Yao Qi <yao.qi@linaro.org>
+
* mem-break.c (set_breakpoint_at): Rename it to ...
(set_breakpoint_type_at): ... it.
(set_breakpoint_at): Call set_breakpoint_type_at.
diff --git a/gdb/gdbserver/mem-break.c b/gdb/gdbserver/mem-break.c
index f0b77f9..3539422 100644
--- a/gdb/gdbserver/mem-break.c
+++ b/gdb/gdbserver/mem-break.c
@@ -173,6 +173,17 @@ struct breakpoint
/* The breakpoint's type. */
enum bkpt_type type;
+ /* Link to this breakpoint's raw breakpoint. This is always
+ non-NULL. */
+ struct raw_breakpoint *raw;
+};
+
+/* Breakpoint requested by GDB. */
+
+struct gdb_breakpoint
+{
+ struct breakpoint base;
+
/* Pointer to the condition list that should be evaluated on
the target or NULL if the breakpoint is unconditional or
if GDB doesn't want us to evaluate the conditionals on the
@@ -181,10 +192,13 @@ struct breakpoint
/* Point to the list of commands to run when this is hit. */
struct point_command_list *command_list;
+};
- /* Link to this breakpoint's raw breakpoint. This is always
- non-NULL. */
- struct raw_breakpoint *raw;
+/* Breakpoint used by GDBserver. */
+
+struct other_breakpoint
+{
+ struct breakpoint base;
/* Function to call when we hit this breakpoint. If it returns 1,
the breakpoint shall be deleted; 0 or if this callback is NULL,
@@ -192,6 +206,13 @@ struct breakpoint
int (*handler) (CORE_ADDR);
};
+/* Reinsert breakpoint. */
+
+struct reinsert_breakpoint
+{
+ struct breakpoint base;
+};
+
/* Return the breakpoint size from its kind. */
static int
@@ -266,6 +287,18 @@ Z_packet_to_raw_bkpt_type (char z_type)
}
}
+/* Return true if breakpoint TYPE is a GDB breakpoint. */
+
+static int
+is_gdb_breakpoint (enum bkpt_type type)
+{
+ return (type == gdb_breakpoint_Z0
+ || type == gdb_breakpoint_Z1
+ || type == gdb_breakpoint_Z2
+ || type == gdb_breakpoint_Z3
+ || type == gdb_breakpoint_Z4);
+}
+
int
any_persistent_commands (void)
{
@@ -275,9 +308,14 @@ any_persistent_commands (void)
for (bp = proc->breakpoints; bp != NULL; bp = bp->next)
{
- for (cl = bp->command_list; cl != NULL; cl = cl->next)
- if (cl->persistence)
- return 1;
+ if (is_gdb_breakpoint (bp->type))
+ {
+ struct gdb_breakpoint *gdb_bp = (struct gdb_breakpoint *) bp;
+
+ for (cl = gdb_bp->command_list; cl != NULL; cl = cl->next)
+ if (cl->persistence)
+ return 1;
+ }
}
return 0;
@@ -773,11 +811,32 @@ set_breakpoint (enum bkpt_type type, enum raw_bkpt_type raw_type,
return NULL;
}
- bp = XCNEW (struct breakpoint);
- bp->type = type;
+ if (is_gdb_breakpoint (type))
+ {
+ struct gdb_breakpoint *gdb_bp = XCNEW (struct gdb_breakpoint);
+
+ bp = (struct breakpoint *) gdb_bp;
+ gdb_assert (handler == NULL);
+ }
+ else if (type == other_breakpoint)
+ {
+ struct other_breakpoint *other_bp = XCNEW (struct other_breakpoint);
+
+ other_bp->handler = handler;
+ bp = (struct breakpoint *) other_bp;
+ }
+ else if (type == reinsert_breakpoint)
+ {
+ struct reinsert_breakpoint *reinsert_bp
+ = XCNEW (struct reinsert_breakpoint);
+ bp = (struct breakpoint *) reinsert_bp;
+ }
+ else
+ gdb_assert_not_reached ("unhandled breakpoint type");
+
+ bp->type = type;
bp->raw = raw;
- bp->handler = handler;
bp->next = proc->breakpoints;
proc->breakpoints = bp;
@@ -924,7 +983,7 @@ delete_breakpoint (struct breakpoint *todel)
address ADDR and return a pointer to its structure. If KIND is -1,
the breakpoint's kind is ignored. */
-static struct breakpoint *
+static struct gdb_breakpoint *
find_gdb_breakpoint (char z_type, CORE_ADDR addr, int kind)
{
struct process_info *proc = current_process ();
@@ -934,7 +993,7 @@ find_gdb_breakpoint (char z_type, CORE_ADDR addr, int kind)
for (bp = proc->breakpoints; bp != NULL; bp = bp->next)
if (bp->type == type && bp->raw->pc == addr
&& (kind == -1 || bp->raw->kind == kind))
- return bp;
+ return (gdb_breakpoint *) bp;
return NULL;
}
@@ -952,10 +1011,10 @@ z_type_supported (char z_type)
failure returns NULL and sets *ERR to either -1 for error, or 1 if
Z_TYPE breakpoints are not supported on this target. */
-static struct breakpoint *
+static struct gdb_breakpoint *
set_gdb_breakpoint_1 (char z_type, CORE_ADDR addr, int kind, int *err)
{
- struct breakpoint *bp;
+ struct gdb_breakpoint *bp;
enum bkpt_type type;
enum raw_bkpt_type raw_type;
@@ -981,12 +1040,12 @@ set_gdb_breakpoint_1 (char z_type, CORE_ADDR addr, int kind, int *err)
if (bp != NULL)
{
- if (bp->raw->kind != kind)
+ if (bp->base.raw->kind != kind)
{
/* A different kind than previously seen. The previous
breakpoint must be gone then. */
- bp->raw->inserted = -1;
- delete_breakpoint (bp);
+ bp->base.raw->inserted = -1;
+ delete_breakpoint ((struct breakpoint *) bp);
bp = NULL;
}
else if (z_type == Z_PACKET_SW_BP)
@@ -1022,7 +1081,8 @@ set_gdb_breakpoint_1 (char z_type, CORE_ADDR addr, int kind, int *err)
raw_type = Z_packet_to_raw_bkpt_type (z_type);
type = Z_packet_to_bkpt_type (z_type);
- return set_breakpoint (type, raw_type, addr, kind, NULL, err);
+ return (struct gdb_breakpoint *) set_breakpoint (type, raw_type, addr,
+ kind, NULL, err);
}
static int
@@ -1047,10 +1107,10 @@ check_gdb_bp_preconditions (char z_type, int *err)
/* See mem-break.h. This is a wrapper for set_gdb_breakpoint_1 that
knows to prepare to access memory for Z0 breakpoints. */
-struct breakpoint *
+struct gdb_breakpoint *
set_gdb_breakpoint (char z_type, CORE_ADDR addr, int kind, int *err)
{
- struct breakpoint *bp;
+ struct gdb_breakpoint *bp;
if (!check_gdb_bp_preconditions (z_type, err))
return NULL;
@@ -1082,7 +1142,7 @@ set_gdb_breakpoint (char z_type, CORE_ADDR addr, int kind, int *err)
static int
delete_gdb_breakpoint_1 (char z_type, CORE_ADDR addr, int kind)
{
- struct breakpoint *bp;
+ struct gdb_breakpoint *bp;
int err;
bp = find_gdb_breakpoint (z_type, addr, kind);
@@ -1092,7 +1152,7 @@ delete_gdb_breakpoint_1 (char z_type, CORE_ADDR addr, int kind)
/* Before deleting the breakpoint, make sure to free its condition
and command lists. */
clear_breakpoint_conditions_and_commands (bp);
- err = delete_breakpoint (bp);
+ err = delete_breakpoint ((struct breakpoint *) bp);
if (err != 0)
return -1;
@@ -1132,7 +1192,7 @@ delete_gdb_breakpoint (char z_type, CORE_ADDR addr, int kind)
/* Clear all conditions associated with a breakpoint. */
static void
-clear_breakpoint_conditions (struct breakpoint *bp)
+clear_breakpoint_conditions (struct gdb_breakpoint *bp)
{
struct point_cond_list *cond;
@@ -1157,7 +1217,7 @@ clear_breakpoint_conditions (struct breakpoint *bp)
/* Clear all commands associated with a breakpoint. */
static void
-clear_breakpoint_commands (struct breakpoint *bp)
+clear_breakpoint_commands (struct gdb_breakpoint *bp)
{
struct point_command_list *cmd;
@@ -1180,7 +1240,7 @@ clear_breakpoint_commands (struct breakpoint *bp)
}
void
-clear_breakpoint_conditions_and_commands (struct breakpoint *bp)
+clear_breakpoint_conditions_and_commands (struct gdb_breakpoint *bp)
{
clear_breakpoint_conditions (bp);
clear_breakpoint_commands (bp);
@@ -1189,7 +1249,7 @@ clear_breakpoint_conditions_and_commands (struct breakpoint *bp)
/* Add condition CONDITION to GDBserver's breakpoint BP. */
static void
-add_condition_to_breakpoint (struct breakpoint *bp,
+add_condition_to_breakpoint (struct gdb_breakpoint *bp,
struct agent_expr *condition)
{
struct point_cond_list *new_cond;
@@ -1206,7 +1266,7 @@ add_condition_to_breakpoint (struct breakpoint *bp,
/* Add a target-side condition CONDITION to a breakpoint. */
int
-add_breakpoint_condition (struct breakpoint *bp, char **condition)
+add_breakpoint_condition (struct gdb_breakpoint *bp, char **condition)
{
char *actparm = *condition;
struct agent_expr *cond;
@@ -1240,7 +1300,7 @@ static int
gdb_condition_true_at_breakpoint_z_type (char z_type, CORE_ADDR addr)
{
/* Fetch registers for the current inferior. */
- struct breakpoint *bp = find_gdb_breakpoint (z_type, addr, -1);
+ struct gdb_breakpoint *bp = find_gdb_breakpoint (z_type, addr, -1);
ULONGEST value = 0;
struct point_cond_list *cl;
int err = 0;
@@ -1287,7 +1347,7 @@ gdb_condition_true_at_breakpoint (CORE_ADDR where)
/* Add commands COMMANDS to GDBserver's breakpoint BP. */
static void
-add_commands_to_breakpoint (struct breakpoint *bp,
+add_commands_to_breakpoint (struct gdb_breakpoint *bp,
struct agent_expr *commands, int persist)
{
struct point_command_list *new_cmd;
@@ -1305,7 +1365,7 @@ add_commands_to_breakpoint (struct breakpoint *bp,
/* Add a target-side command COMMAND to the breakpoint at ADDR. */
int
-add_breakpoint_commands (struct breakpoint *bp, char **command,
+add_breakpoint_commands (struct gdb_breakpoint *bp, char **command,
int persist)
{
char *actparm = *command;
@@ -1339,7 +1399,7 @@ add_breakpoint_commands (struct breakpoint *bp, char **command,
static int
gdb_no_commands_at_breakpoint_z_type (char z_type, CORE_ADDR addr)
{
- struct breakpoint *bp = find_gdb_breakpoint (z_type, addr, -1);
+ struct gdb_breakpoint *bp = find_gdb_breakpoint (z_type, addr, -1);
if (bp == NULL)
return 1;
@@ -1369,7 +1429,7 @@ static int
run_breakpoint_commands_z_type (char z_type, CORE_ADDR addr)
{
/* Fetch registers for the current inferior. */
- struct breakpoint *bp = find_gdb_breakpoint (z_type, addr, -1);
+ struct gdb_breakpoint *bp = find_gdb_breakpoint (z_type, addr, -1);
ULONGEST value = 0;
struct point_command_list *cl;
int err = 0;
@@ -1657,14 +1717,20 @@ check_breakpoints (CORE_ADDR stop_pc)
return;
}
- if (bp->handler != NULL && (*bp->handler) (stop_pc))
+ if (bp->type == other_breakpoint)
{
- *bp_link = bp->next;
+ struct other_breakpoint *other_bp
+ = (struct other_breakpoint *) bp;
+
+ if (other_bp->handler != NULL && (*other_bp->handler) (stop_pc))
+ {
+ *bp_link = bp->next;
- release_breakpoint (proc, bp);
+ release_breakpoint (proc, bp);
- bp = *bp_link;
- continue;
+ bp = *bp_link;
+ continue;
+ }
}
}
@@ -2051,12 +2117,6 @@ clone_one_breakpoint (const struct breakpoint *src)
{
struct breakpoint *dest;
struct raw_breakpoint *dest_raw;
- struct point_cond_list *current_cond;
- struct point_cond_list *new_cond;
- struct point_cond_list *cond_tail = NULL;
- struct point_command_list *current_cmd;
- struct point_command_list *new_cmd;
- struct point_command_list *cmd_tail = NULL;
/* Clone the raw breakpoint. */
dest_raw = XCNEW (struct raw_breakpoint);
@@ -2068,29 +2128,58 @@ clone_one_breakpoint (const struct breakpoint *src)
dest_raw->inserted = src->raw->inserted;
/* Clone the high-level breakpoint. */
- dest = XCNEW (struct breakpoint);
- dest->type = src->type;
- dest->raw = dest_raw;
- dest->handler = src->handler;
-
- /* Clone the condition list. */
- for (current_cond = src->cond_list; current_cond != NULL;
- current_cond = current_cond->next)
+ if (is_gdb_breakpoint (src->type))
{
- new_cond = XCNEW (struct point_cond_list);
- new_cond->cond = clone_agent_expr (current_cond->cond);
- APPEND_TO_LIST (&dest->cond_list, new_cond, cond_tail);
+ struct gdb_breakpoint *gdb_dest = XCNEW (struct gdb_breakpoint);
+ struct point_cond_list *current_cond;
+ struct point_cond_list *new_cond;
+ struct point_cond_list *cond_tail = NULL;
+ struct point_command_list *current_cmd;
+ struct point_command_list *new_cmd;
+ struct point_command_list *cmd_tail = NULL;
+
+ /* Clone the condition list. */
+ for (current_cond = ((struct gdb_breakpoint *) src)->cond_list;
+ current_cond != NULL;
+ current_cond = current_cond->next)
+ {
+ new_cond = XCNEW (struct point_cond_list);
+ new_cond->cond = clone_agent_expr (current_cond->cond);
+ APPEND_TO_LIST (&gdb_dest->cond_list, new_cond, cond_tail);
+ }
+
+ /* Clone the command list. */
+ for (current_cmd = ((struct gdb_breakpoint *) src)->command_list;
+ current_cmd != NULL;
+ current_cmd = current_cmd->next)
+ {
+ new_cmd = XCNEW (struct point_command_list);
+ new_cmd->cmd = clone_agent_expr (current_cmd->cmd);
+ new_cmd->persistence = current_cmd->persistence;
+ APPEND_TO_LIST (&gdb_dest->command_list, new_cmd, cmd_tail);
+ }
+
+ dest = (struct breakpoint *) gdb_dest;
}
+ else if (src->type == other_breakpoint)
+ {
+ struct other_breakpoint *other_dest = XCNEW (struct other_breakpoint);
- /* Clone the command list. */
- for (current_cmd = src->command_list; current_cmd != NULL;
- current_cmd = current_cmd->next)
+ other_dest->handler = ((struct other_breakpoint *) src)->handler;
+ dest = (struct breakpoint *) other_dest;
+ }
+ else if (src->type == reinsert_breakpoint)
{
- new_cmd = XCNEW (struct point_command_list);
- new_cmd->cmd = clone_agent_expr (current_cmd->cmd);
- new_cmd->persistence = current_cmd->persistence;
- APPEND_TO_LIST (&dest->command_list, new_cmd, cmd_tail);
+ struct reinsert_breakpoint *reinsert_dest
+ = XCNEW (struct reinsert_breakpoint);
+
+ dest = (struct breakpoint *) reinsert_dest;
}
+ else
+ gdb_assert_not_reached ("unhandled breakpoint type");
+
+ dest->type = src->type;
+ dest->raw = dest_raw;
return dest;
}
diff --git a/gdb/gdbserver/mem-break.h b/gdb/gdbserver/mem-break.h
index dd5a750..321de12 100644
--- a/gdb/gdbserver/mem-break.h
+++ b/gdb/gdbserver/mem-break.h
@@ -25,6 +25,7 @@
/* Breakpoints are opaque. */
struct breakpoint;
+struct gdb_breakpoint;
struct fast_tracepoint_jump;
struct raw_breakpoint;
struct process_info;
@@ -70,8 +71,8 @@ enum target_hw_bp_type raw_bkpt_type_to_target_hw_bp_type
failure returns NULL and sets *ERR to either -1 for error, or 1 if
Z_TYPE breakpoints are not supported on this target. */
-struct breakpoint *set_gdb_breakpoint (char z_type, CORE_ADDR addr, int kind,
- int *err);
+struct gdb_breakpoint *set_gdb_breakpoint (char z_type, CORE_ADDR addr,
+ int kind, int *err);
/* Delete a GDB breakpoint of type Z_TYPE and kind KIND previously
inserted at ADDR with set_gdb_breakpoint_at. Returns 0 on success,
@@ -107,20 +108,20 @@ int reinsert_breakpoint_inserted_here (CORE_ADDR addr);
/* Clear all breakpoint conditions and commands associated with a
breakpoint. */
-void clear_breakpoint_conditions_and_commands (struct breakpoint *bp);
+void clear_breakpoint_conditions_and_commands (struct gdb_breakpoint *bp);
/* Set target-side condition CONDITION to the breakpoint at ADDR.
Returns false on failure. On success, advances CONDITION pointer
past the condition and returns true. */
-int add_breakpoint_condition (struct breakpoint *bp, char **condition);
+int add_breakpoint_condition (struct gdb_breakpoint *bp, char **condition);
/* Set target-side commands COMMANDS to the breakpoint at ADDR.
Returns false on failure. On success, advances COMMANDS past the
commands and returns true. If PERSIST, the commands should run
even while GDB is disconnected. */
-int add_breakpoint_commands (struct breakpoint *bp, char **commands,
+int add_breakpoint_commands (struct gdb_breakpoint *bp, char **commands,
int persist);
int any_persistent_commands (void);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 9c50929..18517bc 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -3825,7 +3825,7 @@ main (int argc, char *argv[])
after the last processed option. */
static void
-process_point_options (struct breakpoint *bp, char **packet)
+process_point_options (struct gdb_breakpoint *bp, char **packet)
{
char *dataptr = *packet;
int persist;
@@ -4197,7 +4197,7 @@ process_serial_event (void)
if (insert)
{
- struct breakpoint *bp;
+ struct gdb_breakpoint *bp;
bp = set_gdb_breakpoint (type, addr, kind, &res);
if (bp != NULL)