Skip to content

Commit f2bc7f1

Browse files
pass context to memory allocation
1 parent b3921c4 commit f2bc7f1

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pythonbpf/functions/functions_pass.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -330,18 +330,6 @@ def process_func_body(
330330

331331
local_sym_tab = {}
332332

333-
# pre-allocate dynamic variables
334-
local_sym_tab = allocate_mem(
335-
module,
336-
builder,
337-
func_node.body,
338-
func,
339-
ret_type,
340-
map_sym_tab,
341-
local_sym_tab,
342-
structs_sym_tab,
343-
)
344-
345333
# Add the context parameter (first function argument) to the local symbol table
346334
if func_node.args.args and len(func_node.args.args) > 0:
347335
context_arg = func_node.args.args[0]
@@ -371,6 +359,18 @@ def process_func_body(
371359
local_sym_tab[context_name] = context_type
372360
logger.info(f"Added argument '{context_name}' to local symbol table")
373361

362+
# pre-allocate dynamic variables
363+
local_sym_tab = allocate_mem(
364+
module,
365+
builder,
366+
func_node.body,
367+
func,
368+
ret_type,
369+
map_sym_tab,
370+
local_sym_tab,
371+
structs_sym_tab,
372+
)
373+
374374
logger.info(f"Local symbol table: {local_sym_tab.keys()}")
375375

376376
for stmt in func_node.body:

tests/failing_tests/vmlinux/struct_field_access.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
@section("tracepoint/syscalls/sys_enter_execve")
1616
def hello_world(ctx: struct_trace_event_raw_sys_enter) -> c_int64:
1717
a = 2 + TASK_COMM_LEN + TASK_COMM_LEN
18-
# b = ctx
18+
b = ctx.id
1919
print(f"Hello, World{TASK_COMM_LEN} and {a}")
20-
# print(f"This is context field {b}")
20+
print(f"This is context field {b}")
2121
return c_int64(TASK_COMM_LEN + 2)
2222

2323

0 commit comments

Comments
 (0)