Add target_get_name wrapper:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Sun, 31 May 2009 11:31:27 +0000 (11:31 +0000)
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Sun, 31 May 2009 11:31:27 +0000 (11:31 +0000)
- replaces all accesses to target->type->name.
- add documentation in target_s to warn not to access field directly.

git-svn-id: svn://svn.berlios.de/openocd/trunk@1966 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/server/gdb_server.c
src/target/arm11.c
src/target/embeddedice.c
src/target/target.c
src/target/target.h

index 23748e7c654c502190cffa246349a7979ccdff7c..d5c3f3510ae9104097eba4de1898424403a1f169 100644 (file)
@@ -2211,7 +2211,8 @@ 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);
+               LOG_DEBUG("gdb service for target %s using pipes",
+                               target_get_name(target));
        }
        else
        {
@@ -2222,7 +2223,9 @@ int gdb_init(void)
 
                        add_service("gdb", CONNECTION_TCP, gdb_port + target->target_number, 1, gdb_new_connection, gdb_input, gdb_connection_closed, gdb_service);
 
-                       LOG_DEBUG("gdb service for target %s at port %i", target->type->name, gdb_port + target->target_number);
+                       LOG_DEBUG("gdb service for target %s at port %i",
+                                       target_get_name(target),
+                                       gdb_port + target->target_number);
                        target = target->next;
                }
        }
index 0dc6bf4761607a23e8356cb8030eda8c7e8622b3..15557327055962cd2d7bef4d739ca4d1f0432bb7 100644 (file)
@@ -1847,7 +1847,7 @@ arm11_common_t * arm11_find_target(const char * arg)
                        continue;
 
                /* if (t->type == arm11_target) */
-               if (0 == strcmp(t->type->name, "arm11"))
+               if (0 == strcmp(target_get_name(t), "arm11"))
                        return t->arch_info;
        }
 
index 9d2be364dbe11045836d46aa8ceecf1255cb6e94..d96debd0570af80f3a814b4816bdeb3ddf43c44b 100644 (file)
@@ -184,7 +184,7 @@ reg_cache_t* embeddedice_build_reg_cache(target_t *target, arm7_9_common_t *arm7
                         * in some unusual bits.  Let feroceon.c validate it
                         * and do the appropriate setup itself.
                         */
-                       if (strcmp(target->type->name, "feroceon") == 0)
+                       if (strcmp(target_get_name(target), "feroceon") == 0)
                                break;
                        LOG_ERROR("unknown EmbeddedICE version (comms ctrl: 0x%8.8x)", buf_get_u32(reg_list[EICE_COMMS_CTRL].value, 0, 32));
        }
index 993b8c61353c542b050ee89ac701cf2ea814f6b8..a54e0654b02384354f824d1b4e7baf919cd4d10e 100644 (file)
@@ -484,6 +484,10 @@ int target_examine(void)
        }
        return retval;
 }
+const char *target_get_name(struct target_s *target)
+{
+       return target->type->name;
+}
 
 static int target_write_memory_imp(struct target_s *target, u32 address, u32 size, u32 count, u8 *buffer)
 {
@@ -598,7 +602,7 @@ int target_init(struct command_context_s *cmd_ctx)
 
                if ((retval = target->type->init_target(cmd_ctx, target)) != ERROR_OK)
                {
-                       LOG_ERROR("target '%s' init failed", target->type->name);
+                       LOG_ERROR("target '%s' init failed", target_get_name(target));
                        return retval;
                }
 
@@ -1451,7 +1455,7 @@ DumpTargets:
                command_print(cmd_ctx, "%2d: %-10s %-10s %-10s %10d %14s %s",
                                          target->target_number,
                                          target->cmd_name,
-                                         target->type->name,
+                                         target_get_name(target),
                                          Jim_Nvp_value2name_simple( nvp_target_endian, target->endianness )->name,
                                          target->tap->abs_chain_position,
                                          target->tap->dotted_name,
@@ -3131,7 +3135,7 @@ void target_handle_event( target_t *target, enum target_event e )
                        LOG_DEBUG( "target: (%d) %s (%s) event: %d (%s) action: %s\n",
                                           target->target_number,
                                           target->cmd_name,
-                                          target->type->name,
+                                          target_get_name(target),
                                           e,
                                           Jim_Nvp_value2name_simple( nvp_target_event, e )->name,
                                           Jim_GetString( teap->body, NULL ) );
@@ -3220,7 +3224,7 @@ static int target_configure( Jim_GetOptInfo *goi, target_t *target )
                                        return JIM_ERR;
                                }
                        }
-                       Jim_SetResultString( goi->interp, target->type->name, -1 );
+                       Jim_SetResultString( goi->interp, target_get_name(target), -1 );
                        /* loop for more */
                        break;
                case TCFG_EVENT:
index 3d9d8e9f90c348afcd0efde88b4788026be0c0b3..91dd1b15422f4a7dfe1ca9ba8838147bfeb6fb03 100644 (file)
@@ -107,6 +107,10 @@ typedef struct working_area_s
 
 typedef struct target_type_s
 {
+       /**
+        * Name of the target.  Do @b not access this field directly, use
+        * target_get_name() instead.
+        */
        char *name;
 
        /**
@@ -395,6 +399,13 @@ extern target_t* get_current_target(struct command_context_s *cmd_ctx);
 extern int get_num_by_target(target_t *query_target);
 extern target_t *get_target(const char *id);
 
+/**
+ * Get the target name.
+ *
+ * This routine is a wrapper for the target->type->name field.
+ */
+extern const char *target_get_name(struct target_s *target);
+
 /// @returns @c true if the target has been examined.
 extern bool target_was_examined(struct target_s *target);
 /// Sets the @c examined flag for the given target.