Factor handle_bp_command into pieces:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Thu, 11 Jun 2009 11:43:07 +0000 (11:43 +0000)
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Thu, 11 Jun 2009 11:43:07 +0000 (11:43 +0000)
- 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

src/target/target.c

index 5c432389174ce63331b92433486ff51748016c7c..b7a4f3f80b60e231ae4e5cfbaf3799ea4b8be02b 100644 (file)
@@ -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)

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)