gdbserver: code cleanup
Change-Id: Iab2966be8dd145f33f41902e2d55afe03d0f5856 Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk> Reviewed-on: http://openocd.zylin.com/857 Tested-by: jenkins Reviewed-by: Freddie Chopin <freddie.chopin@gmail.com>
This commit is contained in:
parent
f232512a21
commit
eaed9db414
|
@ -65,14 +65,14 @@ struct gdb_connection {
|
||||||
int closed;
|
int closed;
|
||||||
int busy;
|
int busy;
|
||||||
int noack_mode;
|
int noack_mode;
|
||||||
bool sync; /* set flag to true if you want the next stepi to return immediately.
|
/* set flag to true if you want the next stepi to return immediately.
|
||||||
allowing GDB to pick up a fresh set of register values from the target
|
* allowing GDB to pick up a fresh set of register values from the target
|
||||||
without modifying the target state. */
|
* without modifying the target state. */
|
||||||
|
bool sync;
|
||||||
/* We delay reporting memory write errors until next step/continue or memory
|
/* We delay reporting memory write errors until next step/continue or memory
|
||||||
* write. This improves performance of gdb load significantly as the GDB packet
|
* write. This improves performance of gdb load significantly as the GDB packet
|
||||||
* can be replied immediately and a new GDB packet will be ready without delay
|
* can be replied immediately and a new GDB packet will be ready without delay
|
||||||
* (ca. 10% or so...).
|
* (ca. 10% or so...). */
|
||||||
*/
|
|
||||||
bool mem_write_error;
|
bool mem_write_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -372,8 +372,7 @@ static int gdb_put_packet_inner(struct connection *connection,
|
||||||
char local_buffer[1024];
|
char local_buffer[1024];
|
||||||
local_buffer[0] = '$';
|
local_buffer[0] = '$';
|
||||||
if ((size_t)len + 4 <= sizeof(local_buffer)) {
|
if ((size_t)len + 4 <= sizeof(local_buffer)) {
|
||||||
/* performance gain on smaller packets by only a single call to gdb_write()
|
/* performance gain on smaller packets by only a single call to gdb_write() */
|
||||||
**/
|
|
||||||
memcpy(local_buffer + 1, buffer, len++);
|
memcpy(local_buffer + 1, buffer, len++);
|
||||||
local_buffer[len++] = '#';
|
local_buffer[len++] = '#';
|
||||||
local_buffer[len++] = DIGITS[(my_checksum >> 4) & 0xf];
|
local_buffer[len++] = DIGITS[(my_checksum >> 4) & 0xf];
|
||||||
|
@ -383,7 +382,7 @@ static int gdb_put_packet_inner(struct connection *connection,
|
||||||
return retval;
|
return retval;
|
||||||
} else {
|
} else {
|
||||||
/* larger packets are transmitted directly from caller supplied buffer
|
/* larger packets are transmitted directly from caller supplied buffer
|
||||||
by several calls to gdb_write() to avoid dynamic allocation */
|
* by several calls to gdb_write() to avoid dynamic allocation */
|
||||||
local_buffer[1] = '#';
|
local_buffer[1] = '#';
|
||||||
local_buffer[2] = DIGITS[(my_checksum >> 4) & 0xf];
|
local_buffer[2] = DIGITS[(my_checksum >> 4) & 0xf];
|
||||||
local_buffer[3] = DIGITS[my_checksum & 0xf];
|
local_buffer[3] = DIGITS[my_checksum & 0xf];
|
||||||
|
@ -427,8 +426,7 @@ static int gdb_put_packet_inner(struct connection *connection,
|
||||||
gdb_putback_char(connection, reply);
|
gdb_putback_char(connection, reply);
|
||||||
return ERROR_OK;
|
return ERROR_OK;
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(
|
LOG_ERROR("unknown character(1) 0x%2.2x in reply, dropping connection", reply);
|
||||||
"unknown character(1) 0x%2.2x in reply, dropping connection", reply);
|
|
||||||
gdb_con->closed = 1;
|
gdb_con->closed = 1;
|
||||||
return ERROR_SERVER_REMOTE_CLOSED;
|
return ERROR_SERVER_REMOTE_CLOSED;
|
||||||
}
|
}
|
||||||
|
@ -500,8 +498,7 @@ static inline int fetch_packet(struct connection *connection,
|
||||||
i++;
|
i++;
|
||||||
if (character == '#') {
|
if (character == '#') {
|
||||||
/* Danger! character can be '#' when esc is
|
/* Danger! character can be '#' when esc is
|
||||||
* used so we need an explicit boolean for done here.
|
* used so we need an explicit boolean for done here. */
|
||||||
*/
|
|
||||||
done = 1;
|
done = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -620,8 +617,7 @@ static int gdb_get_packet_inner(struct connection *connection,
|
||||||
|
|
||||||
int checksum_ok = 0;
|
int checksum_ok = 0;
|
||||||
/* explicit code expansion here to get faster inlined code in -O3 by not
|
/* explicit code expansion here to get faster inlined code in -O3 by not
|
||||||
* calculating checksum
|
* calculating checksum */
|
||||||
*/
|
|
||||||
if (gdb_con->noack_mode) {
|
if (gdb_con->noack_mode) {
|
||||||
retval = fetch_packet(connection, &checksum_ok, 1, len, buffer);
|
retval = fetch_packet(connection, &checksum_ok, 1, len, buffer);
|
||||||
if (retval != ERROR_OK)
|
if (retval != ERROR_OK)
|
||||||
|
@ -807,8 +803,8 @@ static int gdb_new_connection(struct connection *connection)
|
||||||
struct flash_bank *p;
|
struct flash_bank *p;
|
||||||
retval = get_flash_bank_by_num(i, &p);
|
retval = get_flash_bank_by_num(i, &p);
|
||||||
if (retval != ERROR_OK) {
|
if (retval != ERROR_OK) {
|
||||||
LOG_ERROR(
|
LOG_ERROR("Connect failed. Consider setting up a gdb-attach event for the target " \
|
||||||
"Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'.");
|
"to prepare target for GDB connect, or use 'gdb_memory_map disable'.");
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1031,8 +1027,7 @@ static int gdb_set_registers_packet(struct connection *connection,
|
||||||
packet_size--;
|
packet_size--;
|
||||||
|
|
||||||
if (packet_size % 2) {
|
if (packet_size % 2) {
|
||||||
LOG_WARNING(
|
LOG_WARNING("GDB set_registers packet with uneven characters received, dropping connection");
|
||||||
"GDB set_registers packet with uneven characters received, dropping connection");
|
|
||||||
return ERROR_SERVER_REMOTE_CLOSED;
|
return ERROR_SERVER_REMOTE_CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1367,10 +1362,8 @@ static int gdb_step_continue_packet(struct connection *connection,
|
||||||
|
|
||||||
if (packet[0] == 'c') {
|
if (packet[0] == 'c') {
|
||||||
LOG_DEBUG("continue");
|
LOG_DEBUG("continue");
|
||||||
retval = target_resume(target, current, address, 0, 0); /* resume at current
|
/* resume at current address, don't handle breakpoints, not debugging */
|
||||||
*address, don't handle
|
retval = target_resume(target, current, address, 0, 0);
|
||||||
*breakpoints, not debugging
|
|
||||||
**/
|
|
||||||
} else if (packet[0] == 's') {
|
} else if (packet[0] == 's') {
|
||||||
LOG_DEBUG("step");
|
LOG_DEBUG("step");
|
||||||
/* step at current or address, don't handle breakpoints */
|
/* step at current or address, don't handle breakpoints */
|
||||||
|
@ -1739,8 +1732,7 @@ static int gdb_query_packet(struct connection *connection,
|
||||||
addr = strtoul(packet, &separator, 16);
|
addr = strtoul(packet, &separator, 16);
|
||||||
|
|
||||||
if (*separator != ',') {
|
if (*separator != ',') {
|
||||||
LOG_ERROR(
|
LOG_ERROR("incomplete read memory packet received, dropping connection");
|
||||||
"incomplete read memory packet received, dropping connection");
|
|
||||||
return ERROR_SERVER_REMOTE_CLOSED;
|
return ERROR_SERVER_REMOTE_CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1946,8 +1938,7 @@ static int gdb_v_packet(struct connection *connection,
|
||||||
* always issues a vFlashErase first. */
|
* always issues a vFlashErase first. */
|
||||||
target_call_event_callbacks(gdb_service->target,
|
target_call_event_callbacks(gdb_service->target,
|
||||||
TARGET_EVENT_GDB_FLASH_WRITE_START);
|
TARGET_EVENT_GDB_FLASH_WRITE_START);
|
||||||
result =
|
result = flash_write(gdb_service->target, gdb_connection->vflash_image, &written, 0);
|
||||||
flash_write(gdb_service->target, gdb_connection->vflash_image, &written, 0);
|
|
||||||
target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_FLASH_WRITE_END);
|
target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_FLASH_WRITE_END);
|
||||||
if (result != ERROR_OK) {
|
if (result != ERROR_OK) {
|
||||||
if (result == ERROR_FLASH_DST_OUT_OF_BANK)
|
if (result == ERROR_FLASH_DST_OUT_OF_BANK)
|
||||||
|
@ -1974,8 +1965,7 @@ static int gdb_detach(struct connection *connection)
|
||||||
{
|
{
|
||||||
struct gdb_service *gdb_service = connection->service->priv;
|
struct gdb_service *gdb_service = connection->service->priv;
|
||||||
|
|
||||||
target_call_event_callbacks(gdb_service->target,
|
target_call_event_callbacks(gdb_service->target, TARGET_EVENT_GDB_DETACH);
|
||||||
TARGET_EVENT_GDB_DETACH);
|
|
||||||
|
|
||||||
return gdb_put_packet(connection, "OK", 2);
|
return gdb_put_packet(connection, "OK", 2);
|
||||||
}
|
}
|
||||||
|
@ -1999,7 +1989,6 @@ static void gdb_sig_halted(struct connection *connection)
|
||||||
char sig_reply[4];
|
char sig_reply[4];
|
||||||
snprintf(sig_reply, 4, "T%2.2x", 2);
|
snprintf(sig_reply, 4, "T%2.2x", 2);
|
||||||
gdb_put_packet(connection, sig_reply, 3);
|
gdb_put_packet(connection, sig_reply, 3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gdb_input_inner(struct connection *connection)
|
static int gdb_input_inner(struct connection *connection)
|
||||||
|
@ -2054,8 +2043,8 @@ static int gdb_input_inner(struct connection *connection)
|
||||||
case 'T': /* Is thread alive? */
|
case 'T': /* Is thread alive? */
|
||||||
gdb_thread_packet(connection, packet, packet_size);
|
gdb_thread_packet(connection, packet, packet_size);
|
||||||
break;
|
break;
|
||||||
case 'H': /* Set current thread ( 'c' for step and continue, 'g' for
|
case 'H': /* Set current thread ( 'c' for step and continue,
|
||||||
* all other operations ) */
|
* 'g' for all other operations ) */
|
||||||
gdb_thread_packet(connection, packet, packet_size);
|
gdb_thread_packet(connection, packet, packet_size);
|
||||||
break;
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
|
@ -2151,7 +2140,7 @@ static int gdb_input_inner(struct connection *connection)
|
||||||
if (retval != ERROR_OK) {
|
if (retval != ERROR_OK) {
|
||||||
/* we'll never receive a halted
|
/* we'll never receive a halted
|
||||||
* condition... issue a false one..
|
* condition... issue a false one..
|
||||||
**/
|
*/
|
||||||
gdb_frontend_halted(target, connection);
|
gdb_frontend_halted(target, connection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2184,8 +2173,7 @@ static int gdb_input_inner(struct connection *connection)
|
||||||
/* handle extended restart packet */
|
/* handle extended restart packet */
|
||||||
breakpoint_clear_target(gdb_service->target);
|
breakpoint_clear_target(gdb_service->target);
|
||||||
watchpoint_clear_target(gdb_service->target);
|
watchpoint_clear_target(gdb_service->target);
|
||||||
command_run_linef(connection->cmd_ctx,
|
command_run_linef(connection->cmd_ctx, "ocd_gdb_restart %s",
|
||||||
"ocd_gdb_restart %s",
|
|
||||||
target_name(target));
|
target_name(target));
|
||||||
/* info rtos parts */
|
/* info rtos parts */
|
||||||
gdb_thread_packet(connection, packet, packet_size);
|
gdb_thread_packet(connection, packet, packet_size);
|
||||||
|
@ -2224,8 +2212,7 @@ static int gdb_input_inner(struct connection *connection)
|
||||||
target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
|
target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
|
||||||
gdb_con->ctrl_c = 0;
|
gdb_con->ctrl_c = 0;
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(
|
LOG_INFO("The target is not running when halt was requested, stopping GDB.");
|
||||||
"The target is not running when halt was requested, stopping GDB.");
|
|
||||||
target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
|
target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue