Skip to contentSkip to conversation

GDB VFS utils

PATCH In review Glenn Washburn 3 participants 5 messages Mar 1, 2023 – Apr 12, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover GDB VFS utils

Hi all,

I've created a couple GDB convenience functions that I found useful when debugging some VFS issues and figure others might find them useful. For instance, they are useful in setting conditional breakpoints on VFS functions where you only care if the dentry path is a certain value. I took the opportunity to create a new "vfs" python module to give VFS related utilities a home.

Glenn

Glenn Washburn (2):
scripts/gdb: Create linux/vfs.py for VFS related GDB helpers scripts/gdb: Add GDB convenience functions $lx_dentry_name() and

    $lx_i_dentry()
 scripts/gdb/linux/proc.py  | 15 +++++-----
 scripts/gdb/linux/utils.py |  8 ------
 scripts/gdb/linux/vfs.py   | 59 ++++++++++++++++++++++++++++++++++++++
 scripts/gdb/vmlinux-gdb.py |  1 +
 4 files changed, 68 insertions(+), 15 deletions(-)
 create mode 100644 scripts/gdb/linux/vfs.py
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/2 scripts/gdb: Create linux/vfs.py for VFS related GDB helpers

This will allow for more VFS specific GDB helpers to be collected in one place. Move utils.dentry_name into the vfs modules. Also a local variable in proc.py was changed from vfs to mnt to prevent a naming collision with the new vfs module.

---
 scripts/gdb/linux/proc.py  | 15 ++++++++-------
 scripts/gdb/linux/utils.py |  8 --------
 scripts/gdb/linux/vfs.py   | 22 ++++++++++++++++++++++
 scripts/gdb/vmlinux-gdb.py |  1 +
 4 files changed, 31 insertions(+), 15 deletions(-)
 create mode 100644 scripts/gdb/linux/vfs.py
scripts/gdb/linux/proc.py +8 -7
index 09cd871925a5..f2c9ba62534b 100644
@@ -16,6 +16,7 @@ from linux import constants
 from linux import utils
 from linux import tasks
 from linux import lists
+from linux import vfs
 from struct import *
 
 
@@ -170,16 +171,16 @@ values of that process namespace"""
         gdb.write("{:^18} {:^15} {:>9} {} {} options\n".format(
                   "mount", "super_block", "devname", "pathname", "fstype"))
 
-        for vfs in lists.list_for_each_entry(namespace['list'],
+        for mnt in lists.list_for_each_entry(namespace['list'],
                                              mount_ptr_type, "mnt_list"):
-            devname = vfs['mnt_devname'].string()
+            devname = mnt['mnt_devname'].string()
             devname = devname if devname else "none"
 
             pathname = ""
-            parent = vfs
+            parent = mnt
             while True:
                 mntpoint = parent['mnt_mountpoint']
-                pathname = utils.dentry_name(mntpoint) + pathname
+                pathname = vfs.dentry_name(mntpoint) + pathname
                 if (parent == parent['mnt_parent']):
                     break
                 parent = parent['mnt_parent']
@@ -187,14 +188,14 @@ values of that process namespace"""
             if (pathname == ""):
                 pathname = "/"
 
-            superblock = vfs['mnt']['mnt_sb']
+            superblock = mnt['mnt']['mnt_sb']
             fstype = superblock['s_type']['name'].string()
             s_flags = int(superblock['s_flags'])
-            m_flags = int(vfs['mnt']['mnt_flags'])
+            m_flags = int(mnt['mnt']['mnt_flags'])
             rd = "ro" if (s_flags & constants.LX_SB_RDONLY) else "rw"
 
             gdb.write("{} {} {} {} {} {}{}{} 0 0\n".format(
-                      vfs.format_string(), superblock.format_string(), devname,
+                      mnt.format_string(), superblock.format_string(), devname,
                       pathname, fstype, rd, info_opts(FS_INFO, s_flags),
                       info_opts(MNT_INFO, m_flags)))
 
scripts/gdb/linux/utils.py +0 -8
index 1553f68716cc..46233e845be3 100644
@@ -193,11 +193,3 @@ def gdb_eval_or_none(expresssion):
         return gdb.parse_and_eval(expresssion)
     except gdb.error:
         return None
-
-
-def dentry_name(d):
-    parent = d['d_parent']
-    if parent == d or parent == 0:
-        return ""
-    p = dentry_name(d['d_parent']) + "/"
-    return p + d['d_iname'].string()
scripts/gdb/linux/vfs.py new file +22 -0
new file mode 100644
index 000000000000..62d4f9ad7d79
@@ -0,0 +1,22 @@
+#
+# gdb helper commands and functions for Linux kernel debugging
+#
+#  VFS tools
+#
+# Copyright (c) 2023 Glenn Washburn
+# Copyright (c) 2016 Linaro Ltd
+#
+# Authors:
+#  Glenn Washburn <[email protected]>
+#  Kieran Bingham <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL version 2.
+#
+
+
+def dentry_name(d):
+    parent = d['d_parent']
+    if parent == d or parent == 0:
+        return ""
+    p = dentry_name(d['d_parent']) + "/"
+    return p + d['d_iname'].string()
scripts/gdb/vmlinux-gdb.py +1 -0
index 3e8d3669f0ce..b5af64dcf4ed 100644
@@ -37,3 +37,4 @@ else:
     import linux.clk
     import linux.genpd
     import linux.device
+    import linux.vfs
Signature · 1 line
2.30.2
#3 lore raw

PATCH 2/2 scripts/gdb: Add GDB convenience functions $lx_dentry_name() and $lx_i_dentry()

In reply to Glenn Washburn

$lx_dentry_name() generates a full VFS path from a given dentry pointer, and $lx_i_dentry() returns the dentry pointer associated with the given inode pointer, if there is one.

---
 scripts/gdb/linux/vfs.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
scripts/gdb/linux/vfs.py +37 -0
index 62d4f9ad7d79..c77b9ce75f6d 100644
@@ -13,6 +13,9 @@
 # This work is licensed under the terms of the GNU GPL version 2.
 #
 
+import gdb
+from linux import utils
+
 
 def dentry_name(d):
     parent = d['d_parent']
@@ -20,3 +23,37 @@ def dentry_name(d):
         return ""
     p = dentry_name(d['d_parent']) + "/"
     return p + d['d_iname'].string()
+
+class DentryName(gdb.Function):
+    """Return string of the full path of a dentry.
+
+$lx_dentry_name(PTR): Given PTR to a dentry struct, return a string
+of the full path of the dentry."""
+
+    def __init__(self):
+        super(DentryName, self).__init__("lx_dentry_name")
+
+    def invoke(self, dentry_ptr):
+        return dentry_name(dentry_ptr)
+
+DentryName()
+
+
+dentry_type = utils.CachedType("struct dentry")
+
+class InodeDentry(gdb.Function):
+    """Return dentry pointer for inode.
+
+$lx_i_dentry(PTR): Given PTR to an inode struct, return a pointer to
+the associated dentry struct, if there is one."""
+
+    def __init__(self):
+        super(InodeDentry, self).__init__("lx_i_dentry")
+
+    def invoke(self, inode_ptr):
+        d_u = inode_ptr["i_dentry"]["first"]
+        if d_u == 0:
+            return ""
+        return utils.container_of(d_u, dentry_type.get_type().pointer(), "d_u")
+
+InodeDentry()
Signature · 1 line
2.30.2
#4 lore raw
In reply to Glenn Washburn
Quoted 8 lines · Glenn Washburn

Hi all,

I've created a couple GDB convenience functions that I found useful when debugging some VFS issues and figure others might find them useful. For instance, they are useful in setting conditional breakpoints on VFS functions where you only care if the dentry path is a certain value. I took the opportunity to create a new "vfs" python module to give VFS related utilities a home.

Andrew, any chance you could pick up those two patches from Glenn:

https://lore.kernel.org/all/7bba4c065a8c2c47f1fc5b03a7278005b04db251.1677631565.git.development@efficientek.com/
https://lore.kernel.org/all/c9a5ad8efbfbd2cc6559e082734eed7628f43a16.1677631565.git.development@efficientek.com/

Thanks!

Signature · 1 line
Florian
#2 lore raw

Re: [PATCH 1/2] scripts/gdb: Create linux/vfs.py for VFS related GDB helpers

In reply to Glenn Washburn
Quoted 4 lines · On Tue, 28 Feb 2023 18:53:34 -0600 Glenn Washburn…

This will allow for more VFS specific GDB helpers to be collected in one place. Move utils.dentry_name into the vfs modules. Also a local variable in proc.py was changed from vfs to mnt to prevent a naming collision with the new vfs module.

checkpatch gets unhappy. Please add this addition?

scripts/gdb/linux/proc.py renamed from scripts/gdb/linux/proc.py~scripts-gdb-create-linux-vfspy-for-vfs-related-gdb-helpers-fix +1 -0
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
 #
 # gdb helper commands and functions for Linux kernel debugging
 #

_