drgn/contrib/platform_drivers.py
Omar Sandoval 9ad47a97eb contrib: add script to dump platform drivers
For a discussion on the linux-debuggers mailing list:
https://lore.kernel.org/linux-debuggers/87v8fiw0fm.fsf@oracle.com/T/#t

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2023-06-20 11:11:23 -07:00

29 lines
859 B
Python

# Copyright (c) Meta Platforms, Inc. and affiliates.
# SPDX-License-Identifier: LGPL-2.1-or-later
"""Print registered platform drivers."""
from drgn import NULL, container_of
from drgn.helpers.linux.list import list_for_each_entry
def bus_to_subsys(bus):
for sp in list_for_each_entry(
"struct subsys_private",
prog["bus_kset"].list.address_of_(),
"subsys.kobj.entry",
):
if sp.bus == bus:
return sp
return NULL(bus.prog_, "struct subsys_private *")
sp = bus_to_subsys(prog["platform_bus_type"].address_of_())
for priv in list_for_each_entry(
"struct driver_private", sp.drivers_kset.list.address_of_(), "kobj.entry"
):
driver = priv.driver
print(driver.name.string_().decode())
platform_driver = container_of(driver, "struct platform_driver", "driver")
print(platform_driver)