scripts/gdb/linux/device.py

Source file repositories/reference/linux-study-clean/scripts/gdb/linux/device.py

File Facts

System
Linux kernel
Corpus path
scripts/gdb/linux/device.py
Extension
.py
Size
5794 bytes
Lines
183
Domain
Support Tooling And Documentation
Bucket
scripts
Inferred role
Support Tooling And Documentation: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

bus_type = CachedType('struct bus_type')
class_type = CachedType('struct class')


def dev_name(dev):
    dev_init_name = dev['init_name']
    if dev_init_name:
        return dev_init_name.string()
    return dev['kobj']['name'].string()


def kset_for_each_object(kset):
    return list_for_each_entry(kset['list'],
            kobject_type.get_type().pointer(), "entry")


def for_each_bus():
    for kobj in kset_for_each_object(gdb.parse_and_eval('bus_kset')):
        subsys = container_of(kobj, kset_type.get_type().pointer(), 'kobj')
        subsys_priv = container_of(subsys, subsys_private_type.get_type().pointer(), 'subsys')
        yield subsys_priv


def for_each_class():
    for kobj in kset_for_each_object(gdb.parse_and_eval('class_kset')):
        subsys = container_of(kobj, kset_type.get_type().pointer(), 'kobj')
        subsys_priv = container_of(subsys, subsys_private_type.get_type().pointer(), 'subsys')
        yield subsys_priv


def get_bus_by_name(name):
    for item in for_each_bus():
        if item['bus']['name'].string() == name:
            return item
    raise gdb.GdbError("Can't find bus type {!r}".format(name))


def get_class_by_name(name):
    for item in for_each_class():
        if item['class']['name'].string() == name:
            return item
    raise gdb.GdbError("Can't find device class {!r}".format(name))


klist_type = CachedType('struct klist')
klist_node_type = CachedType('struct klist_node')


def klist_for_each(klist):
    return list_for_each_entry(klist['k_list'],
                klist_node_type.get_type().pointer(), 'n_node')


def bus_for_each_device(bus):
    for kn in klist_for_each(bus['klist_devices']):
        dp = container_of(kn, device_private_type.get_type().pointer(), 'knode_bus')
        yield dp['device']


def class_for_each_device(cls):
    for kn in klist_for_each(cls['klist_devices']):
        dp = container_of(kn, device_private_type.get_type().pointer(), 'knode_class')
        yield dp['device']


def device_for_each_child(dev):
    for kn in klist_for_each(dev['p']['klist_children']):
        dp = container_of(kn, device_private_type.get_type().pointer(), 'knode_parent')
        yield dp['device']

Annotation

Implementation Notes