gdb: fix occasional crash when flash probe failed
authorØyvind Harboe <oyvind.harboe@zylin.com>
Sat, 13 Nov 2010 12:03:29 +0000 (13:03 +0100)
committerØyvind Harboe <oyvind.harboe@zylin.com>
Mon, 15 Nov 2010 08:14:05 +0000 (09:14 +0100)
Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com>
src/server/gdb_server.c

index 9503a130a6cfb7b1b9e43c78abe7d2a91657bc22..77142dfadec8acfd5c2ebf41560cd491ded3ca38 100644 (file)
@@ -833,9 +833,6 @@ static int gdb_new_connection(struct connection *connection)
        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);
-
        /* remove the initial ACK from the incoming buffer */
        if ((retval = gdb_get_char(connection, &initial_ack)) != ERROR_OK)
                return retval;
@@ -873,6 +870,13 @@ static int gdb_new_connection(struct connection *connection)
                  target_name(gdb_service->target),
                  target_state_name(gdb_service->target));
 
+       /* DANGER! If we fail subsequently, we must remove this handler,
+        * otherwise we occasionally see crashes as the timer can invoke the
+        * callback fn.
+        *
+        * register callback to be informed about target events */
+       target_register_event_callback(gdb_target_callback_event_handler, connection);
+
        return ERROR_OK;
 }