From f2bc7f1434502c71b6fa477d07b5d708592845c5 Mon Sep 17 00:00:00 2001 From: varun-r-mallya Date: Wed, 22 Oct 2025 12:01:52 +0530 Subject: [PATCH] pass context to memory allocation --- pythonbpf/functions/functions_pass.py | 24 +++++++++---------- .../vmlinux/struct_field_access.py | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 359efe1..b66e04c 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -330,18 +330,6 @@ def process_func_body( local_sym_tab = {} - # pre-allocate dynamic variables - local_sym_tab = allocate_mem( - module, - builder, - func_node.body, - func, - ret_type, - map_sym_tab, - local_sym_tab, - structs_sym_tab, - ) - # Add the context parameter (first function argument) to the local symbol table if func_node.args.args and len(func_node.args.args) > 0: context_arg = func_node.args.args[0] @@ -371,6 +359,18 @@ def process_func_body( local_sym_tab[context_name] = context_type logger.info(f"Added argument '{context_name}' to local symbol table") + # pre-allocate dynamic variables + local_sym_tab = allocate_mem( + module, + builder, + func_node.body, + func, + ret_type, + map_sym_tab, + local_sym_tab, + structs_sym_tab, + ) + logger.info(f"Local symbol table: {local_sym_tab.keys()}") for stmt in func_node.body: diff --git a/tests/failing_tests/vmlinux/struct_field_access.py b/tests/failing_tests/vmlinux/struct_field_access.py index f3db2bf..4ff90c2 100644 --- a/tests/failing_tests/vmlinux/struct_field_access.py +++ b/tests/failing_tests/vmlinux/struct_field_access.py @@ -15,9 +15,9 @@ from ctypes import c_int64, c_void_p # noqa: F401 @section("tracepoint/syscalls/sys_enter_execve") def hello_world(ctx: struct_trace_event_raw_sys_enter) -> c_int64: a = 2 + TASK_COMM_LEN + TASK_COMM_LEN - # b = ctx + 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)