/* 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;
- int ctrl_c;
+ bool ctrl_c;
enum target_state frontend_state;
struct image *vflash_image;
bool closed;
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);
log_remove_callback(gdb_log_callback, connection);
LOG_WARNING("negative reply, retrying");
} else if (reply == 0x3) {
- gdb_con->ctrl_c = 1;
+ gdb_con->ctrl_c = true;
retval = gdb_get_char(connection, &reply);
if (retval != ERROR_OK)
return retval;
LOG_WARNING("negative acknowledgment, but no packet pending");
break;
case 0x3:
- gdb_con->ctrl_c = 1;
+ gdb_con->ctrl_c = true;
*len = 0;
return ERROR_OK;
default:
sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "T%2.2x%s%s",
signal_var, stop_reason, current_thread);
- gdb_connection->ctrl_c = 0;
+ gdb_connection->ctrl_c = false;
}
gdb_put_packet(connection, sig_reply, sig_reply_len);
/* initialize gdb connection information */
gdb_connection->buf_p = gdb_connection->buffer;
gdb_connection->buf_cnt = 0;
- gdb_connection->ctrl_c = 0;
+ gdb_connection->ctrl_c = false;
gdb_connection->frontend_state = TARGET_HALTED;
gdb_connection->vflash_image = NULL;
gdb_connection->closed = false;
* 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);
}
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));
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\"");
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;
retval = target_poll(t);
if (retval != ERROR_OK)
target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
- gdb_con->ctrl_c = 0;
+ gdb_con->ctrl_c = false;
} else {
LOG_INFO("The target is not running when halt was requested, stopping GDB.");
target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
if (NULL == gdb_service)
return -ENOMEM;
- LOG_DEBUG("starting gdb server for %s on %s", target_name(target), port);
+ LOG_INFO("starting gdb server for %s on %s", target_name(target), port);
gdb_service->target = target;
gdb_service->core[0] = -1;
ret = add_service("gdb",
port, 1, &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. "