Skip to content

Commit 168e262

Browse files
add recursive addition algorithm with mixing of ast node type and type node which is not right.
Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
1 parent 2cf7b28 commit 168e262

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

pythonbpf/vmlinux_parser/vmlinux_class_handler.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import importlib
55
from .dependency_handler import DependencyHandler
66
from .dependency_node import DependencyNode
7+
import ctypes
78

89
logger = logging.getLogger(__name__)
910

@@ -12,7 +13,8 @@ def get_module_symbols(module_name: str):
1213
imported_module = importlib.import_module(module_name)
1314
return [name for name in dir(imported_module)], imported_module
1415

15-
def process_vmlinux_class(node, llvm_module, handler: DependencyHandler, parent=""):
16+
# Recursive function that gets all the dependent classes and adds them to handler
17+
def process_vmlinux_class(node, llvm_module, handler: DependencyHandler):
1618
symbols_in_module, imported_module = get_module_symbols("vmlinux")
1719
current_symbol_name = node.name
1820
if current_symbol_name not in symbols_in_module:
@@ -28,7 +30,7 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler, parent=
2830

2931
# Inspect the class fields
3032
# Assuming class_obj has fields stored in some standard way
31-
#If it's a ctypes-like structure with _fields_
33+
# If it's a ctypes-like structure with _fields_
3234
if hasattr(class_obj, '_fields_'):
3335
for field_name, field_type in class_obj._fields_:
3436
field_table[field_name] = field_type
@@ -42,5 +44,21 @@ def process_vmlinux_class(node, llvm_module, handler: DependencyHandler, parent=
4244
raise TypeError("Could not get required class and definition")
4345

4446
logger.info(f"Extracted fields for {current_symbol_name}: {field_table}")
45-
return field_table
47+
if handler.has_node(current_symbol_name):
48+
logger.info("Extraction pruned due to already available field")
49+
return True
50+
else:
51+
new_dep_node = DependencyNode(name=current_symbol_name)
52+
for elem_name, elem_type in field_table.items():
53+
module_name = getattr(elem_type, "__module__", None)
54+
if module_name == ctypes.__name__:
55+
new_dep_node.add_field(elem_name, elem_type, ready=True)
56+
elif module_name == "vmlinux":
57+
new_dep_node.add_field(elem_name, elem_type, ready=False)
58+
if process_vmlinux_class(elem_type, llvm_module, handler):
59+
new_dep_node.set_field_ready(elem_name, True)
60+
else:
61+
print(f"[other] {elem_name} -> {elem_type}")
62+
handler.add_node(new_dep_node)
4663

64+
return True

tests/failing_tests/xdp_pass.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from pythonbpf.maps import HashMap
33
from pythonbpf.helper import XDP_PASS
44
from vmlinux import struct_xdp_md
5-
# from vmlinux import XDP_PASS
65
from ctypes import c_int64
76

87
# Instructions to how to run this program

0 commit comments

Comments
 (0)