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 7927c8d105d6976147d76c5af81354e47cadc6a3
Author: dongjiuzhu1 <dongjiuz...@xiaomi.com>
AuthorDate: Sat Jun 7 20:55:34 2025 +0800

    tools/pynuttx: update fs.py base on new structure fd and file
    
    Update the Python script based on the PR "Separate file
    descriptors from file descriptions" in fs/vfs.
    
    Signed-off-by: dongjiuzhu1 <dongjiuz...@xiaomi.com>
---
 tools/pynuttx/nxgdb/fs.py               | 33 +++++++++++++++++----------------
 tools/pynuttx/nxgdb/protocols/fs.py     | 19 +++++++++++++------
 tools/pynuttx/nxgdb/protocols/thread.py |  4 ++--
 3 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/tools/pynuttx/nxgdb/fs.py b/tools/pynuttx/nxgdb/fs.py
index 0ebbc9d173..9a52d56dbd 100644
--- a/tools/pynuttx/nxgdb/fs.py
+++ b/tools/pynuttx/nxgdb/fs.py
@@ -36,8 +36,8 @@ CONFIG_PSEUDOFS_FILE = 
utils.get_symbol_value("CONFIG_PSEUDOFS_FILE")
 CONFIG_PSEUDOFS_ATTRIBUTES = 
utils.get_symbol_value("CONFIG_PSEUDOFS_ATTRIBUTES")
 
 CONFIG_FS_BACKTRACE = utils.get_symbol_value("CONFIG_FS_BACKTRACE")
-CONFIG_NFILE_DESCRIPTORS_PER_BLOCK = int(
-    utils.get_symbol_value("CONFIG_NFILE_DESCRIPTORS_PER_BLOCK")
+CONFIG_NFILE_DESCRIPTORS_PER_BLOCK = utils.get_field_nitems(
+    "struct fdlist", "fl_prefds"
 )
 CONFIG_FS_SHMFS = utils.get_symbol_value("CONFIG_FS_SHMFS")
 
@@ -171,9 +171,9 @@ def inode_gettype(inode: p.Inode) -> InodeType:
 
 def get_file(tcb: Tcb, fd):
     group = tcb.group
-    filelist = group.tg_filelist
-    fl_files = filelist.fl_files
-    fl_rows = filelist.fl_rows
+    fdlist = group.tg_fdlist
+    fl_fds = fdlist.fl_fds
+    fl_rows = fdlist.fl_rows
 
     row = fd // CONFIG_NFILE_DESCRIPTORS_PER_BLOCK
     col = fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK
@@ -181,7 +181,7 @@ def get_file(tcb: Tcb, fd):
     if row >= fl_rows:
         return None
 
-    return fl_files[row][col]
+    return fl_fds[row][col]
 
 
 def foreach_inode(root=None, path="") -> Generator[Tuple[p.Inode, str], None, 
None]:
@@ -197,20 +197,21 @@ def foreach_inode(root=None, path="") -> 
Generator[Tuple[p.Inode, str], None, No
 def foreach_file(tcb: Tcb):
     """Iterate over all file descriptors in a tcb"""
     group = tcb.group
-    filelist = group.tg_filelist
-    fl_files = filelist.fl_files
-    fl_rows = filelist.fl_rows
+    fdlist = group.tg_fdlist
+    fl_fds = fdlist.fl_fds
+    fl_rows = fdlist.fl_rows
 
     for row in range(fl_rows):
         for col in range(CONFIG_NFILE_DESCRIPTORS_PER_BLOCK):
-            file = fl_files[row][col]
+            fdp = fl_fds[row][col]
 
-            if not file or not file.f_inode:
+            if not fdp or not fdp.f_file:
                 continue
 
             fd = row * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK + col
+            file = fdp.f_file
 
-            yield fd, file
+            yield fd, fdp, file
 
 
 class Fdinfo(gdb.Command):
@@ -220,7 +221,7 @@ class Fdinfo(gdb.Command):
         super().__init__("fdinfo", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION)
         self.total_fd_count = 0
 
-    def print_file_info(self, fd, file: p.File, formatter: str):
+    def print_file_info(self, fd, fdp: p.Fd, file: p.File, formatter: str):
         backtrace_formatter = "{0:<5} {1:<36} {2}"
 
         oflags = int(file.f_oflags)
@@ -230,7 +231,7 @@ class Fdinfo(gdb.Command):
         output = []
         if CONFIG_FS_BACKTRACE:
             backtrace = utils.Backtrace(
-                utils.ArrayIterator(file.f_backtrace), 
formatter=backtrace_formatter
+                utils.ArrayIterator(fdp.f_backtrace), 
formatter=backtrace_formatter
             )
 
             output.append(
@@ -269,8 +270,8 @@ class Fdinfo(gdb.Command):
         gdb.write(formatter.format(*headers) + "\n")
 
         fd_count = 0
-        for fd, file in foreach_file(tcb):
-            self.print_file_info(fd, file, formatter)
+        for fd, fdp, file in foreach_file(tcb):
+            self.print_file_info(fd, fdp, file, formatter)
             fd_count += 1
         self.total_fd_count += fd_count
 
diff --git a/tools/pynuttx/nxgdb/protocols/fs.py 
b/tools/pynuttx/nxgdb/protocols/fs.py
index 2771eba71e..592b99d1a6 100644
--- a/tools/pynuttx/nxgdb/protocols/fs.py
+++ b/tools/pynuttx/nxgdb/protocols/fs.py
@@ -23,6 +23,16 @@
 from .value import Value
 
 
+class Fd(Value):
+    """struct fd"""
+
+    f_file: Value
+    f_cloexec: Value
+    f_tag_fdcheck: Value
+    f_tag_fdsan: Value
+    f_backtrace: Value
+
+
 class File(Value):
     """struct file"""
 
@@ -31,9 +41,6 @@ class File(Value):
     f_pos: Value
     f_inode: Value
     f_priv: Value
-    f_tag_fdsan: Value
-    f_tag_fdcheck: Value
-    f_backtrace: Value
     f_locked: Value
 
 
@@ -58,8 +65,8 @@ class Inode(Value):
     i_name: Value
 
 
-class FileList(Value):
-    """struct filelist_s"""
+class FdList(Value):
+    """struct fdlist"""
 
     fl_rows: Value
-    fl_files: Value
+    fl_fds: Value
diff --git a/tools/pynuttx/nxgdb/protocols/thread.py 
b/tools/pynuttx/nxgdb/protocols/thread.py
index 71e970bea8..750aa8b8ad 100644
--- a/tools/pynuttx/nxgdb/protocols/thread.py
+++ b/tools/pynuttx/nxgdb/protocols/thread.py
@@ -20,7 +20,7 @@
 #
 ############################################################################
 
-from .fs import FileList
+from .fs import FdList
 from .value import Value
 
 
@@ -52,7 +52,7 @@ class Group(Value):
     tg_envp: Value
     tg_envc: Value
     itimer: Value
-    tg_filelist: FileList
+    tg_fdlist: FdList
     tg_mm_map: Value
 
 

Reply via email to