From c6b5ecb47efa4e76b0febd0d7933a016aa3f6805 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Fri, 24 Oct 2025 03:34:17 +0530 Subject: [PATCH] find global variable ir and field data from metadata --- pythonbpf/functions/functions_pass.py | 4 +--- pythonbpf/vmlinux_parser/vmlinux_exports_handler.py | 7 +++++-- tests/failing_tests/vmlinux/struct_field_access.py | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 1cf3577..3aff061 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -348,9 +348,7 @@ def process_func_body( resolved_type = VmlinuxHandlerRegistry.get_struct_type( context_type_name ) - context_type = LocalSymbol( - None, ir.PointerType(resolved_type), resolved_type - ) + context_type = LocalSymbol(None, None, resolved_type) local_sym_tab[context_name] = context_type logger.info(f"Added argument '{context_name}' to local symbol table") diff --git a/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py b/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py index 4a78316..46dfbed 100644 --- a/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py +++ b/pythonbpf/vmlinux_parser/vmlinux_exports_handler.py @@ -93,8 +93,11 @@ class VmlinuxHandler: logger.info( f"Attempting to access field {field_name} of possible vmlinux struct {struct_var_name}" ) - print(var_info.ir_type) - print(self.get_field_type(struct_var_name, field_name)) + python_type: type = var_info.metadata + globvar_ir, field_data = self.get_field_type( + python_type.__name__, field_name + ) + # Return pointer to field and field type return None else: diff --git a/tests/failing_tests/vmlinux/struct_field_access.py b/tests/failing_tests/vmlinux/struct_field_access.py index 1d6e85e..4ff90c2 100644 --- a/tests/failing_tests/vmlinux/struct_field_access.py +++ b/tests/failing_tests/vmlinux/struct_field_access.py @@ -17,7 +17,7 @@ def hello_world(ctx: struct_trace_event_raw_sys_enter) -> c_int64: a = 2 + TASK_COMM_LEN + TASK_COMM_LEN b = ctx.id print(f"Hello, World{TASK_COMM_LEN} and {a}") - # print(f"This is context field {b}") + print(f"This is context field {b}") return c_int64(TASK_COMM_LEN + 2)