54 #define CTRL(c) ((c) - '@')
110 #define _DEBUG_GDB_IO_
123 const char *
function,
const char *
string);
197 LOG_USER(
"undefined debug reason %d (%s) - target needs reset",
205 int timeout_s,
int *got_data)
246 #ifdef _DEBUG_GDB_IO_
264 LOG_DEBUG(
"GDB connection closed by the remote client");
270 bool retry = (WSAGetLastError() == WSAEWOULDBLOCK);
272 bool retry = (errno == EAGAIN);
286 #ifdef _DEBUG_GDB_IO_
288 LOG_DEBUG(
"received '%s'", debug_buffer);
294 *next_char = *(gdb_con->
buf_p++);
299 #ifdef _DEBUG_GDB_IO_
300 LOG_DEBUG(
"returned char '%c' (0x%2.2x)", *next_char, *next_char);
318 *next_char = **
buf_p;
325 #ifdef _DEBUG_GDB_IO_
326 LOG_DEBUG(
"returned char '%c' (0x%2.2x)", *next_char, *next_char);
353 *(--gdb_con->
buf_p) = last_char;
356 LOG_ERROR(
"BUG: couldn't put character back");
368 LOG_DEBUG(
"GDB socket marked as closed, cannot write to it.");
375 LOG_WARNING(
"Error writing to GDB socket. Dropping the connection.");
389 const unsigned int packet_len = strlen(packet);
394 const char *colon = memchr(packet,
':',
MIN(50, packet_len));
395 const bool packet_has_prefix = (colon);
396 const bool packet_prefix_printable = (packet_has_prefix && nonprint > colon);
398 if (packet_prefix_printable) {
399 const unsigned int prefix_len = colon - packet + 1;
400 const unsigned int payload_len = packet_len - prefix_len;
414 unsigned int packet_len,
unsigned char checksum)
444 const char *
buffer,
int len)
447 unsigned char my_checksum = 0;
452 for (i = 0; i < len; i++)
455 #ifdef _DEBUG_GDB_IO_
474 LOG_DEBUG(
"Unexpected start of new packet");
476 }
else if (reply ==
CTRL(
'C')) {
489 char local_buffer[1024];
490 local_buffer[0] =
'$';
491 if ((
size_t)len + 5 <=
sizeof(local_buffer)) {
493 memcpy(local_buffer + 1,
buffer, len++);
494 len += snprintf(local_buffer + len,
sizeof(local_buffer) - len,
"#%02x", my_checksum);
501 snprintf(local_buffer + 1,
sizeof(local_buffer) - 1,
"#%02x", my_checksum);
523 }
else if (reply ==
'-') {
528 }
else if (reply ==
CTRL(
'C')) {
537 }
else if (reply ==
'-') {
542 }
else if (reply ==
'$') {
543 LOG_ERROR(
"GDB missing ack(1) - assumed good");
547 LOG_ERROR(
"unknown character(1) 0x%2.2x in reply, dropping connection", reply);
551 }
else if (reply ==
'$') {
552 LOG_ERROR(
"GDB missing ack(2) - assumed good");
556 LOG_ERROR(
"unknown character(2) 0x%2.2x in reply, dropping connection",
571 gdb_con->
busy =
true;
573 gdb_con->
busy =
false;
582 int *checksum_ok,
int noack,
int *len,
char *
buffer)
584 unsigned char my_checksum = 0;
617 if (character ==
'#') {
624 if (character ==
'}') {
627 my_checksum += character & 0xff;
630 my_checksum += character & 0xff;
633 my_checksum += character & 0xff;
652 if (character ==
'#')
655 if (character ==
'}') {
658 my_checksum += character & 0xff;
664 my_checksum += character & 0xff;
667 my_checksum += character & 0xff;
683 checksum[0] = character;
687 checksum[1] = character;
691 *checksum_ok = (my_checksum == strtoul(checksum,
NULL, 16));
709 #ifdef _DEBUG_GDB_IO_
728 LOG_WARNING(
"acknowledgment received, but no packet pending");
730 LOG_DEBUG(
"Received first acknowledgment after entering noack mode. Ignoring it.");
736 LOG_WARNING(
"negative acknowledgment, but no packet pending");
747 }
while (character !=
'$');
782 gdb_con->
busy =
true;
784 gdb_con->
busy =
false;
793 bin_size = strlen(line);
795 hex_buffer = malloc(bin_size * 2 + 2);
800 size_t pkt_len =
hexify(hex_buffer + 1, (
const uint8_t *)line, bin_size,
819 char stop_reason[32];
827 sig_reply_len = snprintf(sig_reply,
sizeof(sig_reply),
"W00");
846 stop_reason[0] =
'\0';
853 switch (hit_wp_type) {
855 snprintf(stop_reason,
sizeof(stop_reason),
859 snprintf(stop_reason,
sizeof(stop_reason),
863 snprintf(stop_reason,
sizeof(stop_reason),
877 sig_reply_len = snprintf(sig_reply,
sizeof(sig_reply),
"T%2.2x%s%s",
890 char fileio_command[256];
892 bool program_exited =
false;
951 program_exited =
true;
962 command_len = strlen(fileio_command);
965 if (program_exited) {
1006 if (gdb_target !=
target)
1029 static unsigned int next_unique_id = 1;
1074 if (initial_ack !=
'+')
1101 LOG_ERROR(
"Connect failed. Consider setting up a gdb-attach event for the target "
1102 "to prepare target for GDB connect, or use 'gdb_memory_map disable'.");
1109 __FILE__, __LINE__, __func__,
1110 "New GDB Connection: %d, Target %s, state: %s",
1181 snprintf(err, 4,
"E%2.2X", the_error);
1186 char const *packet,
int packet_size)
1202 snprintf(sig_reply, 4,
"S%2.2x", signal_var);
1213 return len - 1 - pos;
1226 char *tstr,
struct reg *
reg)
1235 for (i = 0; i < buf_len; i++) {
1237 tstr += sprintf(tstr,
"%02x", buf[j]);
1243 char const *tstr,
int str_len, uint8_t *bin)
1246 LOG_ERROR(
"BUG: gdb value with uneven number of characters encountered");
1251 for (i = 0; i < str_len; i += 2) {
1253 if (sscanf(tstr + i,
"%02x", &t) != 1) {
1254 LOG_ERROR(
"BUG: unable to convert register value");
1277 memset(tstr,
'x', len);
1281 memset(tstr,
'0', len);
1287 char const *packet,
int packet_size)
1290 struct reg **reg_list;
1293 int reg_packet_size = 0;
1298 #ifdef _DEBUG_GDB_IO_
1310 for (i = 0; i < reg_list_size; i++) {
1311 if (!reg_list[i] || !reg_list[i]->
exist || reg_list[i]->
hidden)
1316 assert(reg_packet_size > 0);
1318 reg_packet = malloc(reg_packet_size + 1);
1322 reg_packet_p = reg_packet;
1324 for (i = 0; i < reg_list_size; i++) {
1325 if (!reg_list[i] || !reg_list[i]->
exist || reg_list[i]->
hidden)
1337 #ifdef _DEBUG_GDB_IO_
1339 char *reg_packet_p_debug;
1340 reg_packet_p_debug =
strndup(reg_packet, reg_packet_size);
1341 LOG_DEBUG(
"reg_packet: %s", reg_packet_p_debug);
1342 free(reg_packet_p_debug);
1355 char const *packet,
int packet_size)
1359 struct reg **reg_list;
1362 char const *packet_p;
1364 #ifdef _DEBUG_GDB_IO_
1372 if (packet_size % 2) {
1373 LOG_WARNING(
"GDB set_registers packet with uneven characters received, dropping connection");
1383 for (i = 0; i < reg_list_size; i++) {
1385 if (!reg_list[i] || !reg_list[i]->
exist || reg_list[i]->
hidden)
1389 if (packet_p + chars > packet + packet_size)
1390 LOG_ERROR(
"BUG: register packet is too small for registers");
1395 retval = reg_list[i]->
type->
set(reg_list[i], bin_buf);
1418 char const *packet,
int packet_size)
1422 int reg_num = strtoul(packet + 1,
NULL, 16);
1423 struct reg **reg_list;
1427 #ifdef _DEBUG_GDB_IO_
1444 if ((reg_list_size <= reg_num) || !reg_list[reg_num] ||
1445 !reg_list[reg_num]->
exist || reg_list[reg_num]->
hidden) {
1446 LOG_ERROR(
"gdb requested a non-existing register (reg_num=%d)", reg_num);
1454 LOG_DEBUG(
"Couldn't get register %s.", reg_list[reg_num]->
name);
1469 char const *packet,
int packet_size)
1473 int reg_num = strtoul(packet + 1, &separator, 16);
1474 struct reg **reg_list;
1478 #ifdef _DEBUG_GDB_IO_
1482 if (*separator !=
'=') {
1483 LOG_ERROR(
"GDB 'set register packet', but no '=' following the register number");
1486 size_t chars = strlen(separator + 1);
1487 uint8_t *bin_buf = malloc(chars / 2);
1504 if ((reg_list_size <= reg_num) || !reg_list[reg_num] ||
1505 !reg_list[reg_num]->
exist || reg_list[reg_num]->
hidden) {
1506 LOG_ERROR(
"gdb requested a non-existing register (reg_num=%d)", reg_num);
1513 LOG_ERROR(
"gdb sent %zu bits for a %" PRIu32
"-bit register (%s)",
1514 chars * 4, reg_list[reg_num]->
size, reg_list[reg_num]->
name);
1522 retval = reg_list[reg_num]->
type->
set(reg_list[reg_num], bin_buf);
1524 LOG_DEBUG(
"Couldn't set register %s.", reg_list[reg_num]->
name);
1544 LOG_DEBUG(
"Reporting %i to GDB as generic error", retval);
1556 *
addr = strtoull(packet, &separator, 16);
1558 if (*separator !=
',') {
1559 LOG_ERROR(
"incomplete read memory packet received, dropping connection");
1564 long signed_len = strtol(separator + 1,
NULL, 16);
1565 if (errno == ERANGE || signed_len < 0 || (
unsigned long)signed_len > UINT32_MAX) {
1566 LOG_WARNING(
"invalid read memory packet received (len == 0)");
1570 *len = (uint32_t)signed_len;
1576 uint8_t *
buffer, uint64_t
addr, uint32_t len)
1580 LOG_DEBUG(
"addr: 0x%16.16" PRIx64
", len: 0x%8.8" PRIx32,
addr, len);
1610 char const *packet,
int packet_size)
1637 hex_buffer = malloc(len * 2 + 1);
1639 LOG_ERROR(
"Unable to allocate memory for hex buffer");
1645 size_t pkt_len =
hexify(hex_buffer,
buffer, len, len * 2 + 1);
1665 for (
size_t i = 0; i < data_len; ++i) {
1666 uint8_t c = data[i];
1669 if (c == 0x23 || c == 0x24 || c == 0x7d || c == 0x2a) {
1670 out[out_pos++] = 0x7d;
1671 out[out_pos++] = c ^ 0x20;
1681 char const *packet,
int packet_size)
1695 uint8_t *
buffer = malloc(len);
1711 char *out_buffer = malloc(len * 2 + 1 + 1);
1713 LOG_ERROR(
"Unable to allocate memory for output buffer");
1718 if (pkt_len < len || INT_MAX <= pkt_len) {
1719 LOG_ERROR(
"Escape binary data failed: invalid output length %zu "
1720 "(input: %" PRIu32
", max: %d)", pkt_len, len, INT_MAX);
1734 char const *packet,
int packet_size)
1747 addr = strtoull(packet, &separator, 16);
1749 if (*separator !=
',') {
1750 LOG_ERROR(
"incomplete write memory packet received, dropping connection");
1754 len = strtoul(separator + 1, &separator, 16);
1756 if (*(separator++) !=
':') {
1757 LOG_ERROR(
"incomplete write memory packet received, dropping connection");
1763 LOG_DEBUG(
"addr: 0x%" PRIx64
", len: 0x%8.8" PRIx32,
addr, len);
1766 LOG_ERROR(
"unable to decode memory packet");
1785 char const *packet,
int packet_size)
1796 uint32_t fast_limit = 8;
1801 addr = strtoull(packet, &separator, 16);
1803 if (*separator !=
',') {
1804 LOG_ERROR(
"incomplete write memory binary packet received, dropping connection");
1808 len = strtoul(separator + 1, &separator, 16);
1810 if (*(separator++) !=
':') {
1811 LOG_ERROR(
"incomplete write memory binary packet received, dropping connection");
1821 if (len >= fast_limit) {
1839 LOG_DEBUG(
"addr: 0x%" PRIx64
", len: 0x%8.8" PRIx32,
addr, len);
1851 if (len < fast_limit) {
1864 char const *packet,
int packet_size)
1867 bool current =
false;
1873 if (packet_size > 1)
1879 if (packet[0] ==
'c') {
1883 }
else if (packet[0] ==
's') {
1892 char const *packet,
int packet_size)
1905 type = strtoul(packet + 1, &separator, 16);
1918 LOG_ERROR(
"invalid gdb watch/breakpoint type(%d), dropping connection",
type);
1925 if (*separator !=
',') {
1926 LOG_ERROR(
"incomplete breakpoint/watchpoint packet received, dropping connection");
1930 address = strtoull(separator + 1, &separator, 16);
1932 if (*separator !=
',') {
1933 LOG_ERROR(
"incomplete breakpoint/watchpoint packet received, dropping connection");
1937 size = strtoul(separator + 1, &separator, 16);
1942 if (packet[0] ==
'Z') {
1953 assert(packet[0] ==
'z');
1961 if (packet[0] ==
'Z') {
1964 assert(packet[0] ==
'z');
1989 char **xml,
int *pos,
int *
size, const
char *fmt, ...)
1996 if ((!*xml) || (!first)) {
2002 *xml = realloc(*xml, *
size);
2013 ret = vsnprintf(*xml + *pos, *
size - *pos, fmt, ap);
2015 if ((ret > 0) && ((ret + 1) < *
size - *pos)) {
2027 const char *annex_end = strchr(buf,
':');
2034 *ofs = strtoul(annex_end + 1, &separator, 16);
2036 if (*separator !=
',')
2039 *len = strtoul(separator + 1,
NULL, 16);
2043 *annex =
strndup(buf, annex_end - buf);
2066 char const *packet,
int packet_size)
2086 unsigned int target_flash_banks = 0;
2091 offset = strtoul(packet, &separator, 16);
2092 length = strtoul(separator + 1, &separator, 16);
2094 xml_printf(&retval, &xml, &pos, &
size,
"<memory-map>\n");
2112 banks[target_flash_banks++] = p;
2115 qsort(banks, target_flash_banks,
sizeof(
struct flash_bank *),
2118 for (
unsigned int i = 0; i < target_flash_banks; i++) {
2120 unsigned int group_len = 0;
2124 if (ram_start < p->
base)
2125 xml_printf(&retval, &xml, &pos, &
size,
2128 ram_start, p->
base - ram_start);
2131 xml_printf(&retval, &xml, &pos, &
size,
2133 "length=\"0x%x\"/>\n",
2137 xml_printf(&retval, &xml, &pos, &
size,
2138 "<memory type=\"flash\" "
2141 "<property name=\"blocksize\">0x%x</property>\n"
2151 for (
unsigned int j = 0; j < p->
num_sectors; j++) {
2155 LOG_WARNING(
"The flash sector at offset 0x%08" PRIx32
2156 " overflows the end of %s bank.",
2158 LOG_WARNING(
"The rest of bank will not show in gdb memory map.");
2163 xml_printf(&retval, &xml, &pos, &
size,
2164 "<memory type=\"flash\" "
2182 xml_printf(&retval, &xml, &pos, &
size,
2183 "length=\"0x%x\">\n"
2184 "<property name=\"blocksize\">"
2197 xml_printf(&retval, &xml, &pos, &
size,
2206 xml_printf(&retval, &xml, &pos, &
size,
"</memory-map>\n");
2217 char *t = malloc(
length + 1);
2263 return "ieee_single";
2265 return "ieee_double";
2274 int *num_arch_defined_types)
2276 int tbl_sz = *num_arch_defined_types;
2278 if (type_id && (strcmp(type_id,
""))) {
2279 for (
int j = 0; j < (tbl_sz + 1); j++) {
2280 if (!((*arch_defined_types_list)[j])) {
2281 (*arch_defined_types_list)[tbl_sz++] = type_id;
2282 *arch_defined_types_list = realloc(*arch_defined_types_list,
2283 sizeof(
char *) * (tbl_sz + 1));
2284 (*arch_defined_types_list)[tbl_sz] =
NULL;
2285 *num_arch_defined_types = tbl_sz;
2288 if (!strcmp((*arch_defined_types_list)[j], type_id))
2299 char const **arch_defined_types_list[],
int *num_arch_defined_types)
2307 num_arch_defined_types))
2309 arch_defined_types_list,
2310 num_arch_defined_types);
2313 xml_printf(&retval, tdesc, pos,
size,
2314 "<vector id=\"%s\" type=\"%s\" count=\"%" PRIu32
"\"/>\n",
2315 type->id,
type->reg_type_vector->type->id,
2316 type->reg_type_vector->count);
2320 field =
type->reg_type_union->fields;
2325 num_arch_defined_types))
2327 arch_defined_types_list,
2328 num_arch_defined_types);
2331 field = field->
next;
2336 xml_printf(&retval, tdesc, pos,
size,
2337 "<union id=\"%s\">\n",
2340 field =
type->reg_type_union->fields;
2342 xml_printf(&retval, tdesc, pos,
size,
2343 "<field name=\"%s\" type=\"%s\"/>\n",
2346 field = field->
next;
2349 xml_printf(&retval, tdesc, pos,
size,
2354 field =
type->reg_type_struct->fields;
2360 xml_printf(&retval, tdesc, pos,
size,
2361 "<struct id=\"%s\" size=\"%" PRIu32
"\">\n",
2362 type->id,
type->reg_type_struct->size);
2364 xml_printf(&retval, tdesc, pos,
size,
2365 "<field name=\"%s\" start=\"%" PRIu32
"\" end=\"%" PRIu32
"\" type=\"%s\" />\n",
2369 field = field->
next;
2376 num_arch_defined_types))
2378 arch_defined_types_list,
2379 num_arch_defined_types);
2386 xml_printf(&retval, tdesc, pos,
size,
2387 "<struct id=\"%s\">\n",
2390 xml_printf(&retval, tdesc, pos,
size,
2391 "<field name=\"%s\" type=\"%s\"/>\n",
2394 field = field->
next;
2398 xml_printf(&retval, tdesc, pos,
size,
2405 xml_printf(&retval, tdesc, pos,
size,
2406 "<flags id=\"%s\" size=\"%" PRIu32
"\">\n",
2407 type->id,
type->reg_type_flags->size);
2410 field =
type->reg_type_flags->fields;
2412 xml_printf(&retval, tdesc, pos,
size,
2413 "<field name=\"%s\" start=\"%" PRIu32
"\" end=\"%" PRIu32
"\" type=\"%s\" />\n",
2417 field = field->
next;
2420 xml_printf(&retval, tdesc, pos,
size,
2432 struct reg **reg_list,
int reg_list_size)
2437 *feature_list = calloc(1,
sizeof(
char *));
2439 for (
int i = 0; i < reg_list_size; i++) {
2440 if (!reg_list[i]->exist || reg_list[i]->hidden)
2445 && (strcmp(reg_list[i]->
feature->name,
""))) {
2450 for (
int j = 0; j < (tbl_sz + 1); j++) {
2451 if (!((*feature_list)[j])) {
2452 (*feature_list)[tbl_sz++] = reg_list[i]->
feature->
name;
2453 *feature_list = realloc(*feature_list,
sizeof(
char *) * (tbl_sz + 1));
2454 (*feature_list)[tbl_sz] =
NULL;
2457 if (!strcmp((*feature_list)[j], reg_list[i]->
feature->name))
2464 if (feature_list_size)
2465 *feature_list_size = tbl_sz;
2475 struct reg **combined_list[],
int *combined_list_size,
2482 unsigned int combined_allocated = 256;
2483 struct reg **local_list = malloc(combined_allocated *
sizeof(
struct reg *));
2485 LOG_ERROR(
"malloc(%zu) failed", combined_allocated *
sizeof(
struct reg *));
2488 unsigned int local_list_size = 0;
2498 ®_list_size, reg_class);
2503 for (
int i = 0; i < reg_list_size; i++) {
2505 struct reg *a = reg_list[i];
2510 for (
unsigned int j = 0; j < local_list_size; j++) {
2511 struct reg *b = local_list[j];
2515 LOG_ERROR(
"SMP register %s is %d bits on one "
2516 "target, but %d bits on another target.",
2527 if (local_list_size >= combined_allocated) {
2528 combined_allocated *= 2;
2529 local_list = realloc(local_list, combined_allocated *
sizeof(
struct reg *));
2531 LOG_ERROR(
"realloc(%zu) failed", combined_allocated *
sizeof(
struct reg *));
2536 local_list[local_list_size] = a;
2544 if (local_list_size == 0) {
2545 LOG_ERROR(
"Unable to get register list");
2558 ®_list_size, reg_class);
2563 for (
unsigned int i = 0; i < local_list_size; i++) {
2565 struct reg *a = local_list[i];
2566 for (
int j = 0; j < reg_list_size; j++) {
2567 struct reg *b = reg_list[j];
2575 "this register does exist.", a->
name);
2581 *combined_list = local_list;
2582 *combined_list_size = local_list_size;
2591 char const *architecture;
2592 char const **features =
NULL;
2593 int feature_list_size = 0;
2608 if (reg_list_size <= 0) {
2617 LOG_ERROR(
"Can't get the registers feature list");
2623 int current_feature = 0;
2625 xml_printf(&retval, &tdesc, &pos, &
size,
2626 "<?xml version=\"1.0\"?>\n"
2627 "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n"
2628 "<target version=\"1.0\">\n");
2633 xml_printf(&retval, &tdesc, &pos, &
size,
2634 "<architecture>%s</architecture>\n", architecture);
2638 while (features[current_feature]) {
2639 char const **arch_defined_types =
NULL;
2640 int num_arch_defined_types = 0;
2642 arch_defined_types = calloc(1,
sizeof(
char *));
2643 xml_printf(&retval, &tdesc, &pos, &
size,
2644 "<feature name=\"%s\">\n",
2645 features[current_feature]);
2648 for (i = 0; i < reg_list_size; i++) {
2653 if (strcmp(reg_list[i]->
feature->name, features[current_feature]))
2656 const char *type_str;
2662 &num_arch_defined_types))
2665 &arch_defined_types,
2666 &num_arch_defined_types);
2679 xml_printf(&retval, &tdesc, &pos, &
size,
2680 "<reg name=\"%s\"", reg_list[i]->
name);
2681 xml_printf(&retval, &tdesc, &pos, &
size,
2682 " bitsize=\"%" PRIu32
"\"", reg_list[i]->
size);
2683 xml_printf(&retval, &tdesc, &pos, &
size,
2684 " regnum=\"%" PRIu32
"\"", reg_list[i]->
number);
2686 xml_printf(&retval, &tdesc, &pos, &
size,
2687 " save-restore=\"yes\"");
2689 xml_printf(&retval, &tdesc, &pos, &
size,
2690 " save-restore=\"no\"");
2692 xml_printf(&retval, &tdesc, &pos, &
size,
2693 " type=\"%s\"", type_str);
2695 if (reg_list[i]->
group)
2696 xml_printf(&retval, &tdesc, &pos, &
size,
2697 " group=\"%s\"", reg_list[i]->
group);
2699 xml_printf(&retval, &tdesc, &pos, &
size,
2703 xml_printf(&retval, &tdesc, &pos, &
size,
2707 free(arch_defined_types);
2711 xml_printf(&retval, &tdesc, &pos, &
size,
2730 LOG_ERROR(
"Unable to Generate Target Description");
2734 char *tdesc = target_desc->
tdesc;
2740 LOG_ERROR(
"Unable to Generate Target Description");
2744 tdesc_length = strlen(tdesc);
2750 transfer_type =
'm';
2752 transfer_type =
'l';
2754 *chunk = malloc(
length + 2);
2760 (*chunk)[0] = transfer_type;
2761 if (transfer_type ==
'm') {
2763 (*chunk)[1 +
length] =
'\0';
2765 strncpy((*chunk) + 1, tdesc +
offset, tdesc_length -
offset);
2766 (*chunk)[1 + (tdesc_length -
offset)] =
'\0';
2774 target_desc->
tdesc = tdesc;
2784 int reg_list_size = 0;
2785 char const **features =
NULL;
2786 int feature_list_size = 0;
2797 if (reg_list_size <= 0) {
2806 LOG_ERROR(
"Can't get the registers feature list");
2811 if (architecture || feature_list_size)
2829 char *thread_list =
NULL;
2833 xml_printf(&retval, &thread_list, &pos, &
size,
2834 "<?xml version=\"1.0\"?>\n"
2845 xml_printf(&retval, &thread_list, &pos, &
size,
2846 "<thread id=\"%" PRIx64
"\" name=\"%s\">",
2850 xml_printf(&retval, &thread_list, &pos, &
size,
2854 xml_printf(&retval, &thread_list, &pos, &
size,
2859 xml_printf(&retval, &thread_list, &pos, &
size,
2861 xml_printf(&retval, &thread_list, &pos, &
size,
2865 xml_printf(&retval, &thread_list, &pos, &
size,
2870 xml_printf(&retval, &thread_list, &pos, &
size,
2874 *thread_list_out = thread_list;
2884 if (!*thread_list) {
2887 LOG_ERROR(
"Unable to Generate Thread List");
2892 size_t thread_list_length = strlen(*thread_list);
2897 transfer_type =
'm';
2899 transfer_type =
'l';
2901 *chunk = malloc(
length + 2 + 3);
2911 (*chunk)[0] = transfer_type;
2912 strncpy((*chunk) + 1, (*thread_list) +
offset,
length);
2913 (*chunk)[1 +
length] =
'\0';
2916 if (transfer_type ==
'l') {
2918 *thread_list =
NULL;
2925 char const *packet,
int packet_size)
2931 if (strncmp(packet,
"qRcmd,", 6) == 0) {
2932 if (packet_size > 6) {
2933 Jim_Interp *interp = cmd_ctx->
interp;
2935 cmd = malloc((packet_size - 6) / 2 + 1);
2936 size_t len =
unhexify((uint8_t *)
cmd, packet + 6, (packet_size - 6) / 2);
2950 Jim_DeleteAssocData(
interp,
"context");
2951 int retval = Jim_SetAssocData(
interp,
"context",
NULL, cmd_ctx);
2952 if (retval == JIM_OK) {
2954 Jim_DeleteAssocData(
interp,
"context");
2956 int inner_retval = Jim_SetAssocData(
interp,
"context",
NULL, old_context);
2957 if (retval == JIM_OK)
2958 retval = inner_retval;
2965 if (retval == JIM_RETURN)
2966 retval =
interp->returnCode;
2968 const char *cretmsg = Jim_GetString(Jim_GetResult(
interp), &lenmsg);
2970 if (lenmsg && cretmsg[lenmsg - 1] !=
'\n') {
2974 retmsg = strdup(cretmsg);
2982 if (retval == JIM_OK) {
2984 char *hex_buffer = malloc(lenmsg * 2 + 1);
2990 size_t pkt_len =
hexify(hex_buffer, (
const uint8_t *)retmsg, lenmsg,
3007 }
else if (strncmp(packet,
"qCRC:", 5) == 0) {
3008 if (packet_size > 5) {
3019 addr = strtoull(packet, &separator, 16);
3021 if (*separator !=
',') {
3022 LOG_ERROR(
"incomplete read memory packet received, dropping connection");
3026 len = strtoul(separator + 1,
NULL, 16);
3033 snprintf(gdb_reply, 10,
"C%8.8" PRIx32, checksum);
3043 }
else if (strncmp(packet,
"qSupported", 10) == 0) {
3050 bool gdb_target_desc_supported =
false;
3055 LOG_INFO(
"Failed detecting Target Description Support, disabling");
3056 gdb_target_desc_supported =
false;
3061 if (gdb_target_desc_supported)
3062 LOG_WARNING(
"Target Descriptions Supported, but disabled");
3063 gdb_target_desc_supported =
false;
3073 "qXfer:features:read%c;"
3074 "qXfer:memory-map:read%c;"
3075 "qXfer:threads:read+;"
3078 gdb_target_desc_supported ?
'+' :
'-',
3090 }
else if ((strncmp(packet,
"qXfer:memory-map:read::", 23) == 0)
3093 else if (strncmp(packet,
"qXfer:features:read:", 20) == 0) {
3124 }
else if (strncmp(packet,
"qXfer:threads:read:", 19) == 0) {
3155 }
else if (strncmp(packet,
"QStartNoAckMode", 15) == 0) {
3175 const char *parse = packet;
3179 if (parse[0] ==
'?') {
3188 if (parse[0] ==
';') {
3193 if (parse[0] ==
'c') {
3220 if (parse[0] ==
's') {
3222 bool fake_step =
false;
3225 bool current_pc =
true;
3228 if (parse[0] ==
':') {
3231 thread_id = strtoll(parse, &endp, 16);
3266 if (parse[0] ==
';') {
3269 if (parse[0] ==
'c') {
3273 if (parse[0] ==
':') {
3277 tid = strtoll(parse,
NULL, 16);
3278 if (tid == thread_id) {
3288 LOG_DEBUG(
"request to step current core only");
3310 char sig_reply[128];
3312 LOG_DEBUG(
"fake step thread %"PRIx64, thread_id);
3314 sig_reply_len = snprintf(sig_reply,
sizeof(sig_reply),
3315 "T05thread:%016"PRIx64
";", thread_id);
3327 LOG_DEBUG(
"stepi ignored. GDB will now fetch the register state "
3328 "from the target.");
3360 const char *hex = *str;
3364 const char *end = strchr(hex, sep);
3366 hexlen = strlen(hex);
3369 *str = hex + hexlen + 1;
3371 if (hexlen % 2 != 0) {
3376 size_t count = hexlen / 2;
3377 char *decoded = malloc(
count + 1);
3382 if (converted !=
count) {
3387 decoded[
count] =
'\0';
3410 const char *parse = packet;
3415 if (parse[0] !=
';')
3427 char *new_cmdline =
alloc_printf(
"%s %s", cmdline, arg);
3430 cmdline = new_cmdline;
3435 LOG_INFO(
"GDB set inferior command line to '%s'", cmdline);
3439 LOG_INFO(
"GDB set inferior command line to '%s' but semihosting is unavailable", cmdline);
3450 char const *packet,
int packet_size)
3457 if (strncmp(packet,
"vCont", 5) == 0) {
3470 if (strncmp(packet,
"vRun", 4) == 0) {
3487 if (strncmp(packet,
"vFlashErase:", 12) == 0) {
3491 char const *parse = packet + 12;
3492 if (*parse ==
'\0') {
3493 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3497 addr = strtoull(parse, (
char **)&parse, 16);
3499 if (*(parse++) !=
',' || *parse ==
'\0') {
3500 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3504 length = strtoul(parse, (
char **)&parse, 16);
3506 if (*parse !=
'\0') {
3507 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3536 LOG_ERROR(
"flash_erase returned %i", result);
3543 if (strncmp(packet,
"vFlashWrite:", 12) == 0) {
3547 char const *parse = packet + 12;
3549 if (*parse ==
'\0') {
3550 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3554 addr = strtoull(parse, (
char **)&parse, 16);
3555 if (*(parse++) !=
':') {
3556 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3559 length = packet_size - (parse - packet);
3578 if (strncmp(packet,
"vFlashDone", 10) == 0) {
3602 LOG_DEBUG(
"wrote %u bytes from vFlash image to flash", (
unsigned)written);
3632 char const *packet,
int packet_size)
3636 char *parsing_point;
3637 int fileio_retcode = strtoul(packet + 1, &separator, 16);
3638 int fileio_errno = 0;
3639 bool fileio_ctrl_c =
false;
3644 if (*separator ==
',') {
3645 parsing_point = separator + 1;
3646 fileio_errno = strtoul(parsing_point, &separator, 16);
3647 if (*separator ==
',') {
3648 if (*(separator + 1) ==
'C') {
3650 fileio_ctrl_c =
true;
3655 LOG_DEBUG(
"File-I/O response, retcode: 0x%x, errno: 0x%x, ctrl-c: %s",
3656 fileio_retcode, fileio_errno, fileio_ctrl_c ?
"true" :
"false");
3677 const char *
function,
const char *
string)
3686 if (gdb_con->
busy) {
3697 snprintf(sig_reply, 4,
"T%2.2x", 2);
3707 char const *packet = gdb_packet_buffer;
3711 static bool warn_use_ext;
3733 gdb_packet_buffer[packet_size] =
'\0';
3735 if (packet_size > 0) {
3740 switch (packet[0]) {
3784 warn_use_ext =
true;
3785 LOG_WARNING(
"Prefer GDB command \"target extended-remote :%s\" instead of \"target remote :%s\"",
3803 bool nostep =
false;
3804 bool already_running =
false;
3806 LOG_WARNING(
"WARNING! The target is already running. "
3807 "All changes GDB did to registers will be discarded! "
3808 "Waiting for target to halt.");
3809 already_running =
true;
3811 LOG_WARNING(
"The target is not in the halted nor running stated, "
3812 "stepi/continue ignored.");
3814 }
else if ((packet[0] ==
's') && gdb_con->
sync) {
3820 LOG_DEBUG(
"stepi ignored. GDB will now fetch the register state "
3821 "from the target.");
3823 gdb_con->
sync =
false;
3825 if (!already_running && nostep) {
3844 if (!already_running) {
3892 if (strncmp(packet,
"jc", 2) == 0) {
3899 LOG_DEBUG(
"ignoring 0x%2.2x packet", packet[0]);
3905 if (strncmp(packet,
"jc", 2) == 0) {
3913 LOG_DEBUG(
"ignoring 0x%2.2x packet", packet[0]);
3933 LOG_DEBUG(
"ignoring 0x%2.2x packet", packet[0]);
3946 struct target *t = available_target;
3947 if (available_target->
rtos)
3962 }
while (gdb_con->
buf_cnt > 0);
3999 static unsigned char count;
4000 unsigned char checksum = 0;
4003 int len = sprintf(buf,
"%%oocd_keepalive:%2.2x",
count++);
4004 for (
int i = 1; i < len; i++)
4006 len += sprintf(buf + len,
"#%2.2x", checksum);
4008 #ifdef _DEBUG_GDB_IO_
4043 LOG_ERROR(
"Unable to escape Tcl string");
4053 .new_connection_during_keep_alive_handler =
NULL,
4058 .service_info_handler = gdb_service_info,
4154 LOG_WARNING(
"gdb services need one or more targets defined");
4176 "gdb sync command can only be run from within gdb using \"monitor gdb sync\"");
4237 if (strcmp(
CMD_ARGV[0],
"hard") == 0)
4239 else if (strcmp(
CMD_ARGV[0],
"soft") == 0)
4241 else if (strcmp(
CMD_ARGV[0],
"disable") == 0)
4249 LOG_USER(
"breakpoint type is not overridden");
4266 uint32_t tdesc_length;
4271 LOG_ERROR(
"Unable to Generate Target Description");
4275 tdesc_length = strlen(tdesc);
4278 size_t size_written;
4281 if (!tdesc_filename) {
4289 LOG_ERROR(
"Can't open %s for writing", tdesc_filename);
4298 LOG_ERROR(
"Error while writing the tdesc file");
4301 free(tdesc_filename);
4310 .handler = handle_gdb_sync_command,
4312 .help =
"next stepi will return immediately allowing "
4313 "GDB to fetch register state without affecting "
4319 .handler = handle_gdb_port_command,
4321 .help =
"Normally gdb listens to a TCP/IP port. Each subsequent GDB "
4322 "server listens for the next port number after the "
4323 "base port number specified. "
4324 "No arguments reports GDB port. \"pipe\" means listen to stdin "
4325 "output to stdout, an integer is base port number, \"disabled\" disables "
4326 "port. Any other string is are interpreted as named pipe to listen to. "
4327 "Output pipe is the same name as input pipe, but with 'o' appended.",
4328 .usage =
"[port_num]",
4331 .name =
"memory_map",
4332 .handler = handle_gdb_memory_map_command,
4334 .help =
"enable or disable memory map",
4335 .usage =
"('enable'|'disable')"
4338 .name =
"flash_program",
4339 .handler = handle_gdb_flash_program_command,
4341 .help =
"enable or disable flash program",
4342 .usage =
"('enable'|'disable')"
4345 .name =
"report_data_abort",
4346 .handler = handle_gdb_report_data_abort_command,
4348 .help =
"enable or disable reporting data aborts",
4349 .usage =
"('enable'|'disable')"
4352 .name =
"report_register_access_error",
4353 .handler = handle_gdb_report_register_access_error,
4355 .help =
"enable or disable reporting register access errors",
4356 .usage =
"('enable'|'disable')"
4359 .name =
"breakpoint_override",
4360 .handler = handle_gdb_breakpoint_override_command,
4362 .help =
"Display or specify type of breakpoint "
4363 "to be used by gdb 'break' commands.",
4364 .usage =
"('hard'|'soft'|'disable')"
4367 .name =
"target_description",
4368 .handler = handle_gdb_target_description_command,
4370 .help =
"enable or disable target description",
4371 .usage =
"('enable'|'disable')"
4374 .name =
"save_tdesc",
4375 .handler = handle_gdb_save_tdesc_command,
4377 .help =
"Save the target description file",
4387 .help =
"GDB commands",
struct reg_data_type * data_type
size_t hexify(char *hex, const uint8_t *bin, size_t count, size_t length)
Convert binary data into a string of hexadecimal pairs.
size_t unhexify(uint8_t *bin, const char *hex, size_t count)
Convert a string of hexadecimal pairs into its binary representation.
int watchpoint_add(struct target *target, target_addr_t address, unsigned int length, enum watchpoint_rw rw, uint64_t value, uint64_t mask)
int breakpoint_remove(struct target *target, target_addr_t address)
int watchpoint_hit(struct target *target, enum watchpoint_rw *rw, target_addr_t *address)
int watchpoint_remove(struct target *target, target_addr_t address)
int breakpoint_add(struct target *target, target_addr_t address, unsigned int length, enum breakpoint_type type)
int watchpoint_remove_all(struct target *target)
int breakpoint_remove_all(struct target *target)
#define WATCHPOINT_IGNORE_DATA_VALUE_MASK
void command_print(struct command_invocation *cmd, const char *format,...)
int command_run_linef(struct command_context *context, const char *format,...)
void command_set_output_handler(struct command_context *context, command_output_handler_t output_handler, void *priv)
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
#define CALL_COMMAND_HANDLER(name, extra ...)
Use this to macro to call a command helper (or a nested handler).
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
#define PRINTF_ATTRIBUTE_FORMAT
#define ERROR_COMMAND_SYNTAX_ERROR
int parse_long(const char *str, long *ul)
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
#define COMMAND_PARSE_ENABLE(in, out)
parses an enable/disable command argument
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
static int register_commands(struct command_context *cmd_ctx, const char *cmd_prefix, const struct command_registration *cmds)
Register one or more commands in the specified context, as children of parent (or top-level commends,...
uint32_t sector_size
Sector size.
uint64_t buffer
Pointer to data buffer to send over SPI.
uint32_t size
Size of dw_spi_transaction::buffer.
uint32_t address
Starting address. Sector aligned.
enum esirisc_reg_num number
static struct esp_usb_jtag * priv
#define ERROR_FLASH_DST_OUT_OF_BANK
struct flash_bank * get_flash_bank_by_num_noprobe(unsigned int num)
Returns the flash bank like get_flash_bank_by_num(), without probing.
unsigned int flash_get_bank_count(void)
int flash_erase_address_range(struct target *target, bool pad, target_addr_t addr, uint32_t length)
Erases length bytes in the target flash, starting at addr.
int flash_write(struct target *target, struct image *image, uint32_t *written, bool erase)
Writes image into the target flash.
int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank)
Returns the flash bank like get_flash_bank_by_name(), without probing.
static int gdb_read_memory_packet(struct connection *connection, char const *packet, int packet_size)
static void gdb_fileio_reply(struct target *target, struct connection *connection)
static void gdb_signal_reply(struct target *target, struct connection *connection)
struct target * get_available_target_from_connection(struct connection *connection)
static int gdb_get_char_inner(struct connection *connection, int *next_char)
static int gdb_target_start(struct target *target, const char *port)
static int gdb_output_con(struct connection *connection, const char *line)
static void gdb_async_notif(struct connection *connection)
static int gdb_v_packet(struct connection *connection, char const *packet, int packet_size)
static void gdb_log_incoming_packet(struct connection *connection, const char *packet)
static const struct service_driver gdb_service_driver
int gdb_put_packet(struct connection *connection, const char *buffer, int len)
static int gdb_input_inner(struct connection *connection)
static int gdb_get_registers_packet(struct connection *connection, char const *packet, int packet_size)
static int gdb_target_add_one(struct target *target)
static void gdb_sig_halted(struct connection *connection)
static bool gdb_handle_vrun_packet(struct connection *connection, const char *packet, int packet_size)
static int gdb_reg_pos(struct target *target, int pos, int len)
static int gdb_generate_thread_list(struct target *target, char **thread_list_out)
static struct gdb_connection * current_gdb_connection
COMMAND_HANDLER(handle_gdb_sync_command)
static int gdb_detach(struct connection *connection)
static int compare_bank(const void *a, const void *b)
int gdb_register_commands(struct command_context *cmd_ctx)
static void gdb_keep_client_alive(struct connection *connection)
static int gdb_target_callback_event_handler(struct target *target, enum target_event event, void *priv)
static char gdb_running_type
static int gdb_get_reg_value_as_str(struct target *target, char *tstr, struct reg *reg)
static int gdb_query_packet(struct connection *connection, char const *packet, int packet_size)
static int gdb_get_thread_list_chunk(struct target *target, char **thread_list, char **chunk, int32_t offset, uint32_t length)
static char * next_hex_encoded_field(const char **str, char sep)
static void gdb_restart_inferior(struct connection *connection, const char *packet, int packet_size)
static COMMAND_HELPER(gdb_service_info, const struct service *service)
int gdb_target_add_all(struct target *target)
static int gdb_set_registers_packet(struct connection *connection, char const *packet, int packet_size)
static int gdb_generate_reg_type_description(struct target *target, char **tdesc, int *pos, int *size, struct reg_data_type *type, char const **arch_defined_types_list[], int *num_arch_defined_types)
static void gdb_log_outgoing_packet(struct connection *connection, const char *packet_buf, unsigned int packet_len, unsigned char checksum)
static int decode_xfer_read(char const *buf, char **annex, int *ofs, unsigned int *len)
static int gdb_fileio_response_packet(struct connection *connection, char const *packet, int packet_size)
static int gdb_memory_map(struct connection *connection, char const *packet, int packet_size)
static int gdb_get_packet(struct connection *connection, char *buffer, int *len)
static int check_pending(struct connection *connection, int timeout_s, int *got_data)
static int parse_packet_addr_len(char const *packet, uint64_t *addr, uint32_t *len)
static int gdb_error(struct connection *connection, int retval)
static int gdb_read_memory(struct connection *connection, uint8_t *buffer, uint64_t addr, uint32_t len)
static int gdb_put_packet_inner(struct connection *connection, const char *buffer, int len)
static int gdb_actual_connections
static void gdb_frontend_halted(struct target *target, struct connection *connection)
static int gdb_connection_closed(struct connection *connection)
static const struct command_registration gdb_command_handlers[]
static int gdb_input(struct connection *connection)
static int gdb_new_connection(struct connection *connection)
static int gdb_get_char_fast(struct connection *connection, int *next_char, char **buf_p, int *buf_cnt)
The cool thing about this fn is that it allows buf_p and buf_cnt to be held in registers in the inner...
static int get_reg_features_list(struct target *target, char const **feature_list[], int *feature_list_size, struct reg **reg_list, int reg_list_size)
static int gdb_get_target_description_chunk(struct target *target, struct target_desc_format *target_desc, char **chunk, int32_t offset, uint32_t length)
static int gdb_get_register_packet(struct connection *connection, char const *packet, int packet_size)
int gdb_get_actual_connections(void)
static char * gdb_port_next
static int gdb_write_memory_packet(struct connection *connection, char const *packet, int packet_size)
static void gdb_log_outgoing_async_notif(struct connection *connection, const char *buf, unsigned int len)
static __attribute__((format(PRINTF_ATTRIBUTE_FORMAT, 5, 6)))
static int gdb_get_char(struct connection *connection, int *next_char)
void gdb_service_free(void)
static int gdb_read_memory_packet_binary(struct connection *connection, char const *packet, int packet_size)
static bool gdb_use_target_description
static int gdb_write(struct connection *connection, const void *data, int len)
static bool gdb_handle_vcont_packet(struct connection *connection, const char *packet, __attribute__((unused)) int packet_size)
static int gdb_putback_char(struct connection *connection, int last_char)
static enum breakpoint_type gdb_breakpoint_override_type
static int gdb_write_memory_binary_packet(struct connection *connection, char const *packet, int packet_size)
static int gdb_breakpoint_override
static int smp_reg_list_noread(struct target *target, struct reg **combined_list[], int *combined_list_size, enum target_register_class reg_class)
static int gdb_report_data_abort
static size_t escape_binary_data(const uint8_t *data, char *out, size_t data_len)
static int gdb_target_description_supported(struct target *target, bool *supported)
static int gdb_report_register_access_error
static int gdb_generate_target_description(struct target *target, char **tdesc_out)
static void gdb_str_to_target(struct target *target, char *tstr, struct reg *reg)
static int gdb_last_signal(struct target *target)
static bool gdb_flash_program
static void gdb_send_error(struct connection *connection, uint8_t the_error)
static int gdb_get_packet_inner(struct connection *connection, char *buffer, int *len)
static bool gdb_use_memory_map
static int gdb_last_signal_packet(struct connection *connection, char const *packet, int packet_size)
static int fetch_packet(struct connection *connection, int *checksum_ok, int noack, int *len, char *buffer)
static const char * gdb_get_reg_type_name(enum reg_type type)
static int gdb_output(struct command_context *context, const char *line)
static void gdb_log_callback(void *priv, const char *file, unsigned int line, const char *function, const char *string)
static int lookup_add_arch_defined_types(char const **arch_defined_types_list[], const char *type_id, int *num_arch_defined_types)
static int gdb_step_continue_packet(struct connection *connection, char const *packet, int packet_size)
static int gdb_breakpoint_watchpoint_packet(struct connection *connection, char const *packet, int packet_size)
static int gdb_set_register_packet(struct connection *connection, char const *packet, int packet_size)
static const struct command_registration gdb_subcommand_handlers[]
static void gdb_target_to_reg(struct target *target, char const *tstr, int str_len, uint8_t *bin)
#define ERROR_GDB_INVALID_PACKET_LEN
#define ERROR_GDB_BUFFER_TOO_SMALL
#define ERROR_GDB_TIMEOUT
static struct target * get_target_from_connection(struct connection *connection)
int fileio_write(struct fileio *fileio, size_t size, const void *buffer, size_t *size_written)
int fileio_close(struct fileio *fileio)
int fileio_open(struct fileio **fileio, const char *url, enum fileio_access access_type, enum fileio_type type)
void image_close(struct image *image)
int image_add_section(struct image *image, target_addr_t base, uint32_t size, uint64_t flags, uint8_t const *data)
int image_open(struct image *image, const char *url, const char *type_string)
The JTAG interface can be implemented with a software or hardware fifo.
int log_remove_callback(log_callback_fn fn, void *priv)
void log_printf_lf(enum log_levels level, const char *file, unsigned int line, const char *function, const char *format,...)
int log_add_callback(log_callback_fn fn, void *priv)
void log_socket_error(const char *socket_desc)
const char * find_nonprint_char(const char *buf, unsigned int buf_len)
Find the first non-printable character in the char buffer, return a pointer to it.
char * alloc_printf(const char *format,...)
#define LOG_TARGET_INFO(target, fmt_str,...)
#define LOG_USER(expr ...)
#define LOG_TARGET_WARNING(target, fmt_str,...)
#define ERROR_NOT_IMPLEMENTED
#define LOG_WARNING(expr ...)
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_TARGET_DEBUG(target, fmt_str,...)
#define LOG_USER_N(expr ...)
#define LOG_ERROR(expr ...)
#define LOG_LEVEL_IS(FOO)
#define LOG_INFO(expr ...)
#define LOG_DEBUG(expr ...)
Upper level NOR flash interfaces.
void flash_set_dirty(void)
Forces targets to re-examine their erase/protection state.
char * strndup(const char *s, size_t n)
static int socket_select(int max_fd, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
static int read_socket(int handle, void *buffer, unsigned int count)
#define OCD_FD_SET(fd, set)
#define OCD_FD_ISSET(fd, set)
struct target * rtos_swbp_target(struct target *target, target_addr_t address, uint32_t length, enum breakpoint_type type)
int gdb_thread_packet(struct connection *connection, char const *packet, int packet_size)
int rtos_set_reg(struct connection *connection, int reg_num, uint8_t *reg_value)
int rtos_get_gdb_reg_list(struct connection *connection)
Return a list of general registers.
int rtos_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
int rtos_update_threads(struct target *target)
int rtos_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
bool rtos_needs_fake_step(struct target *target, int64_t thread_id)
struct rtos * rtos_from_target(struct target *target)
Get the RTOS from the target itself, or from one of the targets in the same SMP node,...
int rtos_get_gdb_reg(struct connection *connection, int reg_num)
Look through all registers to find this register.
#define GDB_THREAD_PACKET_NOT_CONSUMED
target_addr_t addr
Start address to search for the control block.
int connection_write(struct connection *connection, const void *data, int len)
int add_service(const struct service_driver *driver, const char *port, int max_connections, void *priv)
#define ERROR_SERVER_REMOTE_CLOSED
int gdb_read_smp_packet(struct connection *connection, char const *packet, int packet_size)
#define foreach_smp_target(pos, head)
struct target * current_target_override
struct target * current_target
const char * usage
a string listing the options and arguments, required or optional
struct command_context * cmd_ctx
Provides details of a flash bank, available either on-chip or through a major interface.
struct flash_sector * sectors
Array of sectors, allocated and initialized by the flash driver.
target_addr_t base
The base address of this bank.
uint32_t size
The size of this chip bank, in bytes.
unsigned int num_sectors
The number of sectors on this chip.
bool read_only
a ROM region - mainly to list in gdb memory map
struct target * target
Target to which this bank belongs.
uint32_t offset
Bus offset from start of the flash chip (in bytes).
uint32_t size
Number of bytes in this flash sector.
enum gdb_output_flag output_flag
enum target_state frontend_state
unsigned int unique_index
struct target_desc_format target_desc
struct image * vflash_image
char buffer[GDB_BUFFER_SIZE+1]
int(* get)(struct reg *reg)
int(* set)(struct reg *reg, uint8_t *buf)
struct reg_data_type_flags_field * next
struct reg_data_type_bitfield * bitfield
struct reg_data_type * type
struct reg_data_type_bitfield * bitfield
struct reg_data_type_struct_field * next
struct reg_data_type * type
struct reg_data_type_union_field * next
struct reg_feature * feature
struct reg_data_type * reg_data_type
const struct reg_arch_type * type
int(* clean)(struct target *target)
const struct rtos_type * type
struct thread_detail * thread_details
int(* gdb_target_for_threadid)(struct connection *connection, int64_t thread_id, struct target **p_target)
threadid_t current_thread
char * cmdline
The semihosting command line to be passed to the target.
const char * name
the name of the server
char * port
The 'port', which can be an integer for TCP, or 'disabled', 'pipe' (stdin/out) or a FIFO path.
enum connection_type type
int(* step)(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
int(* gdb_query_custom)(struct target *target, const char *packet, char **response_p)
struct semihosting * semihosting
struct gdb_service * gdb_service
enum target_debug_reason debug_reason
enum target_endianness endianness
struct list_head * smp_targets
struct gdb_fileio_info * fileio_info
struct target_type * type
int target_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
Obtain file-I/O information from target for GDB to do syscall.
struct target * all_targets
int target_call_event_callbacks(struct target *target, enum target_event event)
int target_unregister_event_callback(int(*callback)(struct target *target, enum target_event event, void *priv), void *priv)
int target_register_event_callback(int(*callback)(struct target *target, enum target_event event, void *priv), void *priv)
int target_halt(struct target *target)
int target_get_gdb_reg_list_noread(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Obtain the registers for GDB, but don't read register values from the target.
bool target_supports_gdb_connection(const struct target *target)
Check if target allows GDB connections.
int target_call_timer_callbacks_now(void)
Invoke this to ensure that e.g.
int target_checksum_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t *crc)
int target_write_buffer(struct target *target, target_addr_t address, uint32_t size, const uint8_t *buffer)
target_addr_t target_address_max(struct target *target)
Return the highest accessible address for this target.
int target_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
Pass GDB file-I/O response to target after finishing host syscall.
int target_read_buffer(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer)
int target_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Obtain the registers for GDB.
const char * target_debug_reason_str(enum target_debug_reason reason)
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
int target_poll(struct target *target)
int target_resume(struct target *target, bool current, target_addr_t address, bool handle_breakpoints, bool debug_execution)
Make the target (re)start executing using its saved execution context (possibly with some modificatio...
const char * target_get_gdb_arch(const struct target *target)
Obtain the architecture for GDB.
int target_step(struct target *target, bool current, target_addr_t address, bool handle_breakpoints)
Step the target.
struct target * get_current_target(struct command_context *cmd_ctx)
const char * target_type_name(const struct target *target)
Get the target type name.
#define ERROR_TARGET_NOT_HALTED
static bool target_was_examined(const struct target *target)
@ TARGET_EVENT_GDB_FLASH_WRITE_END
@ TARGET_EVENT_GDB_FLASH_ERASE_START
@ TARGET_EVENT_GDB_FLASH_WRITE_START
@ TARGET_EVENT_GDB_ATTACH
@ TARGET_EVENT_GDB_FLASH_ERASE_END
@ TARGET_EVENT_GDB_DETACH
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
#define ERROR_TARGET_NOT_EXAMINED
#define ERROR_TARGET_RESOURCE_NOT_AVAILABLE
int delete_debug_msg_receiver(struct command_context *cmd_ctx, struct target *target)
char * tcl_escape_alloc(Jim_Interp *interp, const char *s)
Convert a C string to a string that can be used for Tcl list.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.