+45
-29
@@ -733,17 +733,26 @@ static void gdb_signal_reply(struct target *target, struct connection *connectio
|
||||
if (target->debug_reason == DBG_REASON_EXIT) {
|
||||
sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "W00");
|
||||
} else {
|
||||
struct target *ct;
|
||||
if (target->rtos != NULL) {
|
||||
target->rtos->current_threadid = target->rtos->current_thread;
|
||||
LOG_DEBUG("current_threadid=%" PRId64, target->rtos->current_threadid);
|
||||
target->rtos->gdb_target_for_threadid(connection, target->rtos->current_threadid, &ct);
|
||||
} else {
|
||||
ct = target;
|
||||
}
|
||||
|
||||
if (gdb_connection->ctrl_c) {
|
||||
signal_var = 0x2;
|
||||
} else
|
||||
signal_var = gdb_last_signal(target);
|
||||
signal_var = gdb_last_signal(ct);
|
||||
|
||||
stop_reason[0] = '\0';
|
||||
if (target->debug_reason == DBG_REASON_WATCHPOINT) {
|
||||
if (ct->debug_reason == DBG_REASON_WATCHPOINT) {
|
||||
enum watchpoint_rw hit_wp_type;
|
||||
target_addr_t hit_wp_address;
|
||||
|
||||
if (watchpoint_hit(target, &hit_wp_type, &hit_wp_address) == ERROR_OK) {
|
||||
if (watchpoint_hit(ct, &hit_wp_type, &hit_wp_address) == ERROR_OK) {
|
||||
|
||||
switch (hit_wp_type) {
|
||||
case WPT_WRITE:
|
||||
@@ -765,15 +774,9 @@ static void gdb_signal_reply(struct target *target, struct connection *connectio
|
||||
}
|
||||
|
||||
current_thread[0] = '\0';
|
||||
if (target->rtos != NULL) {
|
||||
struct target *ct;
|
||||
if (target->rtos != NULL)
|
||||
snprintf(current_thread, sizeof(current_thread), "thread:%" PRIx64 ";",
|
||||
target->rtos->current_thread);
|
||||
target->rtos->current_threadid = target->rtos->current_thread;
|
||||
target->rtos->gdb_target_for_threadid(connection, target->rtos->current_threadid, &ct);
|
||||
if (!gdb_connection->ctrl_c)
|
||||
signal_var = gdb_last_signal(ct);
|
||||
}
|
||||
|
||||
sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "T%2.2x%s%s",
|
||||
signal_var, stop_reason, current_thread);
|
||||
@@ -1340,37 +1343,49 @@ static int gdb_set_register_packet(struct connection *connection,
|
||||
{
|
||||
struct target *target = get_target_from_connection(connection);
|
||||
char *separator;
|
||||
uint8_t *bin_buf;
|
||||
int reg_num = strtoul(packet + 1, &separator, 16);
|
||||
struct reg **reg_list;
|
||||
int reg_list_size;
|
||||
int retval;
|
||||
|
||||
#ifdef _DEBUG_GDB_IO_
|
||||
LOG_DEBUG("-");
|
||||
|
||||
retval = target_get_gdb_reg_list(target, ®_list, ®_list_size,
|
||||
REG_CLASS_ALL);
|
||||
if (retval != ERROR_OK)
|
||||
return gdb_error(connection, retval);
|
||||
|
||||
if (reg_list_size <= reg_num) {
|
||||
LOG_ERROR("gdb requested a non-existing register");
|
||||
return ERROR_SERVER_REMOTE_CLOSED;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (*separator != '=') {
|
||||
LOG_ERROR("GDB 'set register packet', but no '=' following the register number");
|
||||
return ERROR_SERVER_REMOTE_CLOSED;
|
||||
}
|
||||
size_t chars = strlen(separator + 1);
|
||||
uint8_t *bin_buf = malloc(chars / 2);
|
||||
gdb_target_to_reg(target, separator + 1, chars, bin_buf);
|
||||
|
||||
/* convert from GDB-string (target-endian) to hex-string (big-endian) */
|
||||
bin_buf = malloc(DIV_ROUND_UP(reg_list[reg_num]->size, 8));
|
||||
int chars = (DIV_ROUND_UP(reg_list[reg_num]->size, 8) * 2);
|
||||
|
||||
if ((unsigned int)chars != strlen(separator + 1)) {
|
||||
LOG_ERROR("gdb sent %zu bits for a %d-bit register (%s)",
|
||||
strlen(separator + 1) * 4, chars * 4, reg_list[reg_num]->name);
|
||||
if ((target->rtos != NULL) &&
|
||||
(ERROR_OK == rtos_set_reg(connection, reg_num, bin_buf))) {
|
||||
free(bin_buf);
|
||||
gdb_put_packet(connection, "OK", 2);
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
retval = target_get_gdb_reg_list(target, ®_list, ®_list_size,
|
||||
REG_CLASS_ALL);
|
||||
if (retval != ERROR_OK) {
|
||||
free(bin_buf);
|
||||
return gdb_error(connection, retval);
|
||||
}
|
||||
|
||||
if (reg_list_size <= reg_num) {
|
||||
LOG_ERROR("gdb requested a non-existing register");
|
||||
free(bin_buf);
|
||||
free(reg_list);
|
||||
return ERROR_SERVER_REMOTE_CLOSED;
|
||||
}
|
||||
|
||||
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);
|
||||
free(bin_buf);
|
||||
free(reg_list);
|
||||
return ERROR_SERVER_REMOTE_CLOSED;
|
||||
}
|
||||
|
||||
@@ -1640,7 +1655,7 @@ static int gdb_breakpoint_watchpoint_packet(struct connection *connection,
|
||||
char *separator;
|
||||
int retval;
|
||||
|
||||
LOG_DEBUG("-");
|
||||
LOG_DEBUG("[%d]", target->coreid);
|
||||
|
||||
type = strtoul(packet + 1, &separator, 16);
|
||||
|
||||
@@ -2398,6 +2413,7 @@ static int gdb_target_description_supported(struct target *target, int *supporte
|
||||
®_list_size, REG_CLASS_ALL);
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_ERROR("get register list failed");
|
||||
reg_list = NULL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user