gdb: use strncmp rather than strstr

All the packets received will be at start of the packet buffer, so use
more efficient strncmp.

Change-Id: Ib9c45d8f53425367006b1f880c1bde27f03a6cf9
Signed-off-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-on: http://openocd.zylin.com/932
Tested-by: jenkins
Reviewed-by: Matthias Blaicher <matthias@blaicher.com>
Reviewed-by: Peter Stuge <peter@stuge.se>
__archive__
Spencer Oliver 2012-10-26 12:47:06 +01:00 committed by Peter Stuge
parent 6f65045b37
commit 538a86c339
4 changed files with 22 additions and 22 deletions

View File

@ -1396,7 +1396,7 @@ static int linux_thread_packet(struct connection *connection, char *packet,
break;
case 'q':
if ((strstr(packet, "qSymbol"))) {
if (strncmp(packet, "qSymbol", 7) == 0) {
if (rtos_qsymbol(connection, packet, packet_size) == 1) {
linux_compute_virt2phys(target,
target->rtos->
@ -1405,7 +1405,7 @@ static int linux_thread_packet(struct connection *connection, char *packet,
}
break;
} else if (strstr(packet, "qfThreadInfo")) {
} else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
if (linux_os->thread_list == NULL) {
retval = linux_gdb_thread_packet(target,
connection,
@ -1419,10 +1419,10 @@ static int linux_thread_packet(struct connection *connection, char *packet,
packet_size);
break;
}
} else if (strstr(packet, "qsThreadInfo")) {
} else if (strncmp(packet, "qsThreadInfo", 12) == 0) {
gdb_put_packet(connection, "l", 1);
break;
} else if (strstr(packet, "qThreadExtraInfo,")) {
} else if (strncmp(packet, "qThreadExtraInfo,", 17) == 0) {
linux_thread_extra_info(target, connection, packet,
packet_size);
break;

View File

@ -244,7 +244,7 @@ int rtos_thread_packet(struct connection *connection, char *packet, int packet_s
{
struct target *target = get_target_from_connection(connection);
if (strstr(packet, "qThreadExtraInfo,")) {
if (strncmp(packet, "qThreadExtraInfo,", 17) == 0) {
if ((target->rtos != NULL) && (target->rtos->thread_details != NULL) &&
(target->rtos->thread_count != 0)) {
threadid_t threadid = 0;
@ -306,14 +306,14 @@ int rtos_thread_packet(struct connection *connection, char *packet, int packet_s
}
gdb_put_packet(connection, "", 0);
return ERROR_OK;
} else if (strstr(packet, "qSymbol")) {
} else if (strncmp(packet, "qSymbol", 7) == 0) {
if (rtos_qsymbol(connection, packet, packet_size) == 1) {
target->rtos_auto_detect = false;
target->rtos->type->create(target);
target->rtos->type->update_threads(target->rtos);
}
return ERROR_OK;
} else if (strstr(packet, "qfThreadInfo")) {
} else if (strncmp(packet, "qfThreadInfo", 12) == 0) {
int i;
if ((target->rtos != NULL) && (target->rtos->thread_count != 0)) {
@ -332,17 +332,17 @@ int rtos_thread_packet(struct connection *connection, char *packet, int packet_s
gdb_put_packet(connection, "", 0);
return ERROR_OK;
} else if (strstr(packet, "qsThreadInfo")) {
} else if (strncmp(packet, "qsThreadInfo", 12) == 0) {
gdb_put_packet(connection, "l", 1);
return ERROR_OK;
} else if (strstr(packet, "qAttached")) {
} else if (strncmp(packet, "qAttached", 9) == 0) {
gdb_put_packet(connection, "1", 1);
return ERROR_OK;
} else if (strstr(packet, "qOffsets")) {
} else if (strncmp(packet, "qOffsets", 8) == 0) {
char offsets[] = "Text=0;Data=0;Bss=0";
gdb_put_packet(connection, offsets, sizeof(offsets)-1);
return ERROR_OK;
} else if (strstr(packet, "qC")) {
} else if (strncmp(packet, "qC", 2) == 0) {
if (target->rtos != NULL) {
char buffer[19];
int size;

View File

@ -1705,7 +1705,7 @@ static int gdb_query_packet(struct connection *connection,
struct gdb_connection *gdb_connection = connection->priv;
struct target *target = get_target_from_connection(connection);
if (strstr(packet, "qRcmd,")) {
if (strncmp(packet, "qRcmd,", 6) == 0) {
if (packet_size > 6) {
char *cmd;
int i;
@ -1731,7 +1731,7 @@ static int gdb_query_packet(struct connection *connection,
}
gdb_put_packet(connection, "OK", 2);
return ERROR_OK;
} else if (strstr(packet, "qCRC:")) {
} else if (strncmp(packet, "qCRC:", 5) == 0) {
if (packet_size > 5) {
int retval;
char gdb_reply[10];
@ -1765,7 +1765,7 @@ static int gdb_query_packet(struct connection *connection,
return ERROR_OK;
}
} else if (strstr(packet, "qSupported")) {
} else if (strncmp(packet, "qSupported", 10) == 0) {
/* we currently support packet size and qXfer:memory-map:read (if enabled)
* disable qXfer:features:read for the moment */
int retval = ERROR_OK;
@ -1790,10 +1790,10 @@ static int gdb_query_packet(struct connection *connection,
free(buffer);
return ERROR_OK;
} else if (strstr(packet, "qXfer:memory-map:read::")
} else if ((strncmp(packet, "qXfer:memory-map:read::", 23) == 0)
&& (flash_get_bank_count() > 0))
return gdb_memory_map(connection, packet, packet_size);
else if (strstr(packet, "qXfer:features:read:")) {
else if (strncmp(packet, "qXfer:features:read:", 20) == 0) {
char *xml = NULL;
int size = 0;
int pos = 0;
@ -1831,7 +1831,7 @@ static int gdb_query_packet(struct connection *connection,
free(xml);
return ERROR_OK;
} else if (strstr(packet, "QStartNoAckMode")) {
} else if (strncmp(packet, "QStartNoAckMode", 15) == 0) {
gdb_connection->noack_mode = 1;
gdb_put_packet(connection, "OK", 2);
return ERROR_OK;
@ -1855,7 +1855,7 @@ static int gdb_v_packet(struct connection *connection,
return ERROR_OK;
}
if (strstr(packet, "vFlashErase:")) {
if (strncmp(packet, "vFlashErase:", 12) == 0) {
unsigned long addr;
unsigned long length;
@ -1911,7 +1911,7 @@ static int gdb_v_packet(struct connection *connection,
return ERROR_OK;
}
if (strstr(packet, "vFlashWrite:")) {
if (strncmp(packet, "vFlashWrite:", 12) == 0) {
int retval;
unsigned long addr;
unsigned long length;
@ -1945,7 +1945,7 @@ static int gdb_v_packet(struct connection *connection,
return ERROR_OK;
}
if (!strcmp(packet, "vFlashDone")) {
if (strncmp(packet, "vFlashDone", 10) == 0) {
uint32_t written;
/* process the flashing buffer. No need to erase as GDB

View File

@ -65,7 +65,7 @@ int gdb_read_smp_packet(struct connection *connection,
char *hex_buffer;
int retval = ERROR_OK;
if (target->smp) {
if (strstr(packet, "jc")) {
if (strncmp(packet, "jc", 2) == 0) {
hex_buffer = malloc(len * 2 + 1);
buffer = (uint8_t *)&target->gdb_service->core[0];
uint32_t i;
@ -95,7 +95,7 @@ int gdb_write_smp_packet(struct connection *connection,
/* skip command character */
if (target->smp) {
if (strstr(packet, "Jc")) {
if (strncmp(packet, "Jc", 2) == 0) {
packet += 2;
coreid = strtoul(packet, &separator, 16);
target->gdb_service->core[1] = coreid;