mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
handle non-complex types along with recursion
This commit is contained in:
@ -16,7 +16,15 @@ def get_module_symbols(module_name: str):
|
|||||||
# Recursive function that gets all the dependent classes and adds them to handler
|
# Recursive function that gets all the dependent classes and adds them to handler
|
||||||
def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
|
def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
|
||||||
symbols_in_module, imported_module = get_module_symbols("vmlinux")
|
symbols_in_module, imported_module = get_module_symbols("vmlinux")
|
||||||
current_symbol_name = node.name
|
|
||||||
|
# Handle both node objects and type objects
|
||||||
|
if hasattr(node, 'name'):
|
||||||
|
current_symbol_name = node.name
|
||||||
|
elif hasattr(node, '__name__'):
|
||||||
|
current_symbol_name = node.__name__
|
||||||
|
else:
|
||||||
|
current_symbol_name = str(node)
|
||||||
|
|
||||||
if current_symbol_name not in symbols_in_module:
|
if current_symbol_name not in symbols_in_module:
|
||||||
raise ImportError(f"{current_symbol_name} not present in module vmlinux")
|
raise ImportError(f"{current_symbol_name} not present in module vmlinux")
|
||||||
logger.info(f"Resolving vmlinux class {current_symbol_name}")
|
logger.info(f"Resolving vmlinux class {current_symbol_name}")
|
||||||
@ -43,7 +51,7 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
|
|||||||
else:
|
else:
|
||||||
raise TypeError("Could not get required class and definition")
|
raise TypeError("Could not get required class and definition")
|
||||||
|
|
||||||
logger.info(f"Extracted fields for {current_symbol_name}: {field_table}")
|
logger.debug(f"Extracted fields for {current_symbol_name}: {field_table}")
|
||||||
if handler.has_node(current_symbol_name):
|
if handler.has_node(current_symbol_name):
|
||||||
logger.info("Extraction pruned due to already available field")
|
logger.info("Extraction pruned due to already available field")
|
||||||
return True
|
return True
|
||||||
@ -55,7 +63,9 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
|
|||||||
new_dep_node.add_field(elem_name, elem_type, ready=True)
|
new_dep_node.add_field(elem_name, elem_type, ready=True)
|
||||||
elif module_name == "vmlinux":
|
elif module_name == "vmlinux":
|
||||||
new_dep_node.add_field(elem_name, elem_type, ready=False)
|
new_dep_node.add_field(elem_name, elem_type, ready=False)
|
||||||
if process_vmlinux_class(elem_type, llvm_module, handler):
|
# Create a temporary node-like object for recursion
|
||||||
|
temp_node = type('TempNode', (), {'name': elem_type.__name__ if hasattr(elem_type, '__name__') else str(elem_type)})()
|
||||||
|
if process_vmlinux_class(temp_node, llvm_module, handler):
|
||||||
new_dep_node.set_field_ready(elem_name, True)
|
new_dep_node.set_field_ready(elem_name, True)
|
||||||
else:
|
else:
|
||||||
print(f"[other] {elem_name} -> {elem_type}")
|
print(f"[other] {elem_name} -> {elem_type}")
|
||||||
|
|||||||
@ -2,6 +2,7 @@ from pythonbpf import bpf, map, section, bpfglobal, compile, compile_to_ir
|
|||||||
from pythonbpf.maps import HashMap
|
from pythonbpf.maps import HashMap
|
||||||
from pythonbpf.helper import XDP_PASS
|
from pythonbpf.helper import XDP_PASS
|
||||||
from vmlinux import struct_xdp_md
|
from vmlinux import struct_xdp_md
|
||||||
|
# from vmlinux import struct_ring_buffer_per_cpu
|
||||||
from ctypes import c_int64
|
from ctypes import c_int64
|
||||||
|
|
||||||
# Instructions to how to run this program
|
# Instructions to how to run this program
|
||||||
|
|||||||
Reference in New Issue
Block a user