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
1#2#
2# gdb helper commands and functions for Linux kernel debugging3# gdb helper commands and functions for Linux kernel debugging
3#4#
@@ -16,6 +17,7 @@ from linux import constants · 12 unmodified lines
16from linux import utils17from linux import utils
17from linux import tasks18from linux import tasks
18from linux import lists19from linux import lists
20from linux import vfs
19from struct import *21from struct import *
20 22
21 23
@@ -170,16 +172,16 @@ values of that process namespace""" · 148 unmodified lines
170 gdb.write("{:^18} {:^15} {:>9} {} {} options\n".format(172 gdb.write("{:^18} {:^15} {:>9} {} {} options\n".format(
171 "mount", "super_block", "devname", "pathname", "fstype"))173 "mount", "super_block", "devname", "pathname", "fstype"))
172 174
173 for vfs in lists.list_for_each_entry(namespace['list'],175 for mnt in lists.list_for_each_entry(namespace['list'],
174 mount_ptr_type, "mnt_list"):176 mount_ptr_type, "mnt_list"):
175 devname = vfs['mnt_devname'].string()177 devname = mnt['mnt_devname'].string()
176 devname = devname if devname else "none"178 devname = devname if devname else "none"
177 179
178 pathname = ""180 pathname = ""
179 parent = vfs181 parent = mnt
180 while True:182 while True:
181 mntpoint = parent['mnt_mountpoint']183 mntpoint = parent['mnt_mountpoint']
182 pathname = utils.dentry_name(mntpoint) + pathname184 pathname = vfs.dentry_name(mntpoint) + pathname
183 if (parent == parent['mnt_parent']):185 if (parent == parent['mnt_parent']):
184 break186 break
185 parent = parent['mnt_parent']187 parent = parent['mnt_parent']
@@ -187,14 +189,14 @@ values of that process namespace""" · 1 unmodified line
187 if (pathname == ""):189 if (pathname == ""):
188 pathname = "/"190 pathname = "/"
189 191
190 superblock = vfs['mnt']['mnt_sb']192 superblock = mnt['mnt']['mnt_sb']
191 fstype = superblock['s_type']['name'].string()193 fstype = superblock['s_type']['name'].string()
192 s_flags = int(superblock['s_flags'])194 s_flags = int(superblock['s_flags'])
193 m_flags = int(vfs['mnt']['mnt_flags'])195 m_flags = int(mnt['mnt']['mnt_flags'])
194 rd = "ro" if (s_flags & constants.LX_SB_RDONLY) else "rw"196 rd = "ro" if (s_flags & constants.LX_SB_RDONLY) else "rw"
195 197
196 gdb.write("{} {} {} {} {} {}{}{} 0 0\n".format(198 gdb.write("{} {} {} {} {} {}{}{} 0 0\n".format(
197 vfs.format_string(), superblock.format_string(), devname,199 mnt.format_string(), superblock.format_string(), devname,
198 pathname, fstype, rd, info_opts(FS_INFO, s_flags),200 pathname, fstype, rd, info_opts(FS_INFO, s_flags),
199 info_opts(MNT_INFO, m_flags)))201 info_opts(MNT_INFO, m_flags)))
200 202
scripts/gdb/linux/utils.py+0−8
@@ -196,11 +196,3 @@ def gdb_eval_or_none(expresssion): · 195 unmodified lines
196 return gdb.parse_and_eval(expresssion)196 return gdb.parse_and_eval(expresssion)
197 except gdb.error:197 except gdb.error:
198 return None198 return None
199
200
201def 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
17def 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
40 import linux.clk40 import linux.clk
41 import linux.genpd41 import linux.genpd
42 import linux.device42 import linux.device
43 import linux.vfs
43 import linux.mm44 import linux.mm
44 import linux.radixtree45 import linux.radixtree
45 import linux.interrupts46 import linux.interrupts