Skip to content

Commit

Permalink
scripts/gdb: add GDB convenience functions $lx_dentry_name() and $lx_…
Browse files Browse the repository at this point in the history
…i_dentry()

$lx_dentry_name() generates a full VFS path from a given dentry pointer,
and $lx_i_dentry() returns the dentry pointer associated with the given
inode pointer, if there is one.

Link: https://lkml.kernel.org/r/c9a5ad8efbfbd2cc6559e082734eed7628f43a16.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>
  • Loading branch information
crass authored and akpm00 committed Apr 18, 2023
1 parent f4efbda commit 5a10562
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions scripts/gdb/linux/vfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,47 @@
# This work is licensed under the terms of the GNU GPL version 2.
#

import gdb
from linux import utils


def dentry_name(d):
parent = d['d_parent']
if parent == d or parent == 0:
return ""
p = dentry_name(d['d_parent']) + "/"
return p + d['d_iname'].string()

class DentryName(gdb.Function):
"""Return string of the full path of a dentry.
$lx_dentry_name(PTR): Given PTR to a dentry struct, return a string
of the full path of the dentry."""

def __init__(self):
super(DentryName, self).__init__("lx_dentry_name")

def invoke(self, dentry_ptr):
return dentry_name(dentry_ptr)

DentryName()


dentry_type = utils.CachedType("struct dentry")

class InodeDentry(gdb.Function):
"""Return dentry pointer for inode.
$lx_i_dentry(PTR): Given PTR to an inode struct, return a pointer to
the associated dentry struct, if there is one."""

def __init__(self):
super(InodeDentry, self).__init__("lx_i_dentry")

def invoke(self, inode_ptr):
d_u = inode_ptr["i_dentry"]["first"]
if d_u == 0:
return ""
return utils.container_of(d_u, dentry_type.get_type().pointer(), "d_u")

InodeDentry()

0 comments on commit 5a10562

Please sign in to comment.