Clear all dangling breakpoints upon GDB connection.

git-svn-id: svn://svn.berlios.de/openocd/trunk@912 b42882b7-edfa-0310-969c-e2dbd0fdcd60
This commit is contained in:
oharboe 2008-08-13 15:05:15 +00:00
parent fbb46cfaff
commit a71ca65c53
3 changed files with 77 additions and 38 deletions

View File

@ -668,6 +668,13 @@ int gdb_new_connection(connection_t *connection)
/* output goes through gdb connection */
command_set_output_handler(connection->cmd_ctx, gdb_output, connection);
/* we must remove all breakpoints registered to the target as a previous
* GDB session could leave dangling breakpoints if e.g. communication
* timed out.
*/
breakpoint_clear_target(gdb_service->target);
watchpoint_clear_target(gdb_service->target);
/* register callback to be informed about target events */
target_register_event_callback(gdb_target_callback_event_handler, connection);

View File

@ -48,7 +48,7 @@ int breakpoint_add(target_t *target, u32 address, u32 length, enum breakpoint_ty
breakpoint_t *breakpoint = target->breakpoints;
breakpoint_t **breakpoint_p = &target->breakpoints;
int retval;
while (breakpoint)
{
if (breakpoint->address == address)
@ -84,8 +84,6 @@ int breakpoint_add(target_t *target, u32 address, u32 length, enum breakpoint_ty
return retval;
break;
default:
LOG_ERROR("unknown error");
exit(-1);
break;
}
}
@ -97,11 +95,34 @@ int breakpoint_add(target_t *target, u32 address, u32 length, enum breakpoint_ty
return ERROR_OK;
}
/* free up a breakpoint */
static void breakpoint_free(target_t *target, breakpoint_t *breakpoint_remove)
{
breakpoint_t *breakpoint = target->breakpoints;
breakpoint_t **breakpoint_p = &target->breakpoints;
while (breakpoint)
{
if (breakpoint==breakpoint_remove)
break;
breakpoint_p = &breakpoint->next;
breakpoint = breakpoint->next;
}
if (breakpoint==NULL)
return;
target->type->remove_breakpoint(target, breakpoint);
(*breakpoint_p) = breakpoint->next;
free(breakpoint->orig_instr);
free(breakpoint);
}
int breakpoint_remove(target_t *target, u32 address)
{
breakpoint_t *breakpoint = target->breakpoints;
breakpoint_t **breakpoint_p = &target->breakpoints;
int retval;
while (breakpoint)
{
@ -113,23 +134,7 @@ int breakpoint_remove(target_t *target, u32 address)
if (breakpoint)
{
if ((retval = target->type->remove_breakpoint(target, breakpoint)) != ERROR_OK)
{
switch (retval)
{
case ERROR_TARGET_NOT_HALTED:
LOG_INFO("can't remove breakpoint while target is running");
return retval;
break;
default:
LOG_ERROR("unknown error");
exit(-1);
break;
}
}
(*breakpoint_p) = breakpoint->next;
free(breakpoint->orig_instr);
free(breakpoint);
breakpoint_free(target, breakpoint);
}
else
{
@ -139,6 +144,15 @@ int breakpoint_remove(target_t *target, u32 address)
return ERROR_OK;
}
void breakpoint_clear_target(target_t *target)
{
breakpoint_t *breakpoint;
while ((breakpoint = target->breakpoints)!=NULL)
{
breakpoint_free(target, breakpoint);
}
}
breakpoint_t* breakpoint_find(target_t *target, u32 address)
{
breakpoint_t *breakpoint = target->breakpoints;
@ -206,11 +220,32 @@ int watchpoint_add(target_t *target, u32 address, u32 length, enum watchpoint_rw
return ERROR_OK;
}
static void watchpoint_free(target_t *target, watchpoint_t *watchpoint_remove)
{
watchpoint_t *watchpoint = target->watchpoints;
watchpoint_t **watchpoint_p = &target->watchpoints;
while (watchpoint)
{
if (watchpoint == watchpoint_remove)
break;
watchpoint_p = &watchpoint->next;
watchpoint = watchpoint->next;
}
if (watchpoint==NULL)
return;
target->type->remove_watchpoint(target, watchpoint);
(*watchpoint_p) = watchpoint->next;
free(watchpoint);
}
int watchpoint_remove(target_t *target, u32 address)
{
watchpoint_t *watchpoint = target->watchpoints;
watchpoint_t **watchpoint_p = &target->watchpoints;
int retval;
while (watchpoint)
{
@ -222,22 +257,7 @@ int watchpoint_remove(target_t *target, u32 address)
if (watchpoint)
{
if ((retval = target->type->remove_watchpoint(target, watchpoint)) != ERROR_OK)
{
switch (retval)
{
case ERROR_TARGET_NOT_HALTED:
LOG_INFO("can't remove watchpoint while target is running");
return retval;
break;
default:
LOG_ERROR("unknown error");
exit(-1);
break;
}
}
(*watchpoint_p) = watchpoint->next;
free(watchpoint);
watchpoint_free(target, watchpoint);
}
else
{
@ -246,3 +266,13 @@ int watchpoint_remove(target_t *target, u32 address)
return ERROR_OK;
}
void watchpoint_clear_target(target_t *target)
{
watchpoint_t *watchpoint;
while ((watchpoint = target->watchpoints)!=NULL)
{
watchpoint_free(target, watchpoint);
}
}

View File

@ -60,11 +60,13 @@ typedef struct watchpoint_s
struct watchpoint_s *next;
} watchpoint_t;
extern void breakpoint_clear_target(struct target_s *target);
extern int breakpoint_add(struct target_s *target, u32 address, u32 length, enum breakpoint_type type);
extern int breakpoint_remove(struct target_s *target, u32 address);
extern breakpoint_t* breakpoint_find(struct target_s *target, u32 address);
extern int watchpoint_add(struct target_s *target, u32 address, u32 length, enum watchpoint_rw rw, u32 value, u32 mask);
extern int watchpoint_remove(struct target_s *target, u32 address);
extern void watchpoint_clear_target(struct target_s *target);
#endif /* BREAKPOINTS_H */