mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
complete part of expr passing for attribute of i64 type
This commit is contained in:
@ -72,20 +72,23 @@ def _handle_attribute_expr(
|
|||||||
if var_name in local_sym_tab:
|
if var_name in local_sym_tab:
|
||||||
var_ptr, var_type, var_metadata = local_sym_tab[var_name]
|
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"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]
|
metadata = structs_sym_tab[var_metadata]
|
||||||
if attr_name in metadata.fields:
|
if 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)
|
||||||
return val, field_type
|
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
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -87,17 +87,15 @@ class VmlinuxHandler:
|
|||||||
self, struct_var_name, field_name, module, builder, local_sym_tab
|
self, struct_var_name, field_name, module, builder, local_sym_tab
|
||||||
):
|
):
|
||||||
"""Handle access to vmlinux struct fields"""
|
"""Handle access to vmlinux struct fields"""
|
||||||
# Check if it's a variable of vmlinux struct type
|
|
||||||
if struct_var_name in local_sym_tab:
|
if struct_var_name in local_sym_tab:
|
||||||
var_info = local_sym_tab[struct_var_name] # noqa: F841
|
var_info = local_sym_tab[struct_var_name]
|
||||||
# Need to check if this variable is a vmlinux struct
|
|
||||||
# This will depend on how you track vmlinux struct types in your symbol table
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Attempting to access field {field_name} of possible vmlinux struct {struct_var_name}"
|
f"Attempting to access field {field_name} of possible vmlinux struct {struct_var_name}"
|
||||||
)
|
)
|
||||||
# Return pointer to field and field type
|
# Return pointer to field and field type
|
||||||
return None
|
return None
|
||||||
return None
|
else:
|
||||||
|
raise RuntimeError("Variable accessed not found in symbol table")
|
||||||
|
|
||||||
def has_field(self, struct_name, field_name):
|
def has_field(self, struct_name, field_name):
|
||||||
"""Check if a vmlinux struct has a specific field"""
|
"""Check if a vmlinux struct has a specific field"""
|
||||||
|
|||||||
Reference in New Issue
Block a user