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 38b5dcd42c75f26cd749dd47b8eb723ccb7f9d82
Author: xuxingliang <[email protected]>
AuthorDate: Tue Oct 22 20:32:55 2024 +0800

    gdb/register: register name sp, pc are always available
    
    GDB provides four “standard” register names sp, pc, fp and ps. Those can be 
used in most of the cases.
    
    See https://sourceware.org/gdb/current/onlinedocs/gdb.html/Registers.html
    
    Signed-off-by: xuxingliang <[email protected]>
---
 tools/gdb/nuttxgdb/stack.py |  7 +++----
 tools/gdb/nuttxgdb/utils.py | 30 ++----------------------------
 2 files changed, 5 insertions(+), 32 deletions(-)

diff --git a/tools/gdb/nuttxgdb/stack.py b/tools/gdb/nuttxgdb/stack.py
index f1bc60d4eb..8315f600d4 100644
--- a/tools/gdb/nuttxgdb/stack.py
+++ b/tools/gdb/nuttxgdb/stack.py
@@ -137,10 +137,9 @@ def fetch_stacks():
     stacks = dict()
 
     for tcb in utils.get_tcbs():
-        if (
-            tcb["task_state"] == gdb.parse_and_eval("TSTATE_TASK_RUNNING")
-            and not utils.in_interrupt_context()
-        ):
+        # We have no way to detect if we are in an interrupt context for now.
+        # Originally we use `and not utils.in_interrupt_context()`
+        if tcb["task_state"] == gdb.parse_and_eval("TSTATE_TASK_RUNNING"):
             sp = utils.get_sp()
         else:
             sp = utils.get_sp(tcb=tcb)
diff --git a/tools/gdb/nuttxgdb/utils.py b/tools/gdb/nuttxgdb/utils.py
index f85b803656..4595495162 100644
--- a/tools/gdb/nuttxgdb/utils.py
+++ b/tools/gdb/nuttxgdb/utils.py
@@ -519,32 +519,6 @@ def in_interrupt_context(cpuid=0):
         return not g_current_regs or not g_current_regs[cpuid]
 
 
-def get_arch_sp_name():
-    if is_target_arch("arm") or is_target_arch("aarch64"):
-        # arm and arm variants
-        return "sp"
-    elif is_target_arch("i386", exact=True):
-        return "esp"
-    elif is_target_arch("i386:x86-64", exact=True):
-        return "rsp"
-    else:
-        # Default to use sp, add more archs if needed
-        return "sp"
-
-
-def get_arch_pc_name():
-    if is_target_arch("arm") or is_target_arch("aarch64"):
-        # arm and arm variants
-        return "pc"
-    elif is_target_arch("i386", exact=True):
-        return "eip"
-    elif is_target_arch("i386:x86-64", exact=True):
-        return "rip"
-    else:
-        # Default to use pc, add more archs if needed
-        return "pc"
-
-
 def get_register_byname(regname, tcb=None):
     frame = gdb.selected_frame()
 
@@ -572,11 +546,11 @@ def get_register_byname(regname, tcb=None):
 
 
 def get_sp(tcb=None):
-    return get_register_byname(get_arch_sp_name(), tcb)
+    return get_register_byname("sp", tcb)
 
 
 def get_pc(tcb=None):
-    return get_register_byname(get_arch_pc_name(), tcb)
+    return get_register_byname("pc", tcb)
 
 
 def get_tcbs():

Reply via email to