History

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>

Glenn Washburn committed 3 years ago

Commit f4efbda1 parent 31088f64 files · +32 −15Browse files

Unified · Split

4 files
  1. scripts/gdb/linux/proc.py +9 −7
  2. scripts/gdb/linux/utils.py +0 −8
  3. scripts/gdb/linux/vfs.py +22 −0
  4. scripts/gdb/vmlinux-gdb.py +1 −0
scripts/gdb/linux/proc.py+9−7
@@ -1,3 +1,4 @@
1+# SPDX-License-Identifier: GPL-2.0
12 #
23 # gdb helper commands and functions for Linux kernel debugging
34 #
@@ -16,6 +17,7 @@ from linux import constants · 12 unmodified lines
1617 from linux import utils
1718 from linux import tasks
1819 from linux import lists
20+from linux import vfs
1921 from struct import *
2022
2123
@@ -170,16 +172,16 @@ values of that process namespace""" · 148 unmodified lines
170172 gdb.write("{:^18} {:^15} {:>9} {} {} options\n".format(
171173 "mount", "super_block", "devname", "pathname", "fstype"))
172174
173− for vfs in lists.list_for_each_entry(namespace['list'],
175+ for mnt in lists.list_for_each_entry(namespace['list'],
174176 mount_ptr_type, "mnt_list"):
175− devname = vfs['mnt_devname'].string()
177+ devname = mnt['mnt_devname'].string()
176178 devname = devname if devname else "none"
177179
178180 pathname = ""
179− parent = vfs
181+ parent = mnt
180182 while True:
181183 mntpoint = parent['mnt_mountpoint']
182− pathname = utils.dentry_name(mntpoint) + pathname
184+ pathname = vfs.dentry_name(mntpoint) + pathname
183185 if (parent == parent['mnt_parent']):
184186 break
185187 parent = parent['mnt_parent']
@@ -187,14 +189,14 @@ values of that process namespace""" · 1 unmodified line
187189 if (pathname == ""):
188190 pathname = "/"
189191
190− superblock = vfs['mnt']['mnt_sb']
192+ superblock = mnt['mnt']['mnt_sb']
191193 fstype = superblock['s_type']['name'].string()
192194 s_flags = int(superblock['s_flags'])
193− m_flags = int(vfs['mnt']['mnt_flags'])
195+ m_flags = int(mnt['mnt']['mnt_flags'])
194196 rd = "ro" if (s_flags & constants.LX_SB_RDONLY) else "rw"
195197
196198 gdb.write("{} {} {} {} {} {}{}{} 0 0\n".format(
197− vfs.format_string(), superblock.format_string(), devname,
199+ mnt.format_string(), superblock.format_string(), devname,
198200 pathname, fstype, rd, info_opts(FS_INFO, s_flags),
199201 info_opts(MNT_INFO, m_flags)))
200202
scripts/gdb/linux/utils.py+0−8
@@ -196,11 +196,3 @@ def gdb_eval_or_none(expresssion): · 195 unmodified lines
196196 return gdb.parse_and_eval(expresssion)
197197 except gdb.error:
198198 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()
scripts/gdb/linux/vfs.py+22−0
@@ -0,0 +1,22 @@
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()
scripts/gdb/vmlinux-gdb.py+1−0
@@ -40,6 +40,7 @@ else: · 39 unmodified lines
4040 import linux.clk
4141 import linux.genpd
4242 import linux.device
43+ import linux.vfs
4344 import linux.mm
4445 import linux.radixtree
4546 import linux.interrupts