From 63928161c6725d25e2bf486a2db254eb44333af1 Mon Sep 17 00:00:00 2001 From: anjiahao Date: Thu, 3 Jul 2025 16:34:13 +0800 Subject: [PATCH] tools/pynuttx: read the mutex holder from sem_t The holder of a mutex lives in the low 31 bits of sem.val.mholder, with bit 31 as the blocking flag; mutex_t no longer carries a holder field of its own. Read it through a sem_t with the blocking bit masked in thread.py, both in the thread listing and in ps, and add the helper to utils. Signed-off-by: anjiahao --- tools/pynuttx/nxgdb/thread.py | 5 ++--- tools/pynuttx/nxgdb/utils.py | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/pynuttx/nxgdb/thread.py b/tools/pynuttx/nxgdb/thread.py index d5e6be469db4f..04326529989b4 100644 --- a/tools/pynuttx/nxgdb/thread.py +++ b/tools/pynuttx/nxgdb/thread.py @@ -251,8 +251,7 @@ def invoke(self, args, from_tty): if tcb["task_state"] == gdb.parse_and_eval("TSTATE_WAIT_SEM"): mutex = tcb["waitobj"].cast(utils.lookup_type("sem_t").pointer()) if mutex["flags"] & SEM_TYPE_MUTEX: - mutex = tcb["waitobj"].cast(utils.lookup_type("mutex_t").pointer()) - statename = f"Waiting,Mutex:{mutex['holder']}" + statename = f"Waiting,Mutex:{utils.mutex_get_holder(mutex)}" try: """Maybe tcb not have name member, or name is not utf-8""" @@ -488,7 +487,7 @@ def cast2ptr(x, t): ) waiter = ( - str(int(cast2ptr(tcb["waitobj"], "mutex_t")["holder"])) + str(utils.mutex_get_holder(cast2ptr(tcb["waitobj"], "sem_t"))) if tcb["waitobj"] and cast2ptr(tcb["waitobj"], "sem_t")["flags"] & get_macro("SEM_TYPE_MUTEX") else "" diff --git a/tools/pynuttx/nxgdb/utils.py b/tools/pynuttx/nxgdb/utils.py index 3aa8e6416cf92..71548de04e637 100644 --- a/tools/pynuttx/nxgdb/utils.py +++ b/tools/pynuttx/nxgdb/utils.py @@ -811,6 +811,12 @@ def get_task_name(tcb): return "" +# sem +def mutex_get_holder(sem): + NXSEM_MBLOCKING_BIT = 1 << 31 + return sem["val"]["mholder"] & ~NXSEM_MBLOCKING_BIT + + def switch_inferior(inferior): state = suppress_cli_notifications(True)