Commit 7fd9ba22 authored by oharboe's avatar oharboe
Browse files

Centralize error handling for buggy register handling

git-svn-id: svn://svn.berlios.de/openocd/trunk@1019 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent 7b369df5
......@@ -936,11 +936,7 @@ int gdb_set_registers_packet(connection_t *connection, target_t *target, char *p
/* get register arch_type, and call set method */
arch_type = register_get_arch_type(reg_list[i]->arch_type);
if (arch_type == NULL)
{
LOG_ERROR("BUG: encountered unregistered arch type");
exit(-1);
}
arch_type->set(reg_list[i], bin_buf);
/* advance packet pointer */
......@@ -1033,11 +1029,6 @@ int gdb_set_register_packet(connection_t *connection, target_t *target, char *pa
/* get register arch_type, and call set method */
arch_type = register_get_arch_type(reg_list[reg_num]->arch_type);
if (arch_type == NULL)
{
LOG_ERROR("BUG: encountered unregistered arch type");
exit(-1);
}
arch_type->set(reg_list[reg_num], bin_buf);
gdb_put_packet(connection, "OK", 2);
......
......@@ -35,7 +35,7 @@ reg_t* register_get_by_name(reg_cache_t *first, char *name, int search_all)
{
int i;
reg_cache_t *cache = first;
while (cache)
{
for (i = 0; i < cache->num_regs; i++)
......@@ -43,26 +43,26 @@ reg_t* register_get_by_name(reg_cache_t *first, char *name, int search_all)
if (strcmp(cache->reg_list[i].name, name) == 0)
return &(cache->reg_list[i]);
}
if (search_all)
cache = cache->next;
else
break;
}
return NULL;
}
reg_cache_t** register_get_last_cache_p(reg_cache_t **first)
{
reg_cache_t **cache_p = first;
if (*cache_p)
while (*cache_p)
cache_p = &((*cache_p)->next);
else
return first;
return cache_p;
}
......@@ -70,7 +70,7 @@ int register_reg_arch_type(int (*get)(reg_t *reg), int (*set)(reg_t *reg, u8 *bu
{
reg_arch_type_t** arch_type_p = &reg_arch_types;
int id = 0;
if (*arch_type_p)
{
while (*arch_type_p)
......@@ -79,26 +79,27 @@ int register_reg_arch_type(int (*get)(reg_t *reg), int (*set)(reg_t *reg, u8 *bu
arch_type_p = &((*arch_type_p)->next);
}
}
(*arch_type_p) = malloc(sizeof(reg_arch_type_t));
(*arch_type_p)->id = id + 1;
(*arch_type_p)->set = set;
(*arch_type_p)->get = get;
(*arch_type_p)->next = NULL;
return id + 1;
}
reg_arch_type_t* register_get_arch_type(int id)
{
reg_arch_type_t *arch_type = reg_arch_types;
while (arch_type)
{
if (arch_type->id == id)
return arch_type;
arch_type = arch_type->next;
}
LOG_ERROR("BUG: encountered unregistered arch type 0x%08x", id);
exit(-1);
return NULL;
}
......@@ -1212,7 +1212,7 @@ int target_checksum_memory(struct target_s *target, u32 address, u32 size, u32*
}
if ((retval = target->type->checksum_memory(target, address,
size, &checksum)) == ERROR_TARGET_RESOURCE_NOT_AVAILABLE)
size, &checksum)) != ERROR_OK)
{
buffer = malloc(size);
if (buffer == NULL)
......@@ -1625,11 +1625,6 @@ int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char **args
if (reg->valid == 0)
{
reg_arch_type_t *arch_type = register_get_arch_type(reg->arch_type);
if (arch_type == NULL)
{
LOG_ERROR("BUG: encountered unregistered arch type");
return ERROR_OK;
}
arch_type->get(reg);
}
value = buf_to_str(reg->value, reg->size, 16);
......@@ -1645,12 +1640,6 @@ int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char **args
str_to_buf(args[1], strlen(args[1]), buf, reg->size, 0);
reg_arch_type_t *arch_type = register_get_arch_type(reg->arch_type);
if (arch_type == NULL)
{
LOG_ERROR("BUG: encountered unregistered arch type");
return ERROR_OK;
}
arch_type->set(reg, buf);
value = buf_to_str(reg->value, reg->size, 16);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment