gdb: use strncmp rather than strstr
authorSpencer Oliver <spen@spen-soft.co.uk>
Fri, 26 Oct 2012 11:47:06 +0000 (12:47 +0100)
committerPeter Stuge <peter@stuge.se>
Sun, 28 Oct 2012 01:40:21 +0000 (01:40 +0000)
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>
src/rtos/linux.c
src/rtos/rtos.c
src/server/gdb_server.c
src/target/smp.c

index 3f1b214bc54f81e3bbc28e3dc70f622b96fb47d0..9c955972a8469b056e168d0c0883e947739a725f 100644 (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;
index 00025abeef83c0222856b2666cd260aef538d774..349f84df0a7c959f2881331af3f7695517a031c1 100644 (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;
index 0a8babe2049673b625a869151938c23254158bf9..ee7683a66db32590e68641bb8d69210850391056 100644 (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
index 9cd4b013d3ea0a26b1cd3db5257146a921e5d94a..ccbc2be434916998ac5692df499a74b132ba4af1 100644 (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;

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)