107 #define _DEBUG_GDB_IO_
120 const char *
function,
const char *
string);
171 LOG_USER(
"undefined debug reason %d (%s) - target needs reset",
179 int timeout_s,
int *got_data)
220 #ifdef _DEBUG_GDB_IO_
238 LOG_DEBUG(
"GDB connection closed by the remote client");
244 bool retry = (WSAGetLastError() == WSAEWOULDBLOCK);
246 bool retry = (errno == EAGAIN);
260 #ifdef _DEBUG_GDB_IO_
262 LOG_DEBUG(
"received '%s'", debug_buffer);
268 *next_char = *(gdb_con->
buf_p++);
273 #ifdef _DEBUG_GDB_IO_
274 LOG_DEBUG(
"returned char '%c' (0x%2.2x)", *next_char, *next_char);
292 *next_char = **
buf_p;
299 #ifdef _DEBUG_GDB_IO_
300 LOG_DEBUG(
"returned char '%c' (0x%2.2x)", *next_char, *next_char);
327 *(--gdb_con->
buf_p) = last_char;
330 LOG_ERROR(
"BUG: couldn't put character back");
342 LOG_DEBUG(
"GDB socket marked as closed, cannot write to it.");
349 LOG_WARNING(
"Error writing to GDB socket. Dropping the connection.");
363 const unsigned packet_len = strlen(packet);
368 const char *colon = memchr(packet,
':',
MIN(50, packet_len));
369 const bool packet_has_prefix = (colon);
370 const bool packet_prefix_printable = (packet_has_prefix && nonprint > colon);
372 if (packet_prefix_printable) {
373 const unsigned int prefix_len = colon - packet + 1;
374 const unsigned int payload_len = packet_len - prefix_len;
388 unsigned int packet_len,
unsigned char checksum)
408 unsigned char my_checksum = 0;
413 for (i = 0; i < len; i++)
416 #ifdef _DEBUG_GDB_IO_
435 LOG_DEBUG(
"Unexpected start of new packet");
446 char local_buffer[1024];
447 local_buffer[0] =
'$';
448 if ((
size_t)len + 4 <=
sizeof(local_buffer)) {
450 memcpy(local_buffer + 1,
buffer, len++);
451 len += snprintf(local_buffer + len,
sizeof(local_buffer) - len,
"#%02x", my_checksum);
458 snprintf(local_buffer + 1,
sizeof(local_buffer) - 1,
"#%02x", my_checksum);
480 }
else if (reply ==
'-') {
485 }
else if (reply == 0x3) {
494 }
else if (reply ==
'-') {
499 }
else if (reply ==
'$') {
500 LOG_ERROR(
"GDB missing ack(1) - assumed good");
504 LOG_ERROR(
"unknown character(1) 0x%2.2x in reply, dropping connection", reply);
508 }
else if (reply ==
'$') {
509 LOG_ERROR(
"GDB missing ack(2) - assumed good");
513 LOG_ERROR(
"unknown character(2) 0x%2.2x in reply, dropping connection",
528 gdb_con->
busy =
true;
530 gdb_con->
busy =
false;
539 int *checksum_ok,
int noack,
int *len,
char *
buffer)
541 unsigned char my_checksum = 0;
574 if (character ==
'#') {
581 if (character ==
'}') {
584 my_checksum += character & 0xff;
587 my_checksum += character & 0xff;
590 my_checksum += character & 0xff;
609 if (character ==
'#')
612 if (character ==
'}') {
615 my_checksum += character & 0xff;
621 my_checksum += character & 0xff;
624 my_checksum += character & 0xff;
640 checksum[0] = character;
644 checksum[1] = character;
648 *checksum_ok = (my_checksum == strtoul(checksum,
NULL, 16));
666 #ifdef _DEBUG_GDB_IO_
685 LOG_WARNING(
"acknowledgment received, but no packet pending");
687 LOG_DEBUG(
"Received first acknowledgment after entering noack mode. Ignoring it.");
693 LOG_WARNING(
"negative acknowledgment, but no packet pending");
704 }
while (character !=
'$');
739 gdb_con->
busy =
true;
741 gdb_con->
busy =
false;
750 bin_size = strlen(line);
752 hex_buffer = malloc(bin_size * 2 + 2);
757 size_t pkt_len =
hexify(hex_buffer + 1, (
const uint8_t *)line, bin_size,
776 char stop_reason[32];
784 sig_reply_len = snprintf(sig_reply,
sizeof(sig_reply),
"W00");
800 stop_reason[0] =
'\0';
807 switch (hit_wp_type) {
809 snprintf(stop_reason,
sizeof(stop_reason),
813 snprintf(stop_reason,
sizeof(stop_reason),
817 snprintf(stop_reason,
sizeof(stop_reason),
831 sig_reply_len = snprintf(sig_reply,
sizeof(sig_reply),
"T%2.2x%s%s",
844 char fileio_command[256];
846 bool program_exited =
false;
905 program_exited =
true;
916 command_len = strlen(fileio_command);
919 if (program_exited) {
983 static unsigned int next_unique_id = 1;
1028 if (initial_ack !=
'+')
1055 LOG_ERROR(
"Connect failed. Consider setting up a gdb-attach event for the target "
1056 "to prepare target for GDB connect, or use 'gdb_memory_map disable'.");
1063 __FILE__, __LINE__, __func__,
1064 "New GDB Connection: %d, Target %s, state: %s",
1070 LOG_ERROR(
"Target %s not examined yet, refuse gdb connection %d!",
1077 LOG_WARNING(
"GDB connection %d on target %s not halted",
1105 LOG_DEBUG(
"{%d} GDB Close, Target: %s, state: %s, gdb_actual_connections=%d",
1136 snprintf(err, 4,
"E%2.2X", the_error);
1141 char const *packet,
int packet_size)
1157 snprintf(sig_reply, 4,
"S%2.2x", signal_var);
1168 return len - 1 - pos;
1181 char *tstr,
struct reg *
reg)
1190 for (i = 0; i < buf_len; i++) {
1192 tstr += sprintf(tstr,
"%02x", buf[j]);
1198 char const *tstr,
int str_len, uint8_t *bin)
1201 LOG_ERROR(
"BUG: gdb value with uneven number of characters encountered");
1206 for (i = 0; i < str_len; i += 2) {
1208 if (sscanf(tstr + i,
"%02x", &t) != 1) {
1209 LOG_ERROR(
"BUG: unable to convert register value");
1232 memset(tstr,
'x', len);
1240 char const *packet,
int packet_size)
1243 struct reg **reg_list;
1246 int reg_packet_size = 0;
1251 #ifdef _DEBUG_GDB_IO_
1263 for (i = 0; i < reg_list_size; i++) {
1264 if (!reg_list[i] || reg_list[i]->
exist ==
false || reg_list[i]->
hidden)
1269 assert(reg_packet_size > 0);
1271 reg_packet = malloc(reg_packet_size + 1);
1275 reg_packet_p = reg_packet;
1277 for (i = 0; i < reg_list_size; i++) {
1278 if (!reg_list[i] || reg_list[i]->
exist ==
false || reg_list[i]->
hidden)
1288 #ifdef _DEBUG_GDB_IO_
1290 char *reg_packet_p_debug;
1291 reg_packet_p_debug =
strndup(reg_packet, reg_packet_size);
1292 LOG_DEBUG(
"reg_packet: %s", reg_packet_p_debug);
1293 free(reg_packet_p_debug);
1306 char const *packet,
int packet_size)
1310 struct reg **reg_list;
1313 char const *packet_p;
1315 #ifdef _DEBUG_GDB_IO_
1323 if (packet_size % 2) {
1324 LOG_WARNING(
"GDB set_registers packet with uneven characters received, dropping connection");
1334 for (i = 0; i < reg_list_size; i++) {
1336 if (!reg_list[i] || !reg_list[i]->
exist || reg_list[i]->
hidden)
1340 if (packet_p + chars > packet + packet_size)
1341 LOG_ERROR(
"BUG: register packet is too small for registers");
1346 retval = reg_list[i]->
type->
set(reg_list[i], bin_buf);
1369 char const *packet,
int packet_size)
1373 int reg_num = strtoul(packet + 1,
NULL, 16);
1374 struct reg **reg_list;
1378 #ifdef _DEBUG_GDB_IO_
1390 if ((reg_list_size <= reg_num) || !reg_list[reg_num] ||
1391 !reg_list[reg_num]->
exist || reg_list[reg_num]->
hidden) {
1392 LOG_ERROR(
"gdb requested a non-existing register (reg_num=%d)", reg_num);
1413 char const *packet,
int packet_size)
1417 int reg_num = strtoul(packet + 1, &separator, 16);
1418 struct reg **reg_list;
1422 #ifdef _DEBUG_GDB_IO_
1426 if (*separator !=
'=') {
1427 LOG_ERROR(
"GDB 'set register packet', but no '=' following the register number");
1430 size_t chars = strlen(separator + 1);
1431 uint8_t *bin_buf = malloc(chars / 2);
1448 if ((reg_list_size <= reg_num) || !reg_list[reg_num] ||
1449 !reg_list[reg_num]->
exist || reg_list[reg_num]->
hidden) {
1450 LOG_ERROR(
"gdb requested a non-existing register (reg_num=%d)", reg_num);
1457 LOG_ERROR(
"gdb sent %zu bits for a %" PRIu32
"-bit register (%s)",
1458 chars * 4, reg_list[reg_num]->
size, reg_list[reg_num]->
name);
1466 retval = reg_list[reg_num]->
type->
set(reg_list[reg_num], bin_buf);
1468 LOG_DEBUG(
"Couldn't set register %s.", reg_list[reg_num]->
name);
1488 LOG_DEBUG(
"Reporting %i to GDB as generic error", retval);
1494 char const *packet,
int packet_size)
1509 addr = strtoull(packet, &separator, 16);
1511 if (*separator !=
',') {
1512 LOG_ERROR(
"incomplete read memory packet received, dropping connection");
1516 len = strtoul(separator + 1,
NULL, 16);
1519 LOG_WARNING(
"invalid read memory packet received (len == 0)");
1526 LOG_DEBUG(
"addr: 0x%16.16" PRIx64
", len: 0x%8.8" PRIx32
"",
addr, len);
1553 hex_buffer = malloc(len * 2 + 1);
1555 size_t pkt_len =
hexify(hex_buffer,
buffer, len, len * 2 + 1);
1569 char const *packet,
int packet_size)
1582 addr = strtoull(packet, &separator, 16);
1584 if (*separator !=
',') {
1585 LOG_ERROR(
"incomplete write memory packet received, dropping connection");
1589 len = strtoul(separator + 1, &separator, 16);
1591 if (*(separator++) !=
':') {
1592 LOG_ERROR(
"incomplete write memory packet received, dropping connection");
1598 LOG_DEBUG(
"addr: 0x%" PRIx64
", len: 0x%8.8" PRIx32
"",
addr, len);
1601 LOG_ERROR(
"unable to decode memory packet");
1620 char const *packet,
int packet_size)
1631 uint32_t fast_limit = 8;
1636 addr = strtoull(packet, &separator, 16);
1638 if (*separator !=
',') {
1639 LOG_ERROR(
"incomplete write memory binary packet received, dropping connection");
1643 len = strtoul(separator + 1, &separator, 16);
1645 if (*(separator++) !=
':') {
1646 LOG_ERROR(
"incomplete write memory binary packet received, dropping connection");
1656 if (len >= fast_limit) {
1674 LOG_DEBUG(
"addr: 0x%" PRIx64
", len: 0x%8.8" PRIx32
"",
addr, len);
1686 if (len < fast_limit) {
1699 char const *packet,
int packet_size)
1703 uint64_t address = 0x0;
1708 if (packet_size > 1)
1709 address = strtoull(packet + 1,
NULL, 16);
1714 if (packet[0] ==
'c') {
1718 }
else if (packet[0] ==
's') {
1727 char const *packet,
int packet_size)
1740 type = strtoul(packet + 1, &separator, 16);
1753 LOG_ERROR(
"invalid gdb watch/breakpoint type(%d), dropping connection",
type);
1760 if (*separator !=
',') {
1761 LOG_ERROR(
"incomplete breakpoint/watchpoint packet received, dropping connection");
1765 address = strtoull(separator + 1, &separator, 16);
1767 if (*separator !=
',') {
1768 LOG_ERROR(
"incomplete breakpoint/watchpoint packet received, dropping connection");
1772 size = strtoul(separator + 1, &separator, 16);
1777 if (packet[0] ==
'Z') {
1797 if (packet[0] ==
'Z') {
1825 char **xml,
int *pos,
int *
size, const
char *fmt, ...)
1832 if ((!*xml) || (!first)) {
1838 *xml = realloc(*xml, *
size);
1849 ret = vsnprintf(*xml + *pos, *
size - *pos, fmt, ap);
1851 if ((ret > 0) && ((ret + 1) < *
size - *pos)) {
1863 const char *annex_end = strchr(buf,
':');
1870 *ofs = strtoul(annex_end + 1, &separator, 16);
1872 if (*separator !=
',')
1875 *len = strtoul(separator + 1,
NULL, 16);
1879 *annex =
strndup(buf, annex_end - buf);
1902 char const *packet,
int packet_size)
1922 unsigned int target_flash_banks = 0;
1927 offset = strtoul(packet, &separator, 16);
1928 length = strtoul(separator + 1, &separator, 16);
1930 xml_printf(&retval, &xml, &pos, &
size,
"<memory-map>\n");
1948 banks[target_flash_banks++] = p;
1951 qsort(banks, target_flash_banks,
sizeof(
struct flash_bank *),
1954 for (
unsigned int i = 0; i < target_flash_banks; i++) {
1956 unsigned group_len = 0;
1960 if (ram_start < p->
base)
1961 xml_printf(&retval, &xml, &pos, &
size,
1964 ram_start, p->
base - ram_start);
1972 for (
unsigned int j = 0; j < p->
num_sectors; j++) {
1977 LOG_WARNING(
"The flash sector at offset 0x%08" PRIx32
1978 " overflows the end of %s bank.",
1980 LOG_WARNING(
"The rest of bank will not show in gdb memory map.");
1985 xml_printf(&retval, &xml, &pos, &
size,
1986 "<memory type=\"flash\" "
2004 xml_printf(&retval, &xml, &pos, &
size,
2005 "length=\"0x%x\">\n"
2006 "<property name=\"blocksize\">"
2018 xml_printf(&retval, &xml, &pos, &
size,
2027 xml_printf(&retval, &xml, &pos, &
size,
"</memory-map>\n");
2038 char *t = malloc(
length + 1);
2084 return "ieee_single";
2086 return "ieee_double";
2095 int *num_arch_defined_types)
2097 int tbl_sz = *num_arch_defined_types;
2099 if (type_id && (strcmp(type_id,
""))) {
2100 for (
int j = 0; j < (tbl_sz + 1); j++) {
2101 if (!((*arch_defined_types_list)[j])) {
2102 (*arch_defined_types_list)[tbl_sz++] = type_id;
2103 *arch_defined_types_list = realloc(*arch_defined_types_list,
2104 sizeof(
char *) * (tbl_sz + 1));
2105 (*arch_defined_types_list)[tbl_sz] =
NULL;
2106 *num_arch_defined_types = tbl_sz;
2109 if (!strcmp((*arch_defined_types_list)[j], type_id))
2120 char const **arch_defined_types_list[],
int *num_arch_defined_types)
2128 num_arch_defined_types))
2130 arch_defined_types_list,
2131 num_arch_defined_types);
2134 xml_printf(&retval, tdesc, pos,
size,
2135 "<vector id=\"%s\" type=\"%s\" count=\"%" PRIu32
"\"/>\n",
2136 type->id,
type->reg_type_vector->type->id,
2137 type->reg_type_vector->count);
2141 field =
type->reg_type_union->fields;
2146 num_arch_defined_types))
2148 arch_defined_types_list,
2149 num_arch_defined_types);
2152 field = field->
next;
2157 xml_printf(&retval, tdesc, pos,
size,
2158 "<union id=\"%s\">\n",
2161 field =
type->reg_type_union->fields;
2163 xml_printf(&retval, tdesc, pos,
size,
2164 "<field name=\"%s\" type=\"%s\"/>\n",
2167 field = field->
next;
2170 xml_printf(&retval, tdesc, pos,
size,
2175 field =
type->reg_type_struct->fields;
2181 xml_printf(&retval, tdesc, pos,
size,
2182 "<struct id=\"%s\" size=\"%" PRIu32
"\">\n",
2183 type->id,
type->reg_type_struct->size);
2185 xml_printf(&retval, tdesc, pos,
size,
2186 "<field name=\"%s\" start=\"%" PRIu32
"\" end=\"%" PRIu32
"\" type=\"%s\" />\n",
2190 field = field->
next;
2197 num_arch_defined_types))
2199 arch_defined_types_list,
2200 num_arch_defined_types);
2207 xml_printf(&retval, tdesc, pos,
size,
2208 "<struct id=\"%s\">\n",
2211 xml_printf(&retval, tdesc, pos,
size,
2212 "<field name=\"%s\" type=\"%s\"/>\n",
2215 field = field->
next;
2219 xml_printf(&retval, tdesc, pos,
size,
2226 xml_printf(&retval, tdesc, pos,
size,
2227 "<flags id=\"%s\" size=\"%" PRIu32
"\">\n",
2228 type->id,
type->reg_type_flags->size);
2231 field =
type->reg_type_flags->fields;
2233 xml_printf(&retval, tdesc, pos,
size,
2234 "<field name=\"%s\" start=\"%" PRIu32
"\" end=\"%" PRIu32
"\" type=\"%s\" />\n",
2238 field = field->
next;
2241 xml_printf(&retval, tdesc, pos,
size,
2253 struct reg **reg_list,
int reg_list_size)
2258 *feature_list = calloc(1,
sizeof(
char *));
2260 for (
int i = 0; i < reg_list_size; i++) {
2261 if (reg_list[i]->exist ==
false || reg_list[i]->hidden)
2266 && (strcmp(reg_list[i]->
feature->name,
""))) {
2271 for (
int j = 0; j < (tbl_sz + 1); j++) {
2272 if (!((*feature_list)[j])) {
2273 (*feature_list)[tbl_sz++] = reg_list[i]->
feature->
name;
2274 *feature_list = realloc(*feature_list,
sizeof(
char *) * (tbl_sz + 1));
2275 (*feature_list)[tbl_sz] =
NULL;
2278 if (!strcmp((*feature_list)[j], reg_list[i]->
feature->name))
2285 if (feature_list_size)
2286 *feature_list_size = tbl_sz;
2296 struct reg **combined_list[],
int *combined_list_size,
2303 unsigned int combined_allocated = 256;
2304 struct reg **local_list = malloc(combined_allocated *
sizeof(
struct reg *));
2306 LOG_ERROR(
"malloc(%zu) failed", combined_allocated *
sizeof(
struct reg *));
2309 unsigned int local_list_size = 0;
2319 ®_list_size, reg_class);
2324 for (
int i = 0; i < reg_list_size; i++) {
2326 struct reg *a = reg_list[i];
2331 for (
unsigned int j = 0; j < local_list_size; j++) {
2332 struct reg *b = local_list[j];
2336 LOG_ERROR(
"SMP register %s is %d bits on one "
2337 "target, but %d bits on another target.",
2348 if (local_list_size >= combined_allocated) {
2349 combined_allocated *= 2;
2350 local_list = realloc(local_list, combined_allocated *
sizeof(
struct reg *));
2352 LOG_ERROR(
"realloc(%zu) failed", combined_allocated *
sizeof(
struct reg *));
2357 local_list[local_list_size] = a;
2365 if (local_list_size == 0) {
2366 LOG_ERROR(
"Unable to get register list");
2379 ®_list_size, reg_class);
2384 for (
unsigned int i = 0; i < local_list_size; i++) {
2386 struct reg *a = local_list[i];
2387 for (
int j = 0; j < reg_list_size; j++) {
2388 struct reg *b = reg_list[j];
2395 LOG_WARNING(
"Register %s does not exist in %s, which is part of an SMP group where "
2396 "this register does exist.",
2403 *combined_list = local_list;
2404 *combined_list_size = local_list_size;
2413 char const *architecture;
2414 char const **features =
NULL;
2415 int feature_list_size = 0;
2430 if (reg_list_size <= 0) {
2439 LOG_ERROR(
"Can't get the registers feature list");
2445 int current_feature = 0;
2447 xml_printf(&retval, &tdesc, &pos, &
size,
2448 "<?xml version=\"1.0\"?>\n"
2449 "<!DOCTYPE target SYSTEM \"gdb-target.dtd\">\n"
2450 "<target version=\"1.0\">\n");
2455 xml_printf(&retval, &tdesc, &pos, &
size,
2456 "<architecture>%s</architecture>\n", architecture);
2460 while (features[current_feature]) {
2461 char const **arch_defined_types =
NULL;
2462 int num_arch_defined_types = 0;
2464 arch_defined_types = calloc(1,
sizeof(
char *));
2465 xml_printf(&retval, &tdesc, &pos, &
size,
2466 "<feature name=\"%s\">\n",
2467 features[current_feature]);
2470 for (i = 0; i < reg_list_size; i++) {
2472 if (reg_list[i]->
exist ==
false || reg_list[i]->
hidden)
2475 if (strcmp(reg_list[i]->
feature->name, features[current_feature]))
2478 const char *type_str;
2484 &num_arch_defined_types))
2487 &arch_defined_types,
2488 &num_arch_defined_types);
2501 xml_printf(&retval, &tdesc, &pos, &
size,
2502 "<reg name=\"%s\"", reg_list[i]->
name);
2503 xml_printf(&retval, &tdesc, &pos, &
size,
2504 " bitsize=\"%" PRIu32
"\"", reg_list[i]->
size);
2505 xml_printf(&retval, &tdesc, &pos, &
size,
2506 " regnum=\"%" PRIu32
"\"", reg_list[i]->
number);
2508 xml_printf(&retval, &tdesc, &pos, &
size,
2509 " save-restore=\"yes\"");
2511 xml_printf(&retval, &tdesc, &pos, &
size,
2512 " save-restore=\"no\"");
2514 xml_printf(&retval, &tdesc, &pos, &
size,
2515 " type=\"%s\"", type_str);
2517 if (reg_list[i]->
group)
2518 xml_printf(&retval, &tdesc, &pos, &
size,
2519 " group=\"%s\"", reg_list[i]->
group);
2521 xml_printf(&retval, &tdesc, &pos, &
size,
2525 xml_printf(&retval, &tdesc, &pos, &
size,
2529 free(arch_defined_types);
2533 xml_printf(&retval, &tdesc, &pos, &
size,
2552 LOG_ERROR(
"Unable to Generate Target Description");
2556 char *tdesc = target_desc->
tdesc;
2562 LOG_ERROR(
"Unable to Generate Target Description");
2566 tdesc_length = strlen(tdesc);
2572 transfer_type =
'm';
2574 transfer_type =
'l';
2576 *chunk = malloc(
length + 2);
2582 (*chunk)[0] = transfer_type;
2583 if (transfer_type ==
'm') {
2585 (*chunk)[1 +
length] =
'\0';
2587 strncpy((*chunk) + 1, tdesc +
offset, tdesc_length -
offset);
2588 (*chunk)[1 + (tdesc_length -
offset)] =
'\0';
2596 target_desc->
tdesc = tdesc;
2606 int reg_list_size = 0;
2607 char const **features =
NULL;
2608 int feature_list_size = 0;
2619 if (reg_list_size <= 0) {
2628 LOG_ERROR(
"Can't get the registers feature list");
2633 if (architecture || feature_list_size)
2651 char *thread_list =
NULL;
2655 xml_printf(&retval, &thread_list, &pos, &
size,
2656 "<?xml version=\"1.0\"?>\n"
2667 xml_printf(&retval, &thread_list, &pos, &
size,
2668 "<thread id=\"%" PRIx64
"\" name=\"%s\">",
2672 xml_printf(&retval, &thread_list, &pos, &
size,
2676 xml_printf(&retval, &thread_list, &pos, &
size,
2681 xml_printf(&retval, &thread_list, &pos, &
size,
2683 xml_printf(&retval, &thread_list, &pos, &
size,
2687 xml_printf(&retval, &thread_list, &pos, &
size,
2692 xml_printf(&retval, &thread_list, &pos, &
size,
2696 *thread_list_out = thread_list;
2706 if (!*thread_list) {
2709 LOG_ERROR(
"Unable to Generate Thread List");
2714 size_t thread_list_length = strlen(*thread_list);
2719 transfer_type =
'm';
2721 transfer_type =
'l';
2723 *chunk = malloc(
length + 2 + 3);
2733 (*chunk)[0] = transfer_type;
2734 strncpy((*chunk) + 1, (*thread_list) +
offset,
length);
2735 (*chunk)[1 +
length] =
'\0';
2738 if (transfer_type ==
'l') {
2740 *thread_list =
NULL;
2747 char const *packet,
int packet_size)
2753 if (strncmp(packet,
"qRcmd,", 6) == 0) {
2754 if (packet_size > 6) {
2755 Jim_Interp *interp = cmd_ctx->
interp;
2757 cmd = malloc((packet_size - 6) / 2 + 1);
2758 size_t len =
unhexify((uint8_t *)
cmd, packet + 6, (packet_size - 6) / 2);
2772 Jim_DeleteAssocData(
interp,
"context");
2773 int retval = Jim_SetAssocData(
interp,
"context",
NULL, cmd_ctx);
2774 if (retval == JIM_OK) {
2776 Jim_DeleteAssocData(
interp,
"context");
2778 int inner_retval = Jim_SetAssocData(
interp,
"context",
NULL, old_context);
2779 if (retval == JIM_OK)
2780 retval = inner_retval;
2788 if (retval == JIM_RETURN)
2789 retval =
interp->returnCode;
2791 const char *cretmsg = Jim_GetString(Jim_GetResult(
interp), &lenmsg);
2793 if (lenmsg && cretmsg[lenmsg - 1] !=
'\n') {
2797 retmsg = strdup(cretmsg);
2802 if (retval == JIM_OK) {
2804 char *hex_buffer = malloc(lenmsg * 2 + 1);
2810 size_t pkt_len =
hexify(hex_buffer, (
const uint8_t *)retmsg, lenmsg,
2827 }
else if (strncmp(packet,
"qCRC:", 5) == 0) {
2828 if (packet_size > 5) {
2839 addr = strtoull(packet, &separator, 16);
2841 if (*separator !=
',') {
2842 LOG_ERROR(
"incomplete read memory packet received, dropping connection");
2846 len = strtoul(separator + 1,
NULL, 16);
2851 snprintf(gdb_reply, 10,
"C%8.8" PRIx32
"", checksum);
2861 }
else if (strncmp(packet,
"qSupported", 10) == 0) {
2868 int gdb_target_desc_supported = 0;
2873 LOG_INFO(
"Failed detecting Target Description Support, disabling");
2874 gdb_target_desc_supported = 0;
2879 if (gdb_target_desc_supported)
2880 LOG_WARNING(
"Target Descriptions Supported, but disabled");
2881 gdb_target_desc_supported = 0;
2888 "PacketSize=%x;qXfer:memory-map:read%c;qXfer:features:read%c;qXfer:threads:read+;QStartNoAckMode+;vContSupported+",
2891 (gdb_target_desc_supported == 1) ?
'+' :
'-');
2902 }
else if ((strncmp(packet,
"qXfer:memory-map:read::", 23) == 0)
2905 else if (strncmp(packet,
"qXfer:features:read:", 20) == 0) {
2936 }
else if (strncmp(packet,
"qXfer:threads:read:", 19) == 0) {
2967 }
else if (strncmp(packet,
"QStartNoAckMode", 15) == 0) {
2987 const char *parse = packet;
2991 if (parse[0] ==
'?') {
3000 if (parse[0] ==
';') {
3005 if (parse[0] ==
'c') {
3032 if (parse[0] ==
's') {
3034 bool fake_step =
false;
3040 if (parse[0] ==
':') {
3043 thread_id = strtoll(parse, &endp, 16);
3065 if (parse[0] ==
';') {
3068 if (parse[0] ==
'c') {
3072 if (parse[0] ==
':') {
3076 tid = strtoll(parse,
NULL, 16);
3077 if (tid == thread_id) {
3087 LOG_DEBUG(
"request to step current core only");
3109 char sig_reply[128];
3111 LOG_DEBUG(
"fake step thread %"PRIx64, thread_id);
3113 sig_reply_len = snprintf(sig_reply,
sizeof(sig_reply),
3114 "T05thread:%016"PRIx64
";", thread_id);
3126 LOG_DEBUG(
"stepi ignored. GDB will now fetch the register state "
3127 "from the target.");
3159 const char *hex = *str;
3163 const char *end = strchr(hex, sep);
3165 hexlen = strlen(hex);
3168 *str = hex + hexlen + 1;
3170 if (hexlen % 2 != 0) {
3175 size_t count = hexlen / 2;
3176 char *decoded = malloc(
count + 1);
3181 if (converted !=
count) {
3186 decoded[
count] =
'\0';
3209 const char *parse = packet;
3214 if (parse[0] !=
';')
3226 char *new_cmdline =
alloc_printf(
"%s %s", cmdline, arg);
3229 cmdline = new_cmdline;
3234 LOG_INFO(
"GDB set inferior command line to '%s'", cmdline);
3238 LOG_INFO(
"GDB set inferior command line to '%s' but semihosting is unavailable", cmdline);
3249 char const *packet,
int packet_size)
3256 if (strncmp(packet,
"vCont", 5) == 0) {
3269 if (strncmp(packet,
"vRun", 4) == 0) {
3286 if (strncmp(packet,
"vFlashErase:", 12) == 0) {
3290 char const *parse = packet + 12;
3291 if (*parse ==
'\0') {
3292 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3296 addr = strtoull(parse, (
char **)&parse, 16);
3298 if (*(parse++) !=
',' || *parse ==
'\0') {
3299 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3303 length = strtoul(parse, (
char **)&parse, 16);
3305 if (*parse !=
'\0') {
3306 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3335 LOG_ERROR(
"flash_erase returned %i", result);
3342 if (strncmp(packet,
"vFlashWrite:", 12) == 0) {
3346 char const *parse = packet + 12;
3348 if (*parse ==
'\0') {
3349 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3353 addr = strtoull(parse, (
char **)&parse, 16);
3354 if (*(parse++) !=
':') {
3355 LOG_ERROR(
"incomplete vFlashErase packet received, dropping connection");
3358 length = packet_size - (parse - packet);
3377 if (strncmp(packet,
"vFlashDone", 10) == 0) {
3401 LOG_DEBUG(
"wrote %u bytes from vFlash image to flash", (
unsigned)written);
3431 char const *packet,
int packet_size)
3435 char *parsing_point;
3436 int fileio_retcode = strtoul(packet + 1, &separator, 16);
3437 int fileio_errno = 0;
3438 bool fileio_ctrl_c =
false;
3443 if (*separator ==
',') {
3444 parsing_point = separator + 1;
3445 fileio_errno = strtoul(parsing_point, &separator, 16);
3446 if (*separator ==
',') {
3447 if (*(separator + 1) ==
'C') {
3449 fileio_ctrl_c =
true;
3454 LOG_DEBUG(
"File-I/O response, retcode: 0x%x, errno: 0x%x, ctrl-c: %s",
3455 fileio_retcode, fileio_errno, fileio_ctrl_c ?
"true" :
"false");
3476 const char *
function,
const char *
string)
3485 if (gdb_con->
busy) {
3496 snprintf(sig_reply, 4,
"T%2.2x", 2);
3506 char const *packet = gdb_packet_buffer;
3510 static bool warn_use_ext;
3532 gdb_packet_buffer[packet_size] =
'\0';
3534 if (packet_size > 0) {
3539 switch (packet[0]) {
3583 warn_use_ext =
true;
3584 LOG_WARNING(
"Prefer GDB command \"target extended-remote :%s\" instead of \"target remote :%s\"",
3602 bool nostep =
false;
3603 bool already_running =
false;
3605 LOG_WARNING(
"WARNING! The target is already running. "
3606 "All changes GDB did to registers will be discarded! "
3607 "Waiting for target to halt.");
3608 already_running =
true;
3610 LOG_WARNING(
"The target is not in the halted nor running stated, "
3611 "stepi/continue ignored.");
3613 }
else if ((packet[0] ==
's') && gdb_con->
sync) {
3619 LOG_DEBUG(
"stepi ignored. GDB will now fetch the register state "
3620 "from the target.");
3622 gdb_con->
sync =
false;
3624 if (!already_running && nostep) {
3643 if (!already_running) {
3715 LOG_DEBUG(
"ignoring 0x%2.2x packet", packet[0]);
3737 LOG_INFO(
"The target is not running when halt was requested, stopping GDB.");
3742 }
while (gdb_con->
buf_cnt > 0);
3779 static unsigned char count;
3780 unsigned char checksum = 0;
3783 int len = sprintf(buf,
"%%oocd_keepalive:%2.2x",
count++);
3784 for (
int i = 1; i < len; i++)
3786 len += sprintf(buf + len,
"#%2.2x", checksum);
3788 #ifdef _DEBUG_GDB_IO_
3818 .new_connection_during_keep_alive_handler =
NULL,
3874 if (strcmp(
gdb_port,
"disabled") == 0) {
3911 LOG_WARNING(
"gdb services need one or more targets defined");
3933 "gdb_sync command can only be run from within gdb using \"monitor gdb_sync\"");
3996 if (strcmp(
CMD_ARGV[0],
"hard") == 0)
3998 else if (strcmp(
CMD_ARGV[0],
"soft") == 0)
4000 else if (strcmp(
CMD_ARGV[0],
"disable") == 0)
4008 LOG_USER(
"breakpoint type is not overridden");
4025 uint32_t tdesc_length;
4030 LOG_ERROR(
"Unable to Generate Target Description");
4034 tdesc_length = strlen(tdesc);
4037 size_t size_written;
4040 if (!tdesc_filename) {
4048 LOG_ERROR(
"Can't open %s for writing", tdesc_filename);
4057 LOG_ERROR(
"Error while writing the tdesc file");
4060 free(tdesc_filename);
4069 .handler = handle_gdb_sync_command,
4071 .help =
"next stepi will return immediately allowing "
4072 "GDB to fetch register state without affecting "
4078 .handler = handle_gdb_port_command,
4080 .help =
"Normally gdb listens to a TCP/IP port. Each subsequent GDB "
4081 "server listens for the next port number after the "
4082 "base port number specified. "
4083 "No arguments reports GDB port. \"pipe\" means listen to stdin "
4084 "output to stdout, an integer is base port number, \"disabled\" disables "
4085 "port. Any other string is are interpreted as named pipe to listen to. "
4086 "Output pipe is the same name as input pipe, but with 'o' appended.",
4087 .usage =
"[port_num]",
4090 .name =
"gdb_memory_map",
4091 .handler = handle_gdb_memory_map_command,
4093 .help =
"enable or disable memory map",
4094 .usage =
"('enable'|'disable')"
4097 .name =
"gdb_flash_program",
4098 .handler = handle_gdb_flash_program_command,
4100 .help =
"enable or disable flash program",
4101 .usage =
"('enable'|'disable')"
4104 .name =
"gdb_report_data_abort",
4105 .handler = handle_gdb_report_data_abort_command,
4107 .help =
"enable or disable reporting data aborts",
4108 .usage =
"('enable'|'disable')"
4111 .name =
"gdb_report_register_access_error",
4112 .handler = handle_gdb_report_register_access_error,
4114 .help =
"enable or disable reporting register access errors",
4115 .usage =
"('enable'|'disable')"
4118 .name =
"gdb_breakpoint_override",
4119 .handler = handle_gdb_breakpoint_override_command,
4121 .help =
"Display or specify type of breakpoint "
4122 "to be used by gdb 'break' commands.",
4123 .usage =
"('hard'|'soft'|'disable')"
4126 .name =
"gdb_target_description",
4127 .handler = handle_gdb_target_description_command,
4129 .help =
"enable or disable target description",
4130 .usage =
"('enable'|'disable')"
4133 .name =
"gdb_save_tdesc",
4134 .handler = handle_gdb_save_tdesc_command,
4136 .help =
"Save the target description file",
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, uint32_t 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 watchpoint_clear_target(struct target *target)
int breakpoint_clear_target(struct target *target)
int breakpoint_add(struct target *target, target_addr_t address, uint32_t length, enum breakpoint_type type)
#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,...
enum esirisc_reg_num number
static struct esp_usb_jtag * priv
static const int sector_size
#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)
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_target_description_supported(struct target *target, int *supported)
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 const struct service_driver gdb_service_driver
static int gdb_input_inner(struct connection *connection)
static int gdb_put_packet_inner(struct connection *connection, char *buffer, int len)
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 void gdb_log_incoming_packet(struct connection *connection, char *packet)
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 void gdb_log_outgoing_packet(struct connection *connection, char *packet_buf, unsigned int packet_len, unsigned char checksum)
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)
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 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 gdb_error(struct connection *connection, int retval)
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)
static int gdb_flash_program
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 __attribute__((format(PRINTF_ATTRIBUTE_FORMAT, 5, 6)))
static int gdb_get_char(struct connection *connection, int *next_char)
void gdb_service_free(void)
static void gdb_log_callback(void *priv, const char *file, unsigned line, const char *function, const char *string)
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(struct connection *connection, void *data, int len)
static int gdb_write_memory_binary_packet(struct connection *connection, char const *packet, int packet_size)
static int gdb_use_memory_map
static int gdb_breakpoint_override
static int gdb_use_target_description
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 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 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 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 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)
int gdb_put_packet(struct connection *connection, char *buffer, int len)
static int gdb_set_register_packet(struct connection *connection, char const *packet, int packet_size)
static void gdb_target_to_reg(struct target *target, char const *tstr, int str_len, uint8_t *bin)
#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 line, const char *function, const char *format,...)
int log_add_callback(log_callback_fn fn, void *priv)
char * find_nonprint_char(char *buf, unsigned buf_len)
Find the first non-printable character in the char buffer, return a pointer to it.
void log_socket_error(const char *socket_desc)
char * alloc_printf(const char *format,...)
#define LOG_USER(expr ...)
#define ERROR_NOT_IMPLEMENTED
#define LOG_WARNING(expr ...)
#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)
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)
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.
size_t size
Size of the control block search area.
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)
int gdb_write_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
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.
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
enum connection_type type
int(* step)(struct target *target, int current, target_addr_t address, int 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)
int target_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
Step the target.
const char * target_state_name(const struct target *t)
Return the name of this targets current state.
int target_poll(struct target *target)
const char * target_get_gdb_arch(const struct target *target)
Obtain the architecture for GDB.
struct target * get_current_target(struct command_context *cmd_ctx)
const char * target_type_name(const struct target *target)
Get the target type name.
int target_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
Make the target (re)start executing using its saved execution context (possibly with some modificatio...
#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)
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.