1 /* -*- tab-width:8 -*- */
4 Copyright (C) 2011 Peter Zotov <whitequark@whitequark.org>
5 Use of this source code is governed by a BSD-style
6 license that can be found in the LICENSE file.
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
18 #include <stlink-common.h>
20 #include "gdb-remote.h"
22 #define FLASH_BASE 0x08000000
23 #define FLASH_PAGE (sl->flash_pgsz)
24 #define FLASH_PAGE_MASK (~((1 << 10) - 1))
25 #define FLASH_SIZE (FLASH_PAGE * 128)
27 static const char hex[] = "0123456789abcdef";
29 static const char* current_memory_map = NULL;
32 * Chip IDs are explained in the appropriate programming manual for the
33 * DBGMCU_IDCODE register (0xE0042000)
38 uint32_t flash_size_reg;
39 uint32_t max_flash_size, flash_pagesize;
41 uint32_t bootrom_base, bootrom_size;
43 { 0x410, "F1 Medium-density device", 0x1ffff7e0,
44 0x20000, 0x400, 0x5000, 0x1ffff000, 0x800 }, // table 2, pm0063
45 { 0x411, "F2 device", 0, /* No flash size register found in the docs*/
46 0x100000, 0x20000, 0x20000, 0x1ff00000, 0x7800 }, // table 1, pm0059
47 { 0x412, "F1 Low-density device", 0x1ffff7e0,
48 0x8000, 0x400, 0x2800, 0x1ffff000, 0x800 }, // table 1, pm0063
49 { 0x413, "F4 device", 0x1FFF7A10,
50 0x100000, 0x20000, 0x20000, 0x1ff00000, 0x7800 }, // table 1, pm0081
51 { 0x414, "F1 High-density device", 0x1ffff7e0,
52 0x80000, 0x800, 0x10000, 0x1ffff000, 0x800 }, // table 3 pm0063
53 // This ignores the EEPROM! (and uses the page erase size,
54 // not the sector write protection...)
55 { 0x416, "L1 Med-density device", 0x1FF8004C, // table 1, pm0062
56 0x20000, 0x100, 0x4000, 0x1ff00000, 0x1000 },
57 { 0x418, "F1 Connectivity line device", 0x1ffff7e0,
58 0x40000, 0x800, 0x10000, 0x1fffb000, 0x4800 },
59 { 0x420, "F1 Medium-density value line device", 0x1ffff7e0,
60 0x20000, 0x400, 0x2000, 0x1ffff000, 0x800 },
61 { 0x428, "F1 High-density value line device", 0x1ffff7e0,
62 0x80000, 0x800, 0x8000, 0x1ffff000, 0x800 },
63 { 0x430, "F1 XL-density device", 0x1ffff7e0, // pm0068
64 0x100000, 0x800, 0x18000, 0x1fffe000, 0x1800 },
68 int serve(stlink_t *sl, int port);
69 char* make_memory_map(const struct chip_params *params, uint32_t flash_size);
71 int main(int argc, char** argv) {
75 const char * HelpStr = "Usage:\n"
76 "\t st-util port [/dev/sgX]\n"
78 "\t st-util --help\n";
83 fprintf(stderr, HelpStr, NULL);
88 //sl = stlink_quirk_open(argv[2], 0);
89 // FIXME - hardcoded to usb....
90 sl = stlink_open_usb(argv[2], 10);
91 if(sl == NULL) return 1;
96 if (strcmp(argv[1], "--help") == 0) {
97 fprintf(stdout, HelpStr, NULL);
102 case 1 : { // Search ST-LINK (from /dev/sg0 to /dev/sg99)
103 const int DevNumMax = 99;
104 int ExistDevCount = 0;
106 for(int DevNum = 0; DevNum <= DevNumMax; DevNum++)
109 char DevName[] = "/dev/sgX";
110 const int X_index = 7;
111 DevName[X_index] = DevNum + '0';
112 if ( !access(DevName, F_OK) ) {
113 sl = stlink_quirk_open(DevName, 0);
117 else if(DevNum < 100) {
118 char DevName[] = "/dev/sgXY";
119 const int X_index = 7;
120 const int Y_index = 8;
121 DevName[X_index] = DevNum/10 + '0';
122 DevName[Y_index] = DevNum%10 + '0';
123 if ( !access(DevName, F_OK) ) {
124 sl = stlink_quirk_open(DevName, 0);
128 if(sl != NULL) break;
132 fprintf(stdout, "\nNumber of /dev/sgX devices found: %i \n",
134 fprintf(stderr, "ST-LINK not found\n");
141 if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) {
142 stlink_exit_dfu_mode(sl);
145 if(stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) {
146 stlink_enter_swd_mode(sl);
149 uint32_t chip_id = stlink_chip_id(sl);
150 printf("Chip ID is %08x.\n", chip_id);
152 const struct chip_params* params = NULL;
154 for(int i = 0; i < sizeof(devices) / sizeof(devices[0]); i++) {
155 if(devices[i].chip_id == (chip_id & 0xFFF)) {
156 params = &devices[i];
162 fprintf(stderr, "Cannot recognize the connected device!\n");
166 printf("Device connected: %s\n", params->description);
167 printf("Device parameters: SRAM: 0x%x bytes, Flash: up to 0x%x bytes in pages of 0x%x bytes\n",
168 params->sram_size, params->max_flash_size, params->flash_pagesize);
170 FLASH_PAGE = params->flash_pagesize;
174 stlink_read_mem32(sl, params->flash_size_reg, 4);
175 flash_size = sl->q_buf[0] | (sl->q_buf[1] << 8);
177 printf("Flash size is %d KiB.\n", flash_size);
178 // memory map is in 1k blocks.
179 current_memory_map = make_memory_map(params, flash_size * 0x400);
183 while(serve(sl, port) == 0);
190 static const char* const memory_map_template =
191 "<?xml version=\"1.0\"?>"
192 "<!DOCTYPE memory-map PUBLIC \"+//IDN gnu.org//DTD GDB Memory Map V1.0//EN\""
193 " \"http://sourceware.org/gdb/gdb-memory-map.dtd\">"
195 " <memory type=\"rom\" start=\"0x00000000\" length=\"0x%x\"/>" // code = sram, bootrom or flash; flash is bigger
196 " <memory type=\"ram\" start=\"0x20000000\" length=\"0x%x\"/>" // sram 8k
197 " <memory type=\"flash\" start=\"0x08000000\" length=\"0x%x\">"
198 " <property name=\"blocksize\">0x%x</property>"
200 " <memory type=\"ram\" start=\"0x40000000\" length=\"0x1fffffff\"/>" // peripheral regs
201 " <memory type=\"ram\" start=\"0xe0000000\" length=\"0x1fffffff\"/>" // cortex regs
202 " <memory type=\"rom\" start=\"0x%08x\" length=\"0x%x\"/>" // bootrom
203 " <memory type=\"rom\" start=\"0x1ffff800\" length=\"0x8\"/>" // option byte area
206 char* make_memory_map(const struct chip_params *params, uint32_t flash_size) {
207 /* This will be freed in serve() */
208 char* map = malloc(4096);
211 snprintf(map, 4096, memory_map_template,
214 flash_size, params->flash_pagesize,
215 params->bootrom_base, params->bootrom_size);
222 * DWT_COMP0 0xE0001020
223 * DWT_MASK0 0xE0001024
224 * DWT_FUNCTION0 0xE0001028
225 * DWT_COMP1 0xE0001030
226 * DWT_MASK1 0xE0001034
227 * DWT_FUNCTION1 0xE0001038
228 * DWT_COMP2 0xE0001040
229 * DWT_MASK2 0xE0001044
230 * DWT_FUNCTION2 0xE0001048
231 * DWT_COMP3 0xE0001050
232 * DWT_MASK3 0xE0001054
233 * DWT_FUNCTION3 0xE0001058
236 #define DATA_WATCH_NUM 4
238 enum watchfun { WATCHDISABLED = 0, WATCHREAD = 5, WATCHWRITE = 6, WATCHACCESS = 7 };
240 struct code_hw_watchpoint {
246 struct code_hw_watchpoint data_watches[DATA_WATCH_NUM];
248 static void init_data_watchpoints(stlink_t *sl) {
250 printf("init watchpoints\n");
253 // set trcena in debug command to turn on dwt unit
254 stlink_read_mem32(sl, 0xE000EDFC, 4);
256 stlink_write_mem32(sl, 0xE000EDFC, 4);
258 // make sure all watchpoints are cleared
259 memset(sl->q_buf, 0, 4);
260 for(int i = 0; i < DATA_WATCH_NUM; i++) {
261 data_watches[i].fun = WATCHDISABLED;
262 stlink_write_mem32(sl, 0xe0001028 + i * 16, 4);
266 static int add_data_watchpoint(stlink_t *sl, enum watchfun wf, stm32_addr_t addr, unsigned int len)
272 // find a free watchpoint
282 if((mask != -1) && (mask < 16)) {
283 for(i = 0; i < DATA_WATCH_NUM; i++) {
284 // is this an empty slot ?
285 if(data_watches[i].fun == WATCHDISABLED) {
287 printf("insert watchpoint %d addr %x wf %u mask %u len %d\n", i, addr, wf, mask, len);
290 data_watches[i].fun = wf;
291 data_watches[i].addr = addr;
292 data_watches[i].mask = mask;
294 // insert comparator address
295 sl->q_buf[0] = (addr & 0xff);
296 sl->q_buf[1] = ((addr >> 8) & 0xff);
297 sl->q_buf[2] = ((addr >> 16) & 0xff);
298 sl->q_buf[3] = ((addr >> 24) & 0xff);
300 stlink_write_mem32(sl, 0xE0001020 + i * 16, 4);
303 memset(sl->q_buf, 0, 4);
305 stlink_write_mem32(sl, 0xE0001024 + i * 16, 4);
308 memset(sl->q_buf, 0, 4);
310 stlink_write_mem32(sl, 0xE0001028 + i * 16, 4);
312 // just to make sure the matched bit is clear !
313 stlink_read_mem32(sl, 0xE0001028 + i * 16, 4);
320 printf("failure: add watchpoints addr %x wf %u len %u\n", addr, wf, len);
325 static int delete_data_watchpoint(stlink_t *sl, stm32_addr_t addr)
329 for(i = 0 ; i < DATA_WATCH_NUM; i++) {
330 if((data_watches[i].addr == addr) && (data_watches[i].fun != WATCHDISABLED)) {
332 printf("delete watchpoint %d addr %x\n", i, addr);
335 memset(sl->q_buf, 0, 4);
336 data_watches[i].fun = WATCHDISABLED;
337 stlink_write_mem32(sl, 0xe0001028 + i * 16, 4);
344 printf("failure: delete watchpoint addr %x\n", addr);
350 #define CODE_BREAK_NUM 6
351 #define CODE_BREAK_LOW 0x01
352 #define CODE_BREAK_HIGH 0x02
354 struct code_hw_breakpoint {
359 struct code_hw_breakpoint code_breaks[CODE_BREAK_NUM];
361 static void init_code_breakpoints(stlink_t *sl) {
362 memset(sl->q_buf, 0, 4);
363 sl->q_buf[0] = 0x03; // KEY | ENABLE
364 stlink_write_mem32(sl, CM3_REG_FP_CTRL, 4);
365 printf("KARL - should read back as 0x03, not 60 02 00 00\n");
366 stlink_read_mem32(sl, CM3_REG_FP_CTRL, 4);
368 memset(sl->q_buf, 0, 4);
369 for(int i = 0; i < CODE_BREAK_NUM; i++) {
370 code_breaks[i].type = 0;
371 stlink_write_mem32(sl, CM3_REG_FP_COMP0 + i * 4, 4);
375 static int update_code_breakpoint(stlink_t *sl, stm32_addr_t addr, int set) {
376 stm32_addr_t fpb_addr = addr & ~0x3;
377 int type = addr & 0x2 ? CODE_BREAK_HIGH : CODE_BREAK_LOW;
380 fprintf(stderr, "update_code_breakpoint: unaligned address %08x\n", addr);
385 for(int i = 0; i < CODE_BREAK_NUM; i++) {
386 if(fpb_addr == code_breaks[i].addr ||
387 (set && code_breaks[i].type == 0)) {
394 if(set) return -1; // Free slot not found
395 else return 0; // Breakpoint is already removed
398 struct code_hw_breakpoint* brk = &code_breaks[id];
400 brk->addr = fpb_addr;
402 if(set) brk->type |= type;
403 else brk->type &= ~type;
405 memset(sl->q_buf, 0, 4);
409 printf("clearing hw break %d\n", id);
412 stlink_write_mem32(sl, 0xe0002008 + id * 4, 4);
414 sl->q_buf[0] = ( brk->addr & 0xff) | 1;
415 sl->q_buf[1] = ((brk->addr >> 8) & 0xff);
416 sl->q_buf[2] = ((brk->addr >> 16) & 0xff);
417 sl->q_buf[3] = ((brk->addr >> 24) & 0xff) | (brk->type << 6);
420 printf("setting hw break %d at %08x (%d)\n",
421 id, brk->addr, brk->type);
422 printf("reg %02x %02x %02x %02x\n",
423 sl->q_buf[3], sl->q_buf[2], sl->q_buf[1], sl->q_buf[0]);
426 stlink_write_mem32(sl, 0xe0002008 + id * 4, 4);
438 struct flash_block* next;
441 static struct flash_block* flash_root;
443 static int flash_add_block(stm32_addr_t addr, unsigned length,
445 if(addr < FLASH_BASE || addr + length > FLASH_BASE + FLASH_SIZE) {
446 fprintf(stderr, "flash_add_block: incorrect bounds\n");
450 if(addr % FLASH_PAGE != 0 || length % FLASH_PAGE != 0) {
451 fprintf(stderr, "flash_add_block: unaligned block\n");
455 struct flash_block* new = malloc(sizeof(struct flash_block));
456 new->next = flash_root;
459 new->length = length;
460 new->data = calloc(length, 1);
467 static int flash_populate(stm32_addr_t addr, uint8_t* data, unsigned length) {
468 int fit_blocks = 0, fit_length = 0;
470 for(struct flash_block* fb = flash_root; fb; fb = fb->next) {
471 /* Block: ------X------Y--------
475 * Block intersects with data, if:
479 unsigned X = fb->addr, Y = fb->addr + fb->length;
480 unsigned a = addr, b = addr + length;
482 // from start of the block
483 unsigned start = (a > X ? a : X) - X;
484 unsigned end = (b > Y ? Y : b) - X;
486 memcpy(fb->data + start, data, end - start);
489 fit_length += end - start;
493 if(fit_blocks == 0) {
494 fprintf(stderr, "Unfit data block %08x -> %04x\n", addr, length);
498 if(fit_length != length) {
499 fprintf(stderr, "warning: data block %08x -> %04x truncated to %04x\n",
500 addr, length, fit_length);
501 fprintf(stderr, "(this is not an error, just a GDB glitch)\n");
507 static int flash_go(stlink_t *sl) {
510 // Some kinds of clock settings do not allow writing to flash.
513 for(struct flash_block* fb = flash_root; fb; fb = fb->next) {
515 printf("flash_do: block %08x -> %04x\n", fb->addr, fb->length);
518 unsigned length = fb->length;
519 for(stm32_addr_t page = fb->addr; page < fb->addr + fb->length; page += FLASH_PAGE) {
521 printf("flash_do: page %08x\n", page);
524 stlink_erase_flash_page(sl, page);
526 if(stlink_write_flash(sl, page, fb->data + (page - fb->addr),
527 length > FLASH_PAGE ? FLASH_PAGE : length) < 0)
538 for(struct flash_block* fb = flash_root, *next; fb; fb = next) {
549 int serve(stlink_t *sl, int port) {
550 int sock = socket(AF_INET, SOCK_STREAM, 0);
556 unsigned int val = 1;
557 setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
559 struct sockaddr_in serv_addr = {0};
560 serv_addr.sin_family = AF_INET;
561 serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
562 serv_addr.sin_port = htons(port);
564 if(bind(sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
569 if(listen(sock, 5) < 0) {
574 stlink_force_debug(sl);
576 init_code_breakpoints(sl);
577 init_data_watchpoints(sl);
579 printf("Listening at *:%d...\n", port);
581 int client = accept(sock, NULL, NULL);
589 printf("GDB connected.\n");
592 * To allow resetting the chip from GDB it is required to
593 * emulate attaching and detaching to target.
595 unsigned int attached = 1;
600 int status = gdb_recv_packet(client, &packet);
602 fprintf(stderr, "cannot recv: %d\n", status);
607 printf("recv: %s\n", packet);
615 if(packet[1] == 'P' || packet[1] == 'C' || packet[1] == 'L') {
620 char *separator = strstr(packet, ":"), *params = "";
621 if(separator == NULL) {
622 separator = packet + strlen(packet);
624 params = separator + 1;
627 unsigned queryNameLength = (separator - &packet[1]);
628 char* queryName = calloc(queryNameLength + 1, 1);
629 strncpy(queryName, &packet[1], queryNameLength);
632 printf("query: %s;%s\n", queryName, params);
635 if(!strcmp(queryName, "Supported")) {
636 reply = strdup("PacketSize=3fff;qXfer:memory-map:read+");
637 } else if(!strcmp(queryName, "Xfer")) {
638 char *type, *op, *s_addr, *s_length;
640 char *annex __attribute__((unused));
642 type = strsep(&tok, ":");
643 op = strsep(&tok, ":");
644 annex = strsep(&tok, ":");
645 s_addr = strsep(&tok, ",");
648 unsigned addr = strtoul(s_addr, NULL, 16),
649 length = strtoul(s_length, NULL, 16);
652 printf("Xfer: type:%s;op:%s;annex:%s;addr:%d;length:%d\n",
653 type, op, annex, addr, length);
656 const char* data = NULL;
658 if(!strcmp(type, "memory-map") && !strcmp(op, "read"))
659 data = current_memory_map;
662 unsigned data_length = strlen(data);
663 if(addr + length > data_length)
664 length = data_length - addr;
669 reply = calloc(length + 2, 1);
671 strncpy(&reply[1], data, length);
686 char *cmdName = strtok_r(packet, ":;", ¶ms);
688 cmdName++; // vCommand -> Command
690 if(!strcmp(cmdName, "FlashErase")) {
691 char *s_addr, *s_length;
694 s_addr = strsep(&tok, ",");
697 unsigned addr = strtoul(s_addr, NULL, 16),
698 length = strtoul(s_length, NULL, 16);
701 printf("FlashErase: addr:%08x,len:%04x\n",
705 if(flash_add_block(addr, length, sl) < 0) {
706 reply = strdup("E00");
708 reply = strdup("OK");
710 } else if(!strcmp(cmdName, "FlashWrite")) {
714 s_addr = strsep(&tok, ":");
717 unsigned addr = strtoul(s_addr, NULL, 16);
718 unsigned data_length = status - (data - packet);
720 // Length of decoded data cannot be more than
721 // encoded, as escapes are removed.
722 // Additional byte is reserved for alignment fix.
723 uint8_t *decoded = calloc(data_length + 1, 1);
724 unsigned dec_index = 0;
725 for(int i = 0; i < data_length; i++) {
726 if(data[i] == 0x7d) {
728 decoded[dec_index++] = data[i] ^ 0x20;
730 decoded[dec_index++] = data[i];
735 if(dec_index % 2 != 0)
739 printf("binary packet %d -> %d\n", data_length, dec_index);
742 if(flash_populate(addr, decoded, dec_index) < 0) {
743 reply = strdup("E00");
745 reply = strdup("OK");
747 } else if(!strcmp(cmdName, "FlashDone")) {
748 if(flash_go(sl) < 0) {
749 reply = strdup("E00");
751 reply = strdup("OK");
753 } else if(!strcmp(cmdName, "Kill")) {
756 reply = strdup("OK");
769 int status = gdb_check_for_interrupt(client);
771 fprintf(stderr, "cannot check for int: %d\n", status);
776 stlink_force_debug(sl);
781 if(sl->core_stat == STLINK_CORE_HALTED) {
788 reply = strdup("S05"); // TRAP
794 reply = strdup("S05"); // TRAP
799 reply = strdup("S05"); // TRAP
801 /* Stub shall reply OK if not attached. */
802 reply = strdup("OK");
807 stlink_read_all_regs(sl, ®p);
809 reply = calloc(8 * 16 + 1, 1);
810 for(int i = 0; i < 16; i++)
811 sprintf(&reply[i * 8], "%08x", htonl(regp.r[i]));
816 unsigned id = strtoul(&packet[1], NULL, 16);
817 unsigned myreg = 0xDEADDEAD;
820 stlink_read_reg(sl, id, ®p);
821 myreg = htonl(regp.r[id]);
822 } else if(id == 0x19) {
823 stlink_read_reg(sl, 16, ®p);
824 myreg = htonl(regp.xpsr);
826 reply = strdup("E00");
829 reply = calloc(8 + 1, 1);
830 sprintf(reply, "%08x", myreg);
836 char* s_reg = &packet[1];
837 char* s_value = strstr(&packet[1], "=") + 1;
839 unsigned reg = strtoul(s_reg, NULL, 16);
840 unsigned value = strtoul(s_value, NULL, 16);
843 stlink_write_reg(sl, ntohl(value), reg);
844 } else if(reg == 0x19) {
845 stlink_write_reg(sl, ntohl(value), 16);
847 reply = strdup("E00");
851 reply = strdup("OK");
858 for(int i = 0; i < 16; i++) {
860 strncpy(str, &packet[1 + i * 8], 8);
861 uint32_t reg = strtoul(str, NULL, 16);
862 stlink_write_reg(sl, ntohl(reg), i);
865 reply = strdup("OK");
869 char* s_start = &packet[1];
870 char* s_count = strstr(&packet[1], ",") + 1;
872 stm32_addr_t start = strtoul(s_start, NULL, 16);
873 unsigned count = strtoul(s_count, NULL, 16);
875 unsigned adj_start = start % 4;
877 stlink_read_mem32(sl, start - adj_start, (count % 4 == 0) ?
878 count : count + 4 - (count % 4));
880 reply = calloc(count * 2 + 1, 1);
881 for(int i = 0; i < count; i++) {
882 reply[i * 2 + 0] = hex[sl->q_buf[i + adj_start] >> 4];
883 reply[i * 2 + 1] = hex[sl->q_buf[i + adj_start] & 0xf];
890 char* s_start = &packet[1];
891 char* s_count = strstr(&packet[1], ",") + 1;
892 char* hexdata = strstr(packet, ":") + 1;
894 stm32_addr_t start = strtoul(s_start, NULL, 16);
895 unsigned count = strtoul(s_count, NULL, 16);
897 for(int i = 0; i < count; i ++) {
898 char hex[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
899 uint8_t byte = strtoul(hex, NULL, 16);
903 if((count % 4) == 0 && (start % 4) == 0) {
904 stlink_write_mem32(sl, start, count);
906 stlink_write_mem8(sl, start, count);
909 reply = strdup("OK");
916 stm32_addr_t addr = strtoul(&packet[3], &endptr, 16);
917 stm32_addr_t len = strtoul(&endptr[1], NULL, 16);
921 if(update_code_breakpoint(sl, addr, 1) < 0) {
922 reply = strdup("E00");
924 reply = strdup("OK");
928 case '2': // insert write watchpoint
929 case '3': // insert read watchpoint
930 case '4': // insert access watchpoint
933 if(packet[1] == '2') {
935 } else if(packet[1] == '3') {
939 if(add_data_watchpoint(sl, wf, addr, len) < 0) {
940 reply = strdup("E00");
942 reply = strdup("OK");
955 stm32_addr_t addr = strtoul(&packet[3], &endptr, 16);
956 //stm32_addr_t len = strtoul(&endptr[1], NULL, 16);
959 case '1': // remove breakpoint
960 update_code_breakpoint(sl, addr, 0);
961 reply = strdup("OK");
964 case '2' : // remove write watchpoint
965 case '3' : // remove read watchpoint
966 case '4' : // remove access watchpoint
967 if(delete_data_watchpoint(sl, addr) < 0) {
968 reply = strdup("E00");
970 reply = strdup("OK");
982 * Enter extended mode which allows restarting.
983 * We do support that always.
986 reply = strdup("OK");
992 /* Reset the core. */
995 init_code_breakpoints(sl);
996 init_data_watchpoints(sl);
1000 reply = strdup("OK");
1011 printf("send: %s\n", reply);
1014 int result = gdb_send_packet(client, reply);
1016 fprintf(stderr, "cannot send: %d\n", result);