]> git.sur5r.net Git - openocd/blobdiff - src/target/breakpoints.c
marked infinite loop in code w/TODO and fixed warning.
[openocd] / src / target / breakpoints.c
index 8b140b3e98ea4176d8dd1dfba83be985512234f9..f52ff3067a11a9c83c4ad46e789c120326907141 100644 (file)
@@ -62,7 +62,7 @@ int breakpoint_add(target_t *target, u32 address, u32 length, enum breakpoint_ty
        (*breakpoint_p)->length = length;
        (*breakpoint_p)->type = type;
        (*breakpoint_p)->set = 0;
-       (*breakpoint_p)->orig_instr = malloc(CEIL(length, 8));
+       (*breakpoint_p)->orig_instr = malloc(length);
        (*breakpoint_p)->next = NULL;
        
        if ((retval = target->type->add_breakpoint(target, *breakpoint_p)) != ERROR_OK)
@@ -71,13 +71,15 @@ int breakpoint_add(target_t *target, u32 address, u32 length, enum breakpoint_ty
                {
                        case ERROR_TARGET_RESOURCE_NOT_AVAILABLE:
                                INFO("can't add %s breakpoint, resource not available", breakpoint_type_strings[(*breakpoint_p)->type]);
-                               free (*breakpoint_p);
+                               free((*breakpoint_p)->orig_instr);
+                               free(*breakpoint_p);
                                *breakpoint_p = NULL;
                                return retval;
                                break;
                        case ERROR_TARGET_NOT_HALTED:
                                INFO("can't add breakpoint while target is running");
-                               free (*breakpoint_p);
+                               free((*breakpoint_p)->orig_instr);
+                               free(*breakpoint_p);
                                *breakpoint_p = NULL;
                                return retval;
                                break;
@@ -222,8 +224,17 @@ int watchpoint_remove(target_t *target, u32 address)
        {
                if ((retval = target->type->remove_watchpoint(target, watchpoint)) != ERROR_OK)
                {
-                       ERROR("BUG: can't remove watchpoint");
-                       exit(-1);
+                       switch (retval)
+                       {
+                               case ERROR_TARGET_NOT_HALTED:
+                                       INFO("can't remove watchpoint while target is running");
+                                       return retval;
+                                       break;
+                               default:
+                                       ERROR("unknown error");
+                                       exit(-1);
+                                       break;
+                       }
                }
                (*watchpoint_p) = watchpoint->next;
                free(watchpoint);