diff --git a/pythonbpf/allocation_pass.py b/pythonbpf/allocation_pass.py index 31ebf6d..9b45311 100644 --- a/pythonbpf/allocation_pass.py +++ b/pythonbpf/allocation_pass.py @@ -337,13 +337,6 @@ def _allocate_for_attribute(builder, var_name, rval, local_sym_tab, structs_sym_ VmlinuxHandlerRegistry.get_field_type(vmlinux_struct_name, field_name) ) field_ir, field = field_type - # TODO: For now, we only support integer type allocations. - # This always assumes first argument of function to be the context struct - # base_ptr = builder.function.args[0] - # local_sym_tab[ - # struct_var - # ].var = base_ptr # This is repurposing of var to store the pointer of the base type - # local_sym_tab[struct_var].ir_type = field_ir # Determine the actual IR type based on the field's type actual_ir_type = None @@ -398,12 +391,12 @@ def _allocate_for_attribute(builder, var_name, rval, local_sym_tab, structs_sym_ ) actual_ir_type = ir.IntType(64) - # Allocate with the actual IR type, not the GlobalVariable + # Allocate with the actual IR type var = _allocate_with_type(builder, var_name, actual_ir_type) - local_sym_tab[var_name] = LocalSymbol(var, actual_ir_type, field) + local_sym_tab[var_name] = LocalSymbol(var, actual_ir_type, field) # <-- Store Field metadata logger.info( - f"Pre-allocated {var_name} from vmlinux struct {vmlinux_struct_name}.{field_name}" + f"Pre-allocated {var_name} as {actual_ir_type} from vmlinux struct {vmlinux_struct_name}.{field_name}" ) return else: diff --git a/pythonbpf/expr/expr_pass.py b/pythonbpf/expr/expr_pass.py index 3bfb0a7..ee2b9f4 100644 --- a/pythonbpf/expr/expr_pass.py +++ b/pythonbpf/expr/expr_pass.py @@ -14,6 +14,7 @@ from .type_normalization import ( ) from pythonbpf.vmlinux_parser.assignment_info import Field from .vmlinux_registry import VmlinuxHandlerRegistry +from ..vmlinux_parser.dependency_node import Field logger: Logger = logging.getLogger(__name__) @@ -89,8 +90,16 @@ def _handle_attribute_expr( return vmlinux_result else: raise RuntimeError("Vmlinux struct did not process successfully") - metadata = structs_sym_tab[var_metadata] - if attr_name in metadata.fields: + + elif isinstance(var_metadata, Field): + logger.error( + f"Cannot access field '{attr_name}' on already-loaded field value '{var_name}'" + ) + return None + + # Regular user-defined struct + metadata = structs_sym_tab.get(var_metadata) + if metadata and attr_name in metadata.fields: gep = metadata.gep(builder, var_ptr, attr_name) val = builder.load(gep) field_type = metadata.field_type(attr_name)