Skip to content

Commit f4efbda

Browse files
crassakpm00
authored andcommitted
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>
1 parent 31088f6 commit f4efbda

4 files changed

Lines changed: 32 additions & 15 deletions

File tree

scripts/gdb/linux/proc.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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 @@
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,31 +172,31 @@ def invoke(self, arg, from_tty):
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']
186188

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,3 @@ def gdb_eval_or_none(expresssion):
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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
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

0 commit comments

Comments
 (0)