From: Richard Braun <[email protected]>
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.
---
src/rtos/rtos.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c
index 84ee498b..99359978 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)
--
2.11.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
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel