mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Implement bpf chunk ID
This commit is contained in:
@ -1,10 +1,11 @@
|
|||||||
from pythonbpf.decorators import section
|
from pythonbpf.decorators import bpf, section
|
||||||
# from pythonbpf.decorators import tracepoint, syscalls
|
# from pythonbpf.decorators import tracepoint, syscalls
|
||||||
from ctypes import c_void_p, c_int32
|
from ctypes import c_void_p, c_int32
|
||||||
|
|
||||||
# @tracepoint(syscalls.sys_enter_execve)
|
# @tracepoint(syscalls.sys_enter_execve)
|
||||||
|
|
||||||
|
|
||||||
|
@bpf
|
||||||
@section("kprobe/sys_clone")
|
@section("kprobe/sys_clone")
|
||||||
def hello(ctx: c_void_p) -> c_int32:
|
def hello(ctx: c_void_p) -> c_int32:
|
||||||
print("Hello, World!")
|
print("Hello, World!")
|
||||||
|
|||||||
@ -6,10 +6,26 @@ from .constants_pass import constants_processing
|
|||||||
from .globals_pass import globals_processing
|
from .globals_pass import globals_processing
|
||||||
|
|
||||||
|
|
||||||
|
def find_bpf_chunks(tree):
|
||||||
|
"""Find all functions decorated with @bpf in the AST."""
|
||||||
|
bpf_functions = []
|
||||||
|
for node in ast.walk(tree):
|
||||||
|
if isinstance(node, ast.FunctionDef):
|
||||||
|
for decorator in node.decorator_list:
|
||||||
|
if isinstance(decorator, ast.Name) and decorator.id == "bpf":
|
||||||
|
bpf_functions.append(node)
|
||||||
|
break
|
||||||
|
return bpf_functions
|
||||||
|
|
||||||
|
|
||||||
def processor(source_code, filename, module):
|
def processor(source_code, filename, module):
|
||||||
tree = ast.parse(source_code, filename)
|
tree = ast.parse(source_code, filename)
|
||||||
print(ast.dump(tree, indent=4))
|
print(ast.dump(tree, indent=4))
|
||||||
|
|
||||||
|
bpf_chunks = find_bpf_chunks(tree)
|
||||||
|
for func_node in bpf_chunks:
|
||||||
|
print(f"Found BPF function: {func_node.name}")
|
||||||
|
|
||||||
# For now, we will parse the BPF specific parts of AST
|
# For now, we will parse the BPF specific parts of AST
|
||||||
# Big rewrite
|
# Big rewrite
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user