Skip to content
Snippets Groups Projects
Commit 652a5b18 authored by oharboe's avatar oharboe
Browse files

Pavel Chromy: performance tweak of gdb_put_packet_inner() removing malloc and...

Pavel Chromy: performance tweak of gdb_put_packet_inner() removing malloc and avoiding memcpy of larger blocks of data,

git-svn-id: svn://svn.berlios.de/openocd/trunk@453 b42882b7-edfa-0310-969c-e2dbd0fdcd60
parent 209d7c0e
No related branches found
No related tags found
No related merge requests found
...@@ -314,33 +314,29 @@ int gdb_put_packet_inner(connection_t *connection, char *buffer, int len) ...@@ -314,33 +314,29 @@ int gdb_put_packet_inner(connection_t *connection, char *buffer, int len)
free(debug_buffer); free(debug_buffer);
#endif #endif
void *allocated = NULL; char local_buffer[1024];
char stackAlloc[1024]; local_buffer[0] = '$';
char *t = stackAlloc; if (len+4 <= sizeof(local_buffer))
int totalLen = 1 + len + 1 + 2;
if (totalLen > sizeof(stackAlloc))
{ {
allocated = malloc(totalLen); /* performance gain on smaller packets by only a single call to gdb_write() */
t = allocated; memcpy(local_buffer+1, buffer, len++);
if (allocated == NULL) local_buffer[len++] = '#';
{ local_buffer[len++] = DIGITS[(my_checksum >> 4) & 0xf];
ERROR("Ran out of memory trying to reply packet %d\n", totalLen); local_buffer[len++] = DIGITS[my_checksum & 0xf];
exit(-1); gdb_write(connection, local_buffer, len);
}
} }
t[0] = '$'; else
memcpy(t + 1, buffer, len);
t[1 + len] = '#';
t[1 + len + 1] = DIGITS[(my_checksum >> 4) & 0xf];
t[1 + len + 2] = DIGITS[my_checksum & 0xf];
gdb_write(connection, t, totalLen);
if (allocated)
{ {
free(allocated); /* larger packets are transmitted directly from caller supplied buffer
by several calls to gdb_write() to avoid dynamic allocation */
local_buffer[1] = '#';
local_buffer[2] = DIGITS[(my_checksum >> 4) & 0xf];
local_buffer[3] = DIGITS[my_checksum & 0xf];
gdb_write(connection, local_buffer, 1);
gdb_write(connection, buffer, len);
gdb_write(connection, local_buffer+1, 3);
} }
if ((retval = gdb_get_char(connection, &reply)) != ERROR_OK) if ((retval = gdb_get_char(connection, &reply)) != ERROR_OK)
return retval; return retval;
...@@ -688,7 +684,7 @@ int gdb_new_connection(connection_t *connection) ...@@ -688,7 +684,7 @@ int gdb_new_connection(connection_t *connection)
* GDB connection will fail if e.g. register read packets fail, * GDB connection will fail if e.g. register read packets fail,
* otherwise resetting/halting the target could have been left to GDB init * otherwise resetting/halting the target could have been left to GDB init
* scripts * scripts
*/ */
if (((retval = gdb_service->target->type->halt(gdb_service->target)) != ERROR_OK) && if (((retval = gdb_service->target->type->halt(gdb_service->target)) != ERROR_OK) &&
(retval != ERROR_TARGET_ALREADY_HALTED)) (retval != ERROR_TARGET_ALREADY_HALTED))
{ {
...@@ -1387,18 +1383,18 @@ void xml_printf(int *retval, char **xml, int *pos, int *size, const char *fmt, . ...@@ -1387,18 +1383,18 @@ void xml_printf(int *retval, char **xml, int *pos, int *size, const char *fmt, .
} }
} }
va_list ap; va_list ap;
int ret; int ret;
va_start(ap, fmt); va_start(ap, fmt);
ret = vsnprintf(*xml + *pos, *size - *pos, fmt, ap); ret = vsnprintf(*xml + *pos, *size - *pos, fmt, ap);
va_end(ap); va_end(ap);
if ((ret > 0) && ((ret + 1) < *size - *pos)) if ((ret > 0) && ((ret + 1) < *size - *pos))
{ {
*pos += ret; *pos += ret;
return; return;
} }
/* there was just enough or not enough space, allocate more. */ /* there was just enough or not enough space, allocate more. */
first = 0; first = 0;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment