From 4e01df735f35c9de2717df61099b845fd227f7ad Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Fri, 24 Oct 2025 02:38:39 +0530 Subject: [PATCH] complete part of expr passing for attribute of i64 type --- pythonbpf/expr/expr_pass.py | 19 +++++++++++-------- .../vmlinux_parser/vmlinux_exports_handler.py | 8 +++----- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pythonbpf/expr/expr_pass.py b/pythonbpf/expr/expr_pass.py index 2a7cd5f..a17b48f 100644 --- a/pythonbpf/expr/expr_pass.py +++ b/pythonbpf/expr/expr_pass.py @@ -72,20 +72,23 @@ def _handle_attribute_expr( if var_name in local_sym_tab: var_ptr, var_type, var_metadata = local_sym_tab[var_name] logger.info(f"Loading attribute {attr_name} from variable {var_name}") - logger.info(f"Variable type: {var_type}, Variable ptr: {var_ptr}") + logger.info(f"Variable type: {var_type}, Variable ptr: {var_ptr}, Variable Metadata: {var_metadata}") + if hasattr(var_metadata, "__module__") and var_metadata.__module__ == "vmlinux": + # Try vmlinux handler when var_metadata is not a string, but has a module attribute. + # This has been done to keep everything separate in vmlinux struct handling. + vmlinux_result = VmlinuxHandlerRegistry.handle_attribute( + expr, local_sym_tab, None, builder + ) + if vmlinux_result is not None: + return vmlinux_result + else: + raise RuntimeError("Vmlinux struct did not process successfully") metadata = structs_sym_tab[var_metadata] if attr_name in metadata.fields: gep = metadata.gep(builder, var_ptr, attr_name) val = builder.load(gep) field_type = metadata.field_type(attr_name) return val, field_type - - # Try vmlinux handler as fallback - vmlinux_result = VmlinuxHandlerRegistry.handle_attribute( - expr, local_sym_tab, None, builder - ) - if vmlinux_result is not None: - return vmlinux_result return None diff --git a/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py b/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py index f68822a..3f65506 100644 --- a/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py +++ b/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py @@ -87,17 +87,15 @@ class VmlinuxHandler: self, struct_var_name, field_name, module, builder, local_sym_tab ): """Handle access to vmlinux struct fields""" - # Check if it's a variable of vmlinux struct type if struct_var_name in local_sym_tab: - var_info = local_sym_tab[struct_var_name] # noqa: F841 - # Need to check if this variable is a vmlinux struct - # This will depend on how you track vmlinux struct types in your symbol table + var_info = local_sym_tab[struct_var_name] logger.info( f"Attempting to access field {field_name} of possible vmlinux struct {struct_var_name}" ) # Return pointer to field and field type return None - return None + else: + raise RuntimeError("Variable accessed not found in symbol table") def has_field(self, struct_name, field_name): """Check if a vmlinux struct has a specific field"""