diff --git a/pythonbpf/codegen.py b/pythonbpf/codegen.py index e3fa5d3..e97b194 100644 --- a/pythonbpf/codegen.py +++ b/pythonbpf/codegen.py @@ -67,7 +67,7 @@ def processor(source_code, filename, module): globals_processing(tree, module) structs_sym_tab = structs_proc(tree, module, bpf_chunks) map_sym_tab = maps_proc(tree, module, bpf_chunks) - func_proc(tree, module, bpf_chunks, map_sym_tab, structs_sym_tab, vmlinux_symtab) + func_proc(tree, module, bpf_chunks, map_sym_tab, structs_sym_tab) globals_list_creation(tree, module) diff --git a/pythonbpf/expr/expr_pass.py b/pythonbpf/expr/expr_pass.py index 281d3a1..5e1163a 100644 --- a/pythonbpf/expr/expr_pass.py +++ b/pythonbpf/expr/expr_pass.py @@ -142,7 +142,12 @@ def get_operand_value( logger.info(f"var is {var}, base_type is {base_type}, depth is {depth}") val = deref_to_depth(func, builder, var, depth) return val - raise ValueError(f"Undefined variable: {operand.id}") + else: + # Check if it's a vmlinux enum/constant + vmlinux_result = VmlinuxHandlerRegistry.handle_name(operand.id) + if vmlinux_result is not None: + val, _ = vmlinux_result + return val elif isinstance(operand, ast.Constant): if isinstance(operand.value, int): cst = ir.Constant(ir.IntType(64), int(operand.value)) diff --git a/tests/passing_tests/vmlinux/simple_struct_test.py b/tests/passing_tests/vmlinux/simple_struct_test.py index c784696..6507725 100644 --- a/tests/passing_tests/vmlinux/simple_struct_test.py +++ b/tests/passing_tests/vmlinux/simple_struct_test.py @@ -1,4 +1,4 @@ -from pythonbpf import bpf, section, bpfglobal, compile_to_ir +from pythonbpf import bpf, section, bpfglobal, compile_to_ir, compile from vmlinux import TASK_COMM_LEN # noqa: F401 from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401 @@ -16,7 +16,8 @@ from ctypes import c_int64 @bpf @section("tracepoint/syscalls/sys_enter_execve") def hello_world(ctx: struct_trace_event_raw_sys_enter) -> c_int64: - print("Hello, World") + a = 2 + TASK_COMM_LEN + TASK_COMM_LEN + print(f"Hello, World{a}") return c_int64(TASK_COMM_LEN) @@ -27,3 +28,4 @@ def LICENSE() -> str: compile_to_ir("simple_struct_test.py", "simple_struct_test.ll") +compile()