This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit db1e97405a81aecf3eb0db6548fd485c44a01241
Author: anjiahao <anjia...@xiaomi.com>
AuthorDate: Mon Aug 26 20:29:03 2024 +0800

    thread.py: fix bug that ARM-A TCB info register[2]
    
    Signed-off-by: anjiahao <anjia...@xiaomi.com>
---
 tools/gdb/thread.py | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/tools/gdb/thread.py b/tools/gdb/thread.py
index a1e90cdea9..01768d4d55 100644
--- a/tools/gdb/thread.py
+++ b/tools/gdb/thread.py
@@ -31,10 +31,13 @@ UINT16_MAX = 0xFFFF
 SEM_TYPE_MUTEX = 4
 
 saved_regs = None
+regoffset = None
 
 
 def save_regs():
     global saved_regs
+    global regoffset
+
     tcbinfo = gdb.parse_and_eval("g_tcbinfo")
 
     if saved_regs:
@@ -42,25 +45,41 @@ def save_regs():
     arch = gdb.selected_frame().architecture()
     saved_regs = []
     i = 0
+
+    if not regoffset:
+        regoffset = [
+            int(tcbinfo["reg_off"]["p"][i])
+            for i in range(tcbinfo["regs_num"])
+            if tcbinfo["reg_off"]["p"][i] != UINT16_MAX
+        ]
+
     for reg in arch.registers():
-        if i >= tcbinfo["regs_num"]:
+        if i >= len(regoffset):
             break
 
-        saved_regs.append(gdb.parse_and_eval("$%s" % reg.name))
+        ret = gdb.parse_and_eval("$%s" % reg.name)
+        saved_regs.append(ret)
         i += 1
 
 
 def restore_regs():
     tcbinfo = gdb.parse_and_eval("g_tcbinfo")
     global saved_regs
+    global regoffset
 
     if not saved_regs:
         return
 
     arch = gdb.selected_frame().architecture()
     i = 0
+
+    regoffset = [
+        int(tcbinfo["reg_off"]["p"][i])
+        for i in range(tcbinfo["regs_num"])
+        if tcbinfo["reg_off"]["p"][i] != UINT16_MAX
+    ]
     for reg in arch.registers():
-        if i >= tcbinfo["regs_num"]:
+        if i >= len(regoffset):
             break
 
         gdb.execute(f"set ${reg.name}={int(saved_regs[i])}")
@@ -84,6 +103,8 @@ class SetRegs(gdb.Command):
         super(SetRegs, self).__init__("setregs", gdb.COMMAND_USER)
 
     def invoke(self, arg, from_tty):
+        global regoffset
+
         parser = argparse.ArgumentParser(
             description="Set registers to the specified values"
         )
@@ -116,11 +137,12 @@ class SetRegs(gdb.Command):
         save_regs()
         arch = gdb.selected_frame().architecture()
 
-        regoffset = [
-            int(tcbinfo["reg_off"]["p"][i])
-            for i in range(tcbinfo["regs_num"])
-            if tcbinfo["reg_off"]["p"][i] != UINT16_MAX
-        ]
+        if not regoffset:
+            regoffset = [
+                int(tcbinfo["reg_off"]["p"][i])
+                for i in range(tcbinfo["regs_num"])
+                if tcbinfo["reg_off"]["p"][i] != UINT16_MAX
+            ]
 
         i = 0
         for reg in arch.registers():

Reply via email to