target: create and use target_name()
authorDavid Brownell <dbrownell@users.sourceforge.net>
Thu, 26 Nov 2009 00:38:08 +0000 (16:38 -0800)
committerDavid Brownell <dbrownell@users.sourceforge.net>
Thu, 26 Nov 2009 00:38:08 +0000 (16:38 -0800)
Several of the sites now using target_type_name() really
ought to be using an instance-specific name.  Create a
function called target_name(), accessing the instance's
own (command) name.

Use it in several places that really should be displaying
instance-specific names.  Also in several places which
were already doing so, but which had no wrapper to call.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
src/server/gdb_server.c
src/target/breakpoints.c
src/target/etm.c
src/target/target.c
src/target/target.h

index f733e7b6601ba1c31676851ba7b87f3ca876c9e6..bd1d047d5c9fd051726a7d24f811610a7537436a 100644 (file)
@@ -774,7 +774,7 @@ int gdb_new_connection(struct connection *connection)
        gdb_actual_connections++;
        LOG_DEBUG("New GDB Connection: %d, Target %s, state: %s",
                  gdb_actual_connections,
-                 gdb_service->target->cmd_name,
+                 target_name(gdb_service->target),
                  target_state_name(gdb_service->target));
 
        return ERROR_OK;
@@ -792,7 +792,7 @@ int gdb_connection_closed(struct connection *connection)
 
        gdb_actual_connections--;
        LOG_DEBUG("GDB Close, Target: %s, state: %s, gdb_actual_connections=%d",
-                 gdb_service->target->cmd_name,
+                 target_name(gdb_service->target),
                  target_state_name(gdb_service->target),
                  gdb_actual_connections);
 
@@ -2138,7 +2138,7 @@ int gdb_input_inner(struct connection *connection)
                                        watchpoint_clear_target(gdb_service->target);
                                        command_run_linef(connection->cmd_ctx,
                                                        "ocd_gdb_restart %s",
-                                                       target->cmd_name);
+                                                       target_name(target));
                                        break;
                                default:
                                        /* ignore unkown packets */
@@ -2216,7 +2216,7 @@ int gdb_init(void)
                add_service("gdb", CONNECTION_PIPE, 0, 1, gdb_new_connection, gdb_input, gdb_connection_closed, gdb_service);
 
                LOG_DEBUG("gdb service for target %s using pipes",
-                               target_type_name(target));
+                               target_name(target));
        }
        else
        {
@@ -2233,7 +2233,7 @@ int gdb_init(void)
                                        gdb_connection_closed, gdb_service);
 
                        LOG_DEBUG("gdb service for target %s at TCP port %i",
-                                       target_type_name(target),
+                                       target_name(target),
                                        port);
                        target = target->next;
                        port++;
index df797e3774017531cc83937fce25f87646f1971d..16ab7e0caa672c03d5c9dbd4ebb6625d80904ccc 100644 (file)
@@ -157,7 +157,7 @@ void breakpoint_clear_target(struct target *target)
        struct breakpoint *breakpoint;
 
        LOG_DEBUG("Delete all breakpoints for target: %s",
-                       target_type_name(target));
+                       target_name(target));
        while ((breakpoint = target->breakpoints) != NULL)
        {
                breakpoint_free(target, breakpoint);
@@ -294,7 +294,7 @@ void watchpoint_clear_target(struct target *target)
        struct watchpoint *watchpoint;
 
        LOG_DEBUG("Delete all watchpoints for target: %s",
-                       target_type_name(target));
+                       target_name(target));
        while ((watchpoint = target->watchpoints) != NULL)
        {
                watchpoint_free(target, watchpoint);
index 2ea7345da9f430820de0996c9d1fd66cd26c21d6..520e22f6089c9a20c5785992f4bd1a0e8abb3d8f 100644 (file)
@@ -1374,7 +1374,8 @@ COMMAND_HANDLER(handle_etm_config_command)
        arm = target_to_arm(target);
        if (!is_arm(arm)) {
                command_print(CMD_CTX, "target '%s' is '%s'; not an ARM",
-                               target->cmd_name, target_type_name(target));
+                               target_name(target),
+                               target_type_name(target));
                return ERROR_FAIL;
        }
 
index f46fc67b4bc35aa57883e3c71c0a35ed8c04debc..3de9f2c6a3adbea8492b6d837eb62a3b9661490f 100644 (file)
@@ -556,7 +556,7 @@ static int target_soft_reset_halt_imp(struct target *target)
        }
        if (!target->type->soft_reset_halt_imp) {
                LOG_ERROR("Target %s does not support soft_reset_halt",
-                               target->cmd_name);
+                               target_name(target));
                return ERROR_FAIL;
        }
        return target->type->soft_reset_halt_imp(target);
@@ -766,7 +766,7 @@ int target_init(struct command_context *cmd_ctx)
 
                if ((retval = target->type->init_target(cmd_ctx, target)) != ERROR_OK)
                {
-                       LOG_ERROR("target '%s' init failed", target_type_name(target));
+                       LOG_ERROR("target '%s' init failed", target_name(target));
                        return retval;
                }
 
@@ -1697,7 +1697,7 @@ DumpTargets:
                command_print(CMD_CTX, "%2d%c %-18s %-10s %-6s %-18s %s",
                                          target->target_number,
                                          marker,
-                                         target->cmd_name,
+                                         target_name(target),
                                          target_type_name(target),
                                          Jim_Nvp_value2name_simple(nvp_target_endian,
                                                                target->endianness)->name,
@@ -3510,7 +3510,7 @@ void target_handle_event(struct target *target, enum target_event e)
                if (teap->event == e) {
                        LOG_DEBUG("target: (%d) %s (%s) event: %d (%s) action: %s",
                                           target->target_number,
-                                          target->cmd_name,
+                                          target_name(target),
                                           target_type_name(target),
                                           e,
                                           Jim_Nvp_value2name_simple(nvp_target_event, e)->name,
@@ -4139,7 +4139,7 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                                || !target->type->deassert_reset) {
                        Jim_SetResult_sprintf(interp,
                                        "No target-specific reset for %s",
-                                       target->cmd_name);
+                                       target_name(target));
                        return JIM_ERR;
                }
                /* determine if we should halt or not. */
@@ -4183,10 +4183,9 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                e = target_wait_state(target, n->value, a);
                if (e != ERROR_OK) {
                        Jim_SetResult_sprintf(goi.interp,
-                                                                  "target: %s wait %s fails (%d) %s",
-                                                                  target->cmd_name,
-                                                                  n->name,
-                                                                  e, target_strerror_safe(e));
+                                       "target: %s wait %s fails (%d) %s",
+                                       target_name(target), n->name,
+                                       e, target_strerror_safe(e));
                        return JIM_ERR;
                } else {
                        return JIM_OK;
@@ -4198,9 +4197,10 @@ static int tcl_target_func(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                {
                        struct target_event_action *teap;
                        teap = target->event_action;
-                       command_print(cmd_ctx, "Event actions for target (%d) %s\n",
-                                                  target->target_number,
-                                                  target->cmd_name);
+                       command_print(cmd_ctx,
+                                       "Event actions for target (%d) %s\n",
+                                       target->target_number,
+                                       target_name(target));
                        command_print(cmd_ctx, "%-25s | Body", "Event");
                        command_print(cmd_ctx, "------------------------- | ----------------------------------------");
                        while (teap) {
@@ -4450,7 +4450,9 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                        Jim_WrongNumArgs(goi.interp, 1, goi.argv, "Too many parameters");
                        return JIM_ERR;
                }
-               Jim_SetResultString(goi.interp, get_current_target(cmd_ctx)->cmd_name, -1);
+               Jim_SetResultString(goi.interp,
+                               target_name(get_current_target(cmd_ctx)),
+                               -1);
                return JIM_OK;
        case TG_CMD_TYPES:
                if (goi.argc != 0) {
@@ -4473,8 +4475,9 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                target = all_targets;
                while (target) {
                        Jim_ListAppendElement(goi.interp,
-                                                                  Jim_GetResult(goi.interp),
-                                                                  Jim_NewStringObj(goi.interp, target->cmd_name, -1));
+                                       Jim_GetResult(goi.interp),
+                                       Jim_NewStringObj(goi.interp,
+                                               target_name(target), -1));
                        target = target->next;
                }
                return JIM_OK;
@@ -4505,7 +4508,7 @@ static int jim_target(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
                                        "Target: number %d does not exist", (int)(w));
                        return JIM_ERR;
                }
-               Jim_SetResultString(goi.interp, target->cmd_name, -1);
+               Jim_SetResultString(goi.interp, target_name(target), -1);
                return JIM_OK;
        case TG_CMD_COUNT:
                if (goi.argc != 0) {
index 61bc68aefd22d910b937142aa8998539c090dd78..15003c654288737d884c275a44be385b136369fa 100644 (file)
@@ -159,6 +159,12 @@ struct target
        long long halt_issued_time;                     /* Note time when halt was issued */
 };
 
+/** Returns the instance-specific name of the specified target. */
+static inline const char *target_name(struct target *target)
+{
+       return target->cmd_name;
+}
+
 enum target_event
 {
        /* LD historical names