From 7c559840f025405eeae1976962cbdb441fb95f42 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Sat, 11 Oct 2025 20:02:20 +0530 Subject: [PATCH] add ctype subclass identifier Signed-off-by: varun-r-mallya --- .../vmlinux_parser/vmlinux_class_handler.py | 29 ++++++++++++++++--- tests/failing_tests/xdp_pass.py | 1 - 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pythonbpf/vmlinux_parser/vmlinux_class_handler.py b/pythonbpf/vmlinux_parser/vmlinux_class_handler.py index c31b9d3..dddc458 100644 --- a/pythonbpf/vmlinux_parser/vmlinux_class_handler.py +++ b/pythonbpf/vmlinux_parser/vmlinux_class_handler.py @@ -30,6 +30,7 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler): if current_symbol_name not in symbols_in_module: raise ImportError(f"{current_symbol_name} not present in module vmlinux") logger.info(f"Resolving vmlinux class {current_symbol_name}") + logger.debug(f"Current handler state: {handler.is_ready} readiness and {handler.get_all_nodes()} all nodes") field_table = {} # should contain the field and it's type. # Get the class object from the module @@ -65,13 +66,33 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler): new_dep_node.add_field(elem_name, elem_type, ready=True) elif module_name == "vmlinux": new_dep_node.add_field(elem_name, elem_type, ready=False) - # 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): + print("elem_name:", elem_name, "elem_type:", elem_type) + # currently fails when a non-normal type appears which is basically everytime + identify_ctypes_type(elem_type) + symbol_name = elem_type.__name__ if hasattr(elem_type, '__name__') else str(elem_type) + vmlinux_symbol = getattr(imported_module, symbol_name) + if process_vmlinux_class(vmlinux_symbol, llvm_module, handler): new_dep_node.set_field_ready(elem_name, True) else: raise ValueError(f"{elem_name} with type {elem_type} not supported in recursive resolver") handler.add_node(new_dep_node) + logger.info(f"added node: {current_symbol_name}") return True + +def identify_ctypes_type(t): + if isinstance(t, type): # t is a type/class + if issubclass(t, ctypes.Array): + print("Array type") + print("Element type:", t._type_) + print("Length:", t._length_) + elif issubclass(t, ctypes._Pointer): + print("Pointer type") + print("Points to:", t._type_) + elif issubclass(t, ctypes._SimpleCData): + print("Scalar type") + print("Base type:", t) + else: + print("Other ctypes type") + else: + print("Instance, not type") diff --git a/tests/failing_tests/xdp_pass.py b/tests/failing_tests/xdp_pass.py index 76d1a01..dddce92 100644 --- a/tests/failing_tests/xdp_pass.py +++ b/tests/failing_tests/xdp_pass.py @@ -2,7 +2,6 @@ from pythonbpf import bpf, map, section, bpfglobal, compile, compile_to_ir from pythonbpf.maps import HashMap from pythonbpf.helper import XDP_PASS from vmlinux import struct_xdp_md -# from vmlinux import struct_ring_buffer_per_cpu from ctypes import c_int64 # Instructions to how to run this program