diff options
author | zwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2009-06-11 11:43:07 +0000 |
---|---|---|
committer | zwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60> | 2009-06-11 11:43:07 +0000 |
commit | 538050c146ea514b27657930e63a7f51e2a34c4c (patch) | |
tree | 82a36a58a2396de45488bc5f4d2b10dc18aa5482 | |
parent | 8e899d43ef8c049200e4558c4ba2b7f052468935 (diff) | |
download | riscv-openocd-538050c146ea514b27657930e63a7f51e2a34c4c.zip riscv-openocd-538050c146ea514b27657930e63a7f51e2a34c4c.tar.gz riscv-openocd-538050c146ea514b27657930e63a7f51e2a34c4c.tar.bz2 |
Factor handle_bp_command into pieces:
- Bug fix: return a syntax error if the wrong number of arguments are given.
- Add handle_bp_command_list() and handle_bp_command_set().
- Use temporary addr variable to eliminate redundant strtoul() calls.
- Place variable declarations at their point of first use.
git-svn-id: svn://svn.berlios.de/openocd/trunk@2196 b42882b7-edfa-0310-969c-e2dbd0fdcd60
-rw-r--r-- | src/target/target.c | 86 |
1 files changed, 49 insertions, 37 deletions
diff --git a/src/target/target.c b/src/target/target.c index 5c43238..b7a4f3f 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -2449,57 +2449,69 @@ static int handle_test_image_command(struct command_context_s *cmd_ctx, char *cm return handle_verify_image_command_internal(cmd_ctx, cmd, args, argc, 0); } -static int handle_bp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +static int handle_bp_command_list(struct command_context_s *cmd_ctx) { - int retval; target_t *target = get_current_target(cmd_ctx); - - if (argc == 0) + breakpoint_t *breakpoint = target->breakpoints; + while (breakpoint) { - breakpoint_t *breakpoint = target->breakpoints; - - while (breakpoint) + if (breakpoint->type == BKPT_SOFT) { - if (breakpoint->type == BKPT_SOFT) - { - char* buf = buf_to_str(breakpoint->orig_instr, breakpoint->length, 16); - command_print(cmd_ctx, "0x%8.8x, 0x%x, %i, 0x%s", breakpoint->address, breakpoint->length, breakpoint->set, buf); - free(buf); - } - else - { - command_print(cmd_ctx, "0x%8.8x, 0x%x, %i", breakpoint->address, breakpoint->length, breakpoint->set); - } - breakpoint = breakpoint->next; - } - } - else if (argc >= 2) - { - int hw = BKPT_SOFT; - u32 length = 0; - - length = strtoul(args[1], NULL, 0); - - if (argc >= 3) - if (strcmp(args[2], "hw") == 0) - hw = BKPT_HARD; - - if ((retval = breakpoint_add(target, strtoul(args[0], NULL, 0), length, hw)) != ERROR_OK) - { - LOG_ERROR("Failure setting breakpoints"); + char* buf = buf_to_str(breakpoint->orig_instr, + breakpoint->length, 16); + command_print(cmd_ctx, "0x%8.8x, 0x%x, %i, 0x%s", + breakpoint->address, breakpoint->length, + breakpoint->set, buf); + free(buf); } else { - command_print(cmd_ctx, "breakpoint added at address 0x%8.8lx", - strtoul(args[0], NULL, 0)); + command_print(cmd_ctx, "0x%8.8x, 0x%x, %i", + breakpoint->address, breakpoint->length, breakpoint->set); } + + breakpoint = breakpoint->next; } + return ERROR_OK; +} + +static int handle_bp_command_set(struct command_context_s *cmd_ctx, + u32 addr, u32 length, int hw) +{ + target_t *target = get_current_target(cmd_ctx); + int retval = breakpoint_add(target, addr, length, hw); + if (ERROR_OK == retval) + command_print(cmd_ctx, "breakpoint set at 0x%8.8x", addr); else + LOG_ERROR("Failure setting breakpoint"); + return retval; +} + +static int handle_bp_command(struct command_context_s *cmd_ctx, + char *cmd, char **args, int argc) +{ + if (argc == 0) + return handle_bp_command_list(cmd_ctx); + + if (argc < 2 || argc > 3) { command_print(cmd_ctx, "usage: bp <address> <length> ['hw']"); + return ERROR_COMMAND_SYNTAX_ERROR; } - return ERROR_OK; + u32 addr = strtoul(args[0], NULL, 0); + u32 length = strtoul(args[1], NULL, 0); + + int hw = BKPT_SOFT; + if (argc == 3) + { + if (strcmp(args[2], "hw") == 0) + hw = BKPT_HARD; + else + return ERROR_COMMAND_SYNTAX_ERROR; + } + + return handle_bp_command_set(cmd_ctx, addr, length, hw); } static int handle_rbp_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) |