xref: /linux-6.15/scripts/gdb/linux/vfs.py (revision 5a10562b)
1f4efbdafSGlenn Washburn#
2f4efbdafSGlenn Washburn# gdb helper commands and functions for Linux kernel debugging
3f4efbdafSGlenn Washburn#
4f4efbdafSGlenn Washburn#  VFS tools
5f4efbdafSGlenn Washburn#
6f4efbdafSGlenn Washburn# Copyright (c) 2023 Glenn Washburn
7f4efbdafSGlenn Washburn# Copyright (c) 2016 Linaro Ltd
8f4efbdafSGlenn Washburn#
9f4efbdafSGlenn Washburn# Authors:
10f4efbdafSGlenn Washburn#  Glenn Washburn <[email protected]>
11f4efbdafSGlenn Washburn#  Kieran Bingham <[email protected]>
12f4efbdafSGlenn Washburn#
13f4efbdafSGlenn Washburn# This work is licensed under the terms of the GNU GPL version 2.
14f4efbdafSGlenn Washburn#
15f4efbdafSGlenn Washburn
16*5a10562bSGlenn Washburnimport gdb
17*5a10562bSGlenn Washburnfrom linux import utils
18*5a10562bSGlenn Washburn
19f4efbdafSGlenn Washburn
20f4efbdafSGlenn Washburndef dentry_name(d):
21f4efbdafSGlenn Washburn    parent = d['d_parent']
22f4efbdafSGlenn Washburn    if parent == d or parent == 0:
23f4efbdafSGlenn Washburn        return ""
24f4efbdafSGlenn Washburn    p = dentry_name(d['d_parent']) + "/"
25f4efbdafSGlenn Washburn    return p + d['d_iname'].string()
26*5a10562bSGlenn Washburn
27*5a10562bSGlenn Washburnclass DentryName(gdb.Function):
28*5a10562bSGlenn Washburn    """Return string of the full path of a dentry.
29*5a10562bSGlenn Washburn
30*5a10562bSGlenn Washburn$lx_dentry_name(PTR): Given PTR to a dentry struct, return a string
31*5a10562bSGlenn Washburnof the full path of the dentry."""
32*5a10562bSGlenn Washburn
33*5a10562bSGlenn Washburn    def __init__(self):
34*5a10562bSGlenn Washburn        super(DentryName, self).__init__("lx_dentry_name")
35*5a10562bSGlenn Washburn
36*5a10562bSGlenn Washburn    def invoke(self, dentry_ptr):
37*5a10562bSGlenn Washburn        return dentry_name(dentry_ptr)
38*5a10562bSGlenn Washburn
39*5a10562bSGlenn WashburnDentryName()
40*5a10562bSGlenn Washburn
41*5a10562bSGlenn Washburn
42*5a10562bSGlenn Washburndentry_type = utils.CachedType("struct dentry")
43*5a10562bSGlenn Washburn
44*5a10562bSGlenn Washburnclass InodeDentry(gdb.Function):
45*5a10562bSGlenn Washburn    """Return dentry pointer for inode.
46*5a10562bSGlenn Washburn
47*5a10562bSGlenn Washburn$lx_i_dentry(PTR): Given PTR to an inode struct, return a pointer to
48*5a10562bSGlenn Washburnthe associated dentry struct, if there is one."""
49*5a10562bSGlenn Washburn
50*5a10562bSGlenn Washburn    def __init__(self):
51*5a10562bSGlenn Washburn        super(InodeDentry, self).__init__("lx_i_dentry")
52*5a10562bSGlenn Washburn
53*5a10562bSGlenn Washburn    def invoke(self, inode_ptr):
54*5a10562bSGlenn Washburn        d_u = inode_ptr["i_dentry"]["first"]
55*5a10562bSGlenn Washburn        if d_u == 0:
56*5a10562bSGlenn Washburn            return ""
57*5a10562bSGlenn Washburn        return utils.container_of(d_u, dentry_type.get_type().pointer(), "d_u")
58*5a10562bSGlenn Washburn
59*5a10562bSGlenn WashburnInodeDentry()
60