scripts/gdb/linux/bpf.py
Source file repositories/reference/linux-study-clean/scripts/gdb/linux/bpf.py
File Facts
- System
- Linux kernel
- Corpus path
scripts/gdb/linux/bpf.py- Extension
.py- Size
- 7806 bytes
- Lines
- 254
- Domain
- Support Tooling And Documentation
- Bucket
- scripts
- Inferred role
- Support Tooling And Documentation: scripts
- Status
- atlas-only
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 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
# SPDX-License-Identifier: GPL-2.0
import json
import subprocess
import tempfile
import gdb
from linux import constants, lists, radixtree, utils
if constants.LX_CONFIG_BPF and constants.LX_CONFIG_BPF_JIT:
bpf_ksym_type = utils.CachedType("struct bpf_ksym")
if constants.LX_CONFIG_BPF_SYSCALL:
bpf_prog_type = utils.CachedType("struct bpf_prog")
def get_ksym_name(ksym):
name = ksym["name"].bytes
end = name.find(b"\x00")
if end != -1:
name = name[:end]
return name.decode()
def list_ksyms():
if not (constants.LX_CONFIG_BPF and constants.LX_CONFIG_BPF_JIT):
return []
bpf_kallsyms = gdb.parse_and_eval("&bpf_kallsyms")
bpf_ksym_ptr_type = bpf_ksym_type.get_type().pointer()
return list(lists.list_for_each_entry(bpf_kallsyms,
bpf_ksym_ptr_type,
"lnode"))
class KsymAddBreakpoint(gdb.Breakpoint):
def __init__(self, monitor):
super(KsymAddBreakpoint, self).__init__("bpf_ksym_add", internal=True)
self.silent = True
self.monitor = monitor
def stop(self):
self.monitor.add(gdb.parse_and_eval("ksym"))
return False
class KsymRemoveBreakpoint(gdb.Breakpoint):
def __init__(self, monitor):
super(KsymRemoveBreakpoint, self).__init__("bpf_ksym_del",
internal=True)
self.silent = True
self.monitor = monitor
def stop(self):
self.monitor.remove(gdb.parse_and_eval("ksym"))
return False
class KsymMonitor:
def __init__(self, add, remove):
self.add = add
self.remove = remove
self.add_bp = KsymAddBreakpoint(self)
self.remove_bp = KsymRemoveBreakpoint(self)
self.notify_initial()
def notify_initial(self):
for ksym in list_ksyms():
Annotation
- Atlas domain: Support Tooling And Documentation / scripts.
- Implementation status: atlas-only.
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.