Skip to content

Commit 1e3d775

Browse files
handle non-complex types along with recursion
1 parent 168e262 commit 1e3d775

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pythonbpf/vmlinux_parser/vmlinux_class_handler.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ def get_module_symbols(module_name: str):
1616
# Recursive function that gets all the dependent classes and adds them to handler
1717
def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
1818
symbols_in_module, imported_module = get_module_symbols("vmlinux")
19-
current_symbol_name = node.name
19+
20+
# Handle both node objects and type objects
21+
if hasattr(node, 'name'):
22+
current_symbol_name = node.name
23+
elif hasattr(node, '__name__'):
24+
current_symbol_name = node.__name__
25+
else:
26+
current_symbol_name = str(node)
27+
2028
if current_symbol_name not in symbols_in_module:
2129
raise ImportError(f"{current_symbol_name} not present in module vmlinux")
2230
logger.info(f"Resolving vmlinux class {current_symbol_name}")
@@ -43,7 +51,7 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
4351
else:
4452
raise TypeError("Could not get required class and definition")
4553

46-
logger.info(f"Extracted fields for {current_symbol_name}: {field_table}")
54+
logger.debug(f"Extracted fields for {current_symbol_name}: {field_table}")
4755
if handler.has_node(current_symbol_name):
4856
logger.info("Extraction pruned due to already available field")
4957
return True
@@ -55,7 +63,9 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
5563
new_dep_node.add_field(elem_name, elem_type, ready=True)
5664
elif module_name == "vmlinux":
5765
new_dep_node.add_field(elem_name, elem_type, ready=False)
58-
if process_vmlinux_class(elem_type, llvm_module, handler):
66+
# Create a temporary node-like object for recursion
67+
temp_node = type('TempNode', (), {'name': elem_type.__name__ if hasattr(elem_type, '__name__') else str(elem_type)})()
68+
if process_vmlinux_class(temp_node, llvm_module, handler):
5969
new_dep_node.set_field_ready(elem_name, True)
6070
else:
6171
print(f"[other] {elem_name} -> {elem_type}")

tests/failing_tests/xdp_pass.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pythonbpf.maps import HashMap
33
from pythonbpf.helper import XDP_PASS
44
from vmlinux import struct_xdp_md
5+
# from vmlinux import struct_ring_buffer_per_cpu
56
from ctypes import c_int64
67

78
# Instructions to how to run this program

0 commit comments

Comments
 (0)