X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgdb-server.c;h=b48f7d6d8256af38f9676c34aaf6f51968402ff6;hb=7c294cf6a19fa8c682138097381d3af80f1a9c80;hp=69ffdad61427c923278d0d5903bcf9fe7fdb18e0;hpb=a4ae2f66b628b9031a73964e7791fb7b2a2d2300;p=fw%2Fstlink diff --git a/src/gdb-server.c b/src/gdb-server.c index 69ffdad..b48f7d6 100644 --- a/src/gdb-server.c +++ b/src/gdb-server.c @@ -303,6 +303,12 @@ int serve(struct stlink* sl, int port) { printf("GDB connected.\n"); + /* + * To allow resetting the chip from GDB it is required to + * emulate attaching and detaching to target. + */ + unsigned int attached = 1; + while(1) { char* packet; @@ -389,16 +395,10 @@ int serve(struct stlink* sl, int port) { } case 'v': { - char *separator = strstr(packet, ":"), *params = ""; - if(separator == NULL) { - separator = packet + strlen(packet); - } else { - params = separator + 1; - } + char *params = NULL; + char *cmdName = strtok_r(packet, ":;", ¶ms); - unsigned cmdNameLength = (separator - &packet[1]); - char* cmdName = calloc(cmdNameLength + 1, 1); - strncpy(cmdName, &packet[1], cmdNameLength); + cmdName++; // vCommand -> Command if(!strcmp(cmdName, "FlashErase")) { char *s_addr, *s_length; @@ -463,13 +463,15 @@ int serve(struct stlink* sl, int port) { } else { reply = strdup("OK"); } + } else if(!strcmp(cmdName, "Kill")) { + attached = 0; + + reply = strdup("OK"); } if(reply == NULL) reply = strdup(""); - free(cmdName); - break; } @@ -506,7 +508,12 @@ int serve(struct stlink* sl, int port) { break; case '?': - reply = strdup("S05"); // TRAP + if(attached) { + reply = strdup("S05"); // TRAP + } else { + /* Stub shall reply OK if not attached. */ + reply = strdup("OK"); + } break; case 'g': @@ -644,12 +651,28 @@ int serve(struct stlink* sl, int port) { break; } - case 'k': { - // After this function will be entered afterwards, the - // chip will be reset anyway. So this is a no-op. + case '!': { + /* + * Enter extended mode which allows restarting. + * We do support that always. + */ + + reply = strdup("OK"); + + break; + } + + case 'R': { + /* Reset the core. */ + + stlink_reset(sl); + init_code_breakpoints(sl); + + attached = 1; - close(client); - return 0; + reply = strdup("OK"); + + break; } default: