mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
field check in allocation pass
This commit is contained in:
@ -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)
|
VmlinuxHandlerRegistry.get_field_type(vmlinux_struct_name, field_name)
|
||||||
)
|
)
|
||||||
field_ir, field = field_type
|
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
|
# Determine the actual IR type based on the field's type
|
||||||
actual_ir_type = None
|
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)
|
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)
|
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(
|
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
|
return
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -14,6 +14,7 @@ from .type_normalization import (
|
|||||||
)
|
)
|
||||||
from pythonbpf.vmlinux_parser.assignment_info import Field
|
from pythonbpf.vmlinux_parser.assignment_info import Field
|
||||||
from .vmlinux_registry import VmlinuxHandlerRegistry
|
from .vmlinux_registry import VmlinuxHandlerRegistry
|
||||||
|
from ..vmlinux_parser.dependency_node import Field
|
||||||
|
|
||||||
logger: Logger = logging.getLogger(__name__)
|
logger: Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -89,8 +90,16 @@ def _handle_attribute_expr(
|
|||||||
return vmlinux_result
|
return vmlinux_result
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Vmlinux struct did not process successfully")
|
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)
|
gep = metadata.gep(builder, var_ptr, attr_name)
|
||||||
val = builder.load(gep)
|
val = builder.load(gep)
|
||||||
field_type = metadata.field_type(attr_name)
|
field_type = metadata.field_type(attr_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user