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 796806c65be84a75ad5274d7a6cf6314b7f4091a
Author: xuxingliang <xuxingli...@xiaomi.com>
AuthorDate: Thu Aug 29 12:18:23 2024 +0800

    tools/gdb: allow to use info nxthreads
    
    (gdb) info threads
      Id   Target Id         Frame
    * 1.1  Thread 1 (Name: CPU0 IDLE, State: 3, Pri: 0, Stack: 41eccfec, Size: 
3976)                       0x402cd586 in up_idle () at chip/r528_idle.c:80
      1.2  Thread 2 (Name: CPU1 IDLE, State: 4, Pri: 0, Stack: 4194bb78, Size: 
3976)                       0x402cd586 in up_idle () at chip/r528_idle.c:80
    
    (gdb) info nxthreads
    Index Tid  Pid  Cpu  Thread                Info                             
                                                Frame
     0    0    0    0 '\000' Thread 0x419633b8     (Name: CPU0 IDLE, State: 
Assigned, Priority: 0, Stack: 3976) 0x402cd586  up_idle() at chip/r528_idle.c:80
    *1    1    1    1 '\001' Thread 0x41963498     (Name: CPU1 IDLE, State: 
Running, Priority: 0, Stack: 3976)  0x402cd586  up_idle() at chip/r528_idle.c:80
    (gdb)
    
    Signed-off-by: xuxingliang <xuxingli...@xiaomi.com>
---
 tools/gdb/thread.py | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/tools/gdb/thread.py b/tools/gdb/thread.py
index 01768d4d55..4e8ba981f3 100644
--- a/tools/gdb/thread.py
+++ b/tools/gdb/thread.py
@@ -161,7 +161,7 @@ class Nxinfothreads(gdb.Command):
     """Display information of all threads"""
 
     def __init__(self):
-        super(Nxinfothreads, self).__init__("info threads", gdb.COMMAND_USER)
+        super(Nxinfothreads, self).__init__("info nxthreads", gdb.COMMAND_USER)
 
     def invoke(self, args, from_tty):
         npidhash = gdb.parse_and_eval("g_npidhash")
@@ -252,7 +252,7 @@ class Nxthread(gdb.Command):
     """Switch to a specified thread"""
 
     def __init__(self):
-        super(Nxthread, self).__init__("thread", gdb.COMMAND_USER)
+        super(Nxthread, self).__init__("nxthread", gdb.COMMAND_USER)
 
     def invoke(self, args, from_tty):
         npidhash = gdb.parse_and_eval("g_npidhash")
@@ -551,17 +551,20 @@ class Ps(gdb.Command):
 def register_commands():
     SetRegs()
     Ps()
-
-    # Disable thread commands for core dump and gdb-stub.
-    # In which case the recognized threads count is less or equal to the 
number of cpus
+    Nxinfothreads()
+    Nxthread()
+    Nxcontinue()
+    Nxstep()
+
+    # Use custom command for thread if current target does not support it.
+    # The recognized threads count is less than or equal to the number of CPUs 
in this case.
+    # For coredump and gdb-stub, use native thread commands.
     ncpus = utils.get_symbol_value("CONFIG_SMP_NCPUS") or 1
     nthreads = len(gdb.selected_inferior().threads())
     if nthreads <= ncpus:
-        SetRegs()
-        Nxinfothreads()
-        Nxthread()
-        Nxcontinue()
-        Nxstep()
+        # Native threads command is not available, override the threads command
+        gdb.execute("define info threads\n info nxthreads \n end\n")
+        gdb.execute("define thread\n nxthread \n end\n")
 
         # We can't use a user command to rename continue it will recursion
         gdb.execute("define c\n nxcontinue \n end\n")

Reply via email to