This is an automated email from Gerrit. Richard Braun (rbr...@sceen.net) just uploaded a new patch set to Gerrit, which you can find at http://openocd.zylin.com/4347
-- gerrit commit b6764ceb0bafe31d24e0232c7f6c7fa826fc8643 Author: Richard Braun <richard.br...@sbg-systems.com> Date: Mon Jan 8 16:43:15 2018 +0100 rtos: fix thread ID handling When the RTOS uses addresses as thread identifiers, these values are usually high, above 2G. For some reason, GDB encodes them using a dash followed by the two's complement of the actual value, so that e.g. 0xc1f1a204 is encoded as -3e0e5dfc. Because of the negative symbol, sign extension occurs on the 64-bits output thread ID variable, preventing any chance to match the thread ID in the future. This change introduces a small wrapper that first scans the thread ID into an unsigned 32-bits integer, before assigning this value to a 64-bits signed thread ID. Change-Id: Ibecc4549a382c6fba97fe41ebfd5f8e12bf1b83e Signed-off-by: Richard Braun <richard.br...@sbg-systems.com> diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 84ee498..9935997 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -101,6 +101,19 @@ static int os_alloc_create(struct target *target, struct rtos_type *ostype) return ret; } +static int read_threadid(const char *packet, const char *format_prefix, threadid_t *threadid) +{ + char format[64]; + uint32_t tmp; + int ret; + + snprintf(format, sizeof(format), "%s" SCNx32, format_prefix); + ret = sscanf(packet, format, &tmp); + *threadid = tmp; + + return ret; +} + int rtos_create(Jim_GetOptInfo *goi, struct target *target) { int x; @@ -284,7 +297,7 @@ int rtos_thread_packet(struct connection *connection, char const *packet, int pa (target->rtos->thread_count != 0)) { threadid_t threadid = 0; int found = -1; - sscanf(packet, "qThreadExtraInfo,%" SCNx64, &threadid); + read_threadid(packet, "qThreadExtraInfo,%", &threadid); if ((target->rtos != NULL) && (target->rtos->thread_details != NULL)) { int thread_num; @@ -387,7 +400,7 @@ int rtos_thread_packet(struct connection *connection, char const *packet, int pa } else if (packet[0] == 'T') { /* Is thread alive? */ threadid_t threadid; int found = -1; - sscanf(packet, "T%" SCNx64, &threadid); + read_threadid(packet, "T%", &threadid); if ((target->rtos != NULL) && (target->rtos->thread_details != NULL)) { int thread_num; for (thread_num = 0; thread_num < target->rtos->thread_count; thread_num++) { @@ -406,7 +419,7 @@ int rtos_thread_packet(struct connection *connection, char const *packet, int pa * all other operations ) */ if ((packet[1] == 'g') && (target->rtos != NULL)) { threadid_t threadid; - sscanf(packet, "Hg%16" SCNx64, &threadid); + read_threadid(packet, "Hg%16", &threadid); LOG_DEBUG("RTOS: GDB requested to set current thread to 0x%" PRIx64, threadid); /* threadid of 0 indicates target should choose */ if (threadid == 0) -- ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ OpenOCD-devel mailing list OpenOCD-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openocd-devel