Commit c312e663040208d69efc4c7e0687f0f55eee56c0
authorhovercraft-github <hovercraft@yandex.ru>
Thu, 20 Oct 2016 04:20:35 +0000 (12:20 +0800)
committerhovercraft-github <hovercraft@yandex.ru>
Thu, 20 Oct 2016 04:20:35 +0000 (12:20 +0800)
simavr/sim/sim_gdb.c

index f2c2b42f91029b4c32f599dfd68ad945e85355e9..ce5e0f6024b3707f7d083a4a99cf2557c32971dd 100644 (file)
@@ -301,9 +301,10 @@ gdb_handle_command(
                                 */
                                gdb_send_reply(g, "1");
                                break;
-                       } else if (strncmp(cmd, "Offsets", 7) == 0) {
-                               gdb_send_reply(g, "Text=0;Data=800000;Bss=800000");
-                               break;
+                       // Rmoving the following 3 lines fixes #150 issue:
+                       // } else if (strncmp(cmd, "Offsets", 7) == 0) {
+                       //      gdb_send_reply(g, "Text=0;Data=800000;Bss=800000");
+                       //      break;
                        } else if (strncmp(cmd, "Xfer:memory-map:read", 20) == 0) {
                                snprintf(rep, sizeof(rep),
                                                "l<memory-map>\n"
@@ -616,6 +617,9 @@ int
 avr_gdb_init(
                avr_t * avr )
 {
+       if (avr->gdb)
+               return 0; // GDB server already is active
+
        avr_gdb_t * g = malloc(sizeof(avr_gdb_t));
        memset(g, 0, sizeof(avr_gdb_t));
 
@@ -656,20 +660,30 @@ avr_gdb_init(
        
        return 0;
 
-       error:
-               free(g);
-               return -1;
+error:
+       if (g->listen >= 0)
+               close(g->listen);
+       free(g);
+
+       return -1;
 }
 
 void 
 avr_deinit_gdb(
                avr_t * avr )
 {
+       if (!avr->gdb)
+               return;
+       avr->run = avr_callback_run_raw; // restore normal callbacks
+       avr->sleep = avr_callback_sleep_raw;
        if (avr->gdb->listen != -1)
-          close(avr->gdb->listen);
+               close(avr->gdb->listen);
+       avr->gdb->listen = -1;
        if (avr->gdb->s != -1)
-          close(avr->gdb->s);
+               close(avr->gdb->s);
+       avr->gdb->s = -1;
        free(avr->gdb);
+       avr->gdb = NULL;
 
        network_release();
 }