Skip to content

Commit 4e01df7

Browse files
complete part of expr passing for attribute of i64 type
1 parent 64674cf commit 4e01df7

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

pythonbpf/expr/expr_pass.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,23 @@ def _handle_attribute_expr(
7272
if var_name in local_sym_tab:
7373
var_ptr, var_type, var_metadata = local_sym_tab[var_name]
7474
logger.info(f"Loading attribute {attr_name} from variable {var_name}")
75-
logger.info(f"Variable type: {var_type}, Variable ptr: {var_ptr}")
75+
logger.info(f"Variable type: {var_type}, Variable ptr: {var_ptr}, Variable Metadata: {var_metadata}")
76+
if hasattr(var_metadata, "__module__") and var_metadata.__module__ == "vmlinux":
77+
# Try vmlinux handler when var_metadata is not a string, but has a module attribute.
78+
# This has been done to keep everything separate in vmlinux struct handling.
79+
vmlinux_result = VmlinuxHandlerRegistry.handle_attribute(
80+
expr, local_sym_tab, None, builder
81+
)
82+
if vmlinux_result is not None:
83+
return vmlinux_result
84+
else:
85+
raise RuntimeError("Vmlinux struct did not process successfully")
7686
metadata = structs_sym_tab[var_metadata]
7787
if attr_name in metadata.fields:
7888
gep = metadata.gep(builder, var_ptr, attr_name)
7989
val = builder.load(gep)
8090
field_type = metadata.field_type(attr_name)
8191
return val, field_type
82-
83-
# Try vmlinux handler as fallback
84-
vmlinux_result = VmlinuxHandlerRegistry.handle_attribute(
85-
expr, local_sym_tab, None, builder
86-
)
87-
if vmlinux_result is not None:
88-
return vmlinux_result
8992
return None
9093

9194

pythonbpf/vmlinux_parser/vmlinux_exports_handler.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,15 @@ def handle_vmlinux_struct_field(
8787
self, struct_var_name, field_name, module, builder, local_sym_tab
8888
):
8989
"""Handle access to vmlinux struct fields"""
90-
# Check if it's a variable of vmlinux struct type
9190
if struct_var_name in local_sym_tab:
92-
var_info = local_sym_tab[struct_var_name] # noqa: F841
93-
# Need to check if this variable is a vmlinux struct
94-
# This will depend on how you track vmlinux struct types in your symbol table
91+
var_info = local_sym_tab[struct_var_name]
9592
logger.info(
9693
f"Attempting to access field {field_name} of possible vmlinux struct {struct_var_name}"
9794
)
9895
# Return pointer to field and field type
9996
return None
100-
return None
97+
else:
98+
raise RuntimeError("Variable accessed not found in symbol table")
10199

102100
def has_field(self, struct_name, field_name):
103101
"""Check if a vmlinux struct has a specific field"""

0 commit comments

Comments
 (0)