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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
- No C-style include directives detected by the generator.
Detected Declarations
- No top-level syscall, struct, function, initcall, or export declaration detected by the generator.
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
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: pattern implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.