This is an automated email from Gerrit.

"Evgeniy Naydanov <[email protected]>" just uploaded a new patch 
set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9183

-- gerrit

commit f78898f9a9446a20c85b1ba953c0bd86b379ef55
Author: Greg Savin <[email protected]>
Date:   Mon Feb 7 09:28:31 2022 -0800

    Draft: fix missing thread ID in stop reply when smp-configured hart (but 
not hart 0) single-stepped
    
    See [1] for context.
    
    Link: https://github.com/riscv-collab/riscv-openocd/pull/675 [1]
    Change-Id: I9872062dfa0e3f1ca531d282d52a1b04c527546a
    Signed-off-by: Greg Savin <[email protected]>

diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c
index aa63595733..c866c11bb3 100644
--- a/src/rtos/rtos.c
+++ b/src/rtos/rtos.c
@@ -11,6 +11,7 @@
 
 #include "rtos.h"
 #include "target/target.h"
+#include "target/smp.h"
 #include "helper/log.h"
 #include "helper/binarybuffer.h"
 #include "helper/types.h"
@@ -715,10 +716,29 @@ int rtos_generic_stack_read(struct target *target,
        return ERROR_OK;
 }
 
-int rtos_update_threads(struct target *target)
+struct rtos *rtos_of_target(struct target *target)
 {
+       /* Primarily consider the rtos field of the target itself, secondarily 
consider
+        * rtos field SMP leader target, then consider rtos field of any other 
target in the SMP group.
+        * Otherwise NULL return means that no associated non-zero rtos field 
could be found. */
+
+       struct target_list *pos;
+
        if ((target->rtos) && (target->rtos->type))
-               target->rtos->type->update_threads(target->rtos);
+               return target->rtos;
+
+       foreach_smp_target(pos, target->smp_targets)
+               if ((pos->target->rtos) && (pos->target->rtos->type))
+                       return pos->target->rtos;
+
+       return NULL;
+}
+
+int rtos_update_threads(struct target *target)
+{
+       struct rtos *rtos = rtos_of_target(target);
+       if (rtos)
+               rtos->type->update_threads(rtos);
        return ERROR_OK;
 }
 
diff --git a/src/rtos/rtos.h b/src/rtos/rtos.h
index 2084739cfd..53b5297712 100644
--- a/src/rtos/rtos.h
+++ b/src/rtos/rtos.h
@@ -154,6 +154,7 @@ int rtos_write_buffer(struct target *target, target_addr_t 
address,
 bool rtos_needs_fake_step(struct target *target, int64_t thread_id);
 struct target *rtos_swbp_target(struct target *target, target_addr_t address,
                                uint32_t length, enum breakpoint_type type);
+struct rtos *rtos_of_target(struct target *target);
 
 // Keep in alphabetic order this list of rtos
 extern const struct rtos_type chibios_rtos;
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 80f256a1f3..6a63ef4833 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -831,9 +831,12 @@ static void gdb_signal_reply(struct target *target, struct 
connection *connectio
                sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), "W00");
        } else {
                struct target *ct;
-               if (target->rtos) {
-                       target->rtos->current_threadid = 
target->rtos->current_thread;
-                       target->rtos->gdb_target_for_threadid(connection, 
target->rtos->current_threadid, &ct);
+               struct rtos *rtos;
+
+               rtos = rtos_of_target(target);
+               if (rtos) {
+                       rtos->current_threadid = rtos->current_thread;
+                       rtos->gdb_target_for_threadid(connection, 
rtos->current_threadid, &ct);
                } else {
                        ct = target;
                }
@@ -871,9 +874,9 @@ static void gdb_signal_reply(struct target *target, struct 
connection *connectio
                }
 
                current_thread[0] = '\0';
-               if (target->rtos)
+               if (rtos)
                        snprintf(current_thread, sizeof(current_thread), 
"thread:%" PRIx64 ";",
-                                       target->rtos->current_thread);
+                                       rtos->current_thread);
 
                sig_reply_len = snprintf(sig_reply, sizeof(sig_reply), 
"T%2.2x%s%s",
                                signal_var, stop_reason, current_thread);

-- 

Reply via email to