Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scripts/gdb: create linux/vfs.py for VFS related GDB helpers

Patch series "GDB VFS utils".

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.


This patch (of 2):

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.

[akpm@linux-foundation.org: add SPDX-License-Identifier]
Link: https://lkml.kernel.org/r/cover.1677631565.git.development@efficientek.com
Link: https://lkml.kernel.org/r/7bba4c065a8c2c47f1fc5b03a7278005b04db251.1677631565.git.development@efficientek.com
Signed-off-by: Glenn Washburn <development@efficientek.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Antonio Borneo <antonio.borneo@foss.st.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>
Cc: John Ogness <john.ogness@linutronix.de>
Cc: Kieran Bingham <kbingham@kernel.org>
Cc: Petr Mladek <pmladek@suse.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Glenn Washburn and committed by
Andrew Morton
f4efbdaf 31088f6f

+32 -15
+9 -7
scripts/gdb/linux/proc.py
··· 1 + # SPDX-License-Identifier: GPL-2.0 1 2 # 2 3 # gdb helper commands and functions for Linux kernel debugging 3 4 # ··· 17 16 from linux import utils 18 17 from linux import tasks 19 18 from linux import lists 19 + from linux import vfs 20 20 from struct import * 21 21 22 22 ··· 172 170 gdb.write("{:^18} {:^15} {:>9} {} {} options\n".format( 173 171 "mount", "super_block", "devname", "pathname", "fstype")) 174 172 175 - for vfs in lists.list_for_each_entry(namespace['list'], 173 + for mnt in lists.list_for_each_entry(namespace['list'], 176 174 mount_ptr_type, "mnt_list"): 177 - devname = vfs['mnt_devname'].string() 175 + devname = mnt['mnt_devname'].string() 178 176 devname = devname if devname else "none" 179 177 180 178 pathname = "" 181 - parent = vfs 179 + parent = mnt 182 180 while True: 183 181 mntpoint = parent['mnt_mountpoint'] 184 - pathname = utils.dentry_name(mntpoint) + pathname 182 + pathname = vfs.dentry_name(mntpoint) + pathname 185 183 if (parent == parent['mnt_parent']): 186 184 break 187 185 parent = parent['mnt_parent'] ··· 189 187 if (pathname == ""): 190 188 pathname = "/" 191 189 192 - superblock = vfs['mnt']['mnt_sb'] 190 + superblock = mnt['mnt']['mnt_sb'] 193 191 fstype = superblock['s_type']['name'].string() 194 192 s_flags = int(superblock['s_flags']) 195 - m_flags = int(vfs['mnt']['mnt_flags']) 193 + m_flags = int(mnt['mnt']['mnt_flags']) 196 194 rd = "ro" if (s_flags & constants.LX_SB_RDONLY) else "rw" 197 195 198 196 gdb.write("{} {} {} {} {} {}{}{} 0 0\n".format( 199 - vfs.format_string(), superblock.format_string(), devname, 197 + mnt.format_string(), superblock.format_string(), devname, 200 198 pathname, fstype, rd, info_opts(FS_INFO, s_flags), 201 199 info_opts(MNT_INFO, m_flags))) 202 200
-8
scripts/gdb/linux/utils.py
··· 196 196 return gdb.parse_and_eval(expresssion) 197 197 except gdb.error: 198 198 return None 199 - 200 - 201 - def dentry_name(d): 202 - parent = d['d_parent'] 203 - if parent == d or parent == 0: 204 - return "" 205 - p = dentry_name(d['d_parent']) + "/" 206 - return p + d['d_iname'].string()
+22
scripts/gdb/linux/vfs.py
··· 1 + # 2 + # gdb helper commands and functions for Linux kernel debugging 3 + # 4 + # VFS tools 5 + # 6 + # Copyright (c) 2023 Glenn Washburn 7 + # Copyright (c) 2016 Linaro Ltd 8 + # 9 + # Authors: 10 + # Glenn Washburn <development@efficientek.com> 11 + # Kieran Bingham <kieran.bingham@linaro.org> 12 + # 13 + # This work is licensed under the terms of the GNU GPL version 2. 14 + # 15 + 16 + 17 + def dentry_name(d): 18 + parent = d['d_parent'] 19 + if parent == d or parent == 0: 20 + return "" 21 + p = dentry_name(d['d_parent']) + "/" 22 + return p + d['d_iname'].string()
+1
scripts/gdb/vmlinux-gdb.py
··· 40 40 import linux.clk 41 41 import linux.genpd 42 42 import linux.device 43 + import linux.vfs 43 44 import linux.mm 44 45 import linux.radixtree 45 46 import linux.interrupts