/* private connection data for GDB */
struct gdb_connection {
- char buffer[GDB_BUFFER_SIZE + 1]; /* Extra byte for nul-termination */
+ char buffer[GDB_BUFFER_SIZE + 1]; /* Extra byte for null-termination */
char *buf_p;
int buf_cnt;
bool ctrl_c;
gdb_con->buf_cnt--;
*next_char = *(gdb_con->buf_p++);
if (gdb_con->buf_cnt > 0)
- connection->input_pending = 1;
+ connection->input_pending = true;
else
- connection->input_pending = 0;
+ connection->input_pending = false;
#ifdef _DEBUG_GDB_IO_
LOG_DEBUG("returned char '%c' (0x%2.2x)", *next_char, *next_char);
#endif
*next_char = **buf_p;
(*buf_p)++;
if (*buf_cnt > 0)
- connection->input_pending = 1;
+ connection->input_pending = true;
else
- connection->input_pending = 0;
+ connection->input_pending = false;
#ifdef _DEBUG_GDB_IO_
LOG_DEBUG("returned char '%c' (0x%2.2x)", *next_char, *next_char);
{
struct gdb_connection *gdb_connection = connection->priv;
char sig_reply[65];
- char stop_reason[20];
+ char stop_reason[32];
char current_thread[25];
int sig_reply_len;
int signal_var;
breakpoint_clear_target(target);
watchpoint_clear_target(target);
- if (target->rtos) {
- /* clean previous rtos session if supported*/
- if (target->rtos->type->clean)
- target->rtos->type->clean(target);
-
- /* update threads */
- rtos_update_threads(target);
- }
-
/* remove the initial ACK from the incoming buffer */
retval = gdb_get_char(connection, &initial_ack);
if (retval != ERROR_OK)
gdb_putback_char(connection, initial_ack);
target_call_event_callbacks(target, TARGET_EVENT_GDB_ATTACH);
+ if (target->rtos) {
+ /* clean previous rtos session if supported*/
+ if (target->rtos->type->clean)
+ target->rtos->type->clean(target);
+
+ /* update threads */
+ rtos_update_threads(target);
+ }
+
if (gdb_use_memory_map) {
/* Connect must fail if the memory map can't be set up correctly.
*
* This will cause an auto_probe to be invoked, which is either
* a no-op or it will fail when the target isn't ready(e.g. not halted).
*/
- int i;
- for (i = 0; i < flash_get_bank_count(); i++) {
+ for (unsigned int i = 0; i < flash_get_bank_count(); i++) {
struct flash_bank *p;
p = get_flash_bank_by_num_noprobe(i);
if (p->target != target)
continue;
retval = get_flash_bank_by_num(i, &p);
if (retval != ERROR_OK) {
- LOG_ERROR("Connect failed. Consider setting up a gdb-attach event for the target " \
+ LOG_ERROR("Connect failed. Consider setting up a gdb-attach event for the target "
"to prepare target for GDB connect, or use 'gdb_memory_map disable'.");
return retval;
}
target_name(target),
target_state_name(target));
+ if (!target_was_examined(target)) {
+ LOG_ERROR("Target %s not examined yet, refuse gdb connection %d!",
+ target_name(target), gdb_actual_connections);
+ gdb_actual_connections--;
+ return ERROR_TARGET_NOT_EXAMINED;
+ }
+
+ if (target->state != TARGET_HALTED)
+ LOG_WARNING("GDB connection %d on target %s not halted",
+ gdb_actual_connections, target_name(target));
+
/* DANGER! If we fail subsequently, we must remove this handler,
* otherwise we occasionally see crashes as the timer can invoke the
* callback fn.
/* if this connection registered a debug-message receiver delete it */
delete_debug_msg_receiver(connection->cmd_ctx, target);
- if (connection->priv) {
- free(connection->priv);
- connection->priv = NULL;
- } else
- LOG_ERROR("BUG: connection->priv == NULL");
+ free(connection->priv);
+ connection->priv = NULL;
target_unregister_event_callback(gdb_target_callback_event_handler, connection);
return gdb_error(connection, retval);
for (i = 0; i < reg_list_size; i++) {
- if (reg_list[i] == NULL || reg_list[i]->exist == false)
+ if (reg_list[i] == NULL || reg_list[i]->exist == false || reg_list[i]->hidden)
continue;
reg_packet_size += DIV_ROUND_UP(reg_list[i]->size, 8) * 2;
}
reg_packet_p = reg_packet;
for (i = 0; i < reg_list_size; i++) {
- if (reg_list[i] == NULL || reg_list[i]->exist == false)
+ if (reg_list[i] == NULL || reg_list[i]->exist == false || reg_list[i]->hidden)
continue;
if (!reg_list[i]->valid) {
retval = reg_list[i]->type->get(reg_list[i]);
}
}
- reg_packet = malloc(DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2 + 1); /* plus one for string termination null */
+ reg_packet = calloc(DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2 + 1, 1); /* plus one for string termination null */
gdb_str_to_target(target, reg_packet, reg_list[reg_num]);
}
if (chars != (DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2)) {
- LOG_ERROR("gdb sent %d bits for a %d-bit register (%s)",
- (int) chars * 4, reg_list[reg_num]->size, reg_list[reg_num]->name);
+ LOG_ERROR("gdb sent %zu bits for a %" PRIu32 "-bit register (%s)",
+ chars * 4, reg_list[reg_num]->size, reg_list[reg_num]->name);
free(bin_buf);
free(reg_list);
return ERROR_SERVER_REMOTE_CLOSED;
char *t = *xml;
*xml = realloc(*xml, *size);
if (*xml == NULL) {
- if (t)
- free(t);
+ free(t);
*retval = ERROR_SERVER_REMOTE_CLOSED;
return;
}
int length;
char *separator;
target_addr_t ram_start = 0;
- int i;
- int target_flash_banks = 0;
+ unsigned int target_flash_banks = 0;
/* skip command character */
packet += 23;
*/
banks = malloc(sizeof(struct flash_bank *)*flash_get_bank_count());
- for (i = 0; i < flash_get_bank_count(); i++) {
+ for (unsigned int i = 0; i < flash_get_bank_count(); i++) {
p = get_flash_bank_by_num_noprobe(i);
if (p->target != target)
continue;
qsort(banks, target_flash_banks, sizeof(struct flash_bank *),
compare_bank);
- for (i = 0; i < target_flash_banks; i++) {
- int j;
+ for (unsigned int i = 0; i < target_flash_banks; i++) {
unsigned sector_size = 0;
unsigned group_len = 0;
* smaller ones at the end (maybe 32KB). STR7 will have
* regions with 8KB, 32KB, and 64KB sectors; etc.
*/
- for (j = 0; j < p->num_sectors; j++) {
+ for (unsigned int j = 0; j < p->num_sectors; j++) {
/* Maybe start a new group of sectors. */
if (sector_size == 0) {
}
/* <vector id="id" type="type" count="count"/> */
xml_printf(&retval, tdesc, pos, size,
- "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>\n",
+ "<vector id=\"%s\" type=\"%s\" count=\"%" PRIu32 "\"/>\n",
type->id, type->reg_type_vector->type->id,
type->reg_type_vector->count);
* <field name="name" start="start" end="end"/> ...
* </struct> */
xml_printf(&retval, tdesc, pos, size,
- "<struct id=\"%s\" size=\"%d\">\n",
+ "<struct id=\"%s\" size=\"%" PRIu32 "\">\n",
type->id, type->reg_type_struct->size);
while (field != NULL) {
xml_printf(&retval, tdesc, pos, size,
- "<field name=\"%s\" start=\"%d\" end=\"%d\" type=\"%s\" />\n",
+ "<field name=\"%s\" start=\"%" PRIu32 "\" end=\"%" PRIu32 "\" type=\"%s\" />\n",
field->name, field->bitfield->start, field->bitfield->end,
gdb_get_reg_type_name(field->bitfield->type));
* <field name="name" start="start" end="end"/> ...
* </flags> */
xml_printf(&retval, tdesc, pos, size,
- "<flags id=\"%s\" size=\"%d\">\n",
+ "<flags id=\"%s\" size=\"%" PRIu32 "\">\n",
type->id, type->reg_type_flags->size);
struct reg_data_type_flags_field *field;
field = type->reg_type_flags->fields;
while (field != NULL) {
xml_printf(&retval, tdesc, pos, size,
- "<field name=\"%s\" start=\"%d\" end=\"%d\" type=\"%s\" />\n",
+ "<field name=\"%s\" start=\"%" PRIu32 "\" end=\"%" PRIu32 "\" type=\"%s\" />\n",
field->name, field->bitfield->start, field->bitfield->end,
gdb_get_reg_type_name(field->bitfield->type));
*feature_list = calloc(1, sizeof(char *));
for (int i = 0; i < reg_list_size; i++) {
- if (reg_list[i]->exist == false)
+ if (reg_list[i]->exist == false || reg_list[i]->hidden)
continue;
if (reg_list[i]->feature != NULL
int i;
for (i = 0; i < reg_list_size; i++) {
- if (reg_list[i]->exist == false)
+ if (reg_list[i]->exist == false || reg_list[i]->hidden)
continue;
if (strcmp(reg_list[i]->feature->name, features[current_feature]))
xml_printf(&retval, &tdesc, &pos, &size,
"<reg name=\"%s\"", reg_list[i]->name);
xml_printf(&retval, &tdesc, &pos, &size,
- " bitsize=\"%d\"", reg_list[i]->size);
+ " bitsize=\"%" PRIu32 "\"", reg_list[i]->size);
xml_printf(&retval, &tdesc, &pos, &size,
- " regnum=\"%d\"", reg_list[i]->number);
+ " regnum=\"%" PRIu32 "\"", reg_list[i]->number);
if (reg_list[i]->caller_save)
xml_printf(&retval, &tdesc, &pos, &size,
" save-restore=\"yes\"");
transfer_type = 'l';
*chunk = malloc(length + 2 + 3);
- /* Allocating extra 3 bytes prevents false positive valgrind report
+ /* Allocating extra 3 bytes prevents false positive valgrind report
* of strlen(chunk) word access:
* Invalid read of size 4
* Address 0x4479934 is 44 bytes inside a block of size 45 alloc'd */
if (gdb_connection->sync) {
gdb_connection->sync = false;
if (ct->state == TARGET_HALTED) {
- LOG_DEBUG("stepi ignored. GDB will now fetch the register state " \
+ LOG_DEBUG("stepi ignored. GDB will now fetch the register state "
"from the target.");
gdb_sig_halted(connection);
log_remove_callback(gdb_log_callback, connection);
target_call_event_callbacks(target,
TARGET_EVENT_GDB_FLASH_WRITE_START);
result = flash_write(target, gdb_connection->vflash_image,
- &written, 0);
+ &written, false);
target_call_event_callbacks(target,
TARGET_EVENT_GDB_FLASH_WRITE_END);
if (result != ERROR_OK) {
static int gdb_input_inner(struct connection *connection)
{
/* Do not allocate this on the stack */
- static char gdb_packet_buffer[GDB_BUFFER_SIZE + 1]; /* Extra byte for nul-termination */
+ static char gdb_packet_buffer[GDB_BUFFER_SIZE + 1]; /* Extra byte for null-termination */
struct target *target;
char const *packet = gdb_packet_buffer;
int packet_size;
int retval;
struct gdb_connection *gdb_con = connection->priv;
+ static bool warn_use_ext;
target = get_target_from_connection(connection);
break;
case '?':
gdb_last_signal_packet(connection, packet, packet_size);
+ /* '?' is sent after the eventual '!' */
+ if (!warn_use_ext && !gdb_con->extended_protocol) {
+ warn_use_ext = true;
+ LOG_WARNING("Prefer GDB command \"target extended-remote %s\" instead of \"target remote %s\"",
+ connection->service->port, connection->service->port);
+ }
break;
case 'c':
case 's':
"Waiting for target to halt.");
already_running = true;
} else if (target->state != TARGET_HALTED) {
- LOG_WARNING("The target is not in the halted nor running stated, " \
+ LOG_WARNING("The target is not in the halted nor running stated, "
"stepi/continue ignored.");
nostep = true;
} else if ((packet[0] == 's') && gdb_con->sync) {
* make only the single stepping have the sync feature...
*/
nostep = true;
- LOG_DEBUG("stepi ignored. GDB will now fetch the register state " \
+ LOG_DEBUG("stepi ignored. GDB will now fetch the register state "
"from the target.");
}
gdb_con->sync = false;
target->gdb_service = gdb_service;
ret = add_service("gdb",
- port, 1, &gdb_new_connection, &gdb_input,
+ port, target->gdb_max_connections, &gdb_new_connection, &gdb_input,
&gdb_connection_closed, gdb_service);
- /* initialialize all targets gdb service with the same pointer */
+ /* initialize all targets gdb service with the same pointer */
{
struct target_list *head;
struct target *curr;
{
.name = "gdb_port",
.handler = handle_gdb_port_command,
- .mode = COMMAND_ANY,
+ .mode = COMMAND_CONFIG,
.help = "Normally gdb listens to a TCP/IP port. Each subsequent GDB "
"server listens for the next port number after the "
"base port number specified. "