]> git.sur5r.net Git - openocd/commitdiff
Clear all dangling breakpoints upon GDB connection.
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 13 Aug 2008 15:05:15 +0000 (15:05 +0000)
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 13 Aug 2008 15:05:15 +0000 (15:05 +0000)
git-svn-id: svn://svn.berlios.de/openocd/trunk@912 b42882b7-edfa-0310-969c-e2dbd0fdcd60

src/server/gdb_server.c
src/target/breakpoints.c
src/target/breakpoints.h

index 59ce46472b240a90ee5686c3104530688fd6e265..3f346584efa724125b1a3e4ed3e2d321220101ed 100644 (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);
 
index 3a735497eebe408c7fa4a9a43cdb52efdd2b5c0c..4a949cca700c1e7a29aab5673a5b7548e241a9df 100644 (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);
+       }
+}
index 7eba39aa3c1abaa04f9be136561500656107a541..18ad8d3cc97a2d4e99f7688b7fe06e6a6412a8ce 100644 (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 */