If halt times out, stop GDB. Allows e.g. manual reset via monitor commands.
[fw/openocd] / src / server / gdb_server.c
index 44d9de8381222f8454428a8d6107d915838702f5..ad09a0e704624a47d605b3d3afdf5a9174b062f2 100644 (file)
@@ -714,7 +714,7 @@ int gdb_target_callback_event_handler(struct target_s *target, enum target_event
        target_handle_event(target, event);
        switch (event)
        {
-               case TARGET_EVENT_EARLY_HALTED:
+               case TARGET_EVENT_GDB_HALT:
                        gdb_frontend_halted(target, connection);
                        break;
                case TARGET_EVENT_HALTED:
@@ -2191,8 +2191,16 @@ int gdb_input_inner(connection_t *connection)
                {
                        if (target->state == TARGET_RUNNING)
                        {
-                               target_halt(target);
+                               retval = target_halt(target);
+                               if (retval != ERROR_OK)
+                               {
+                                       target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
+                               }
                                gdb_con->ctrl_c = 0;
+                       } else
+                       {
+                               LOG_INFO("The target is not running when halt was requested, stopping GDB.");
+                               target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
                        }
                }