diff --git a/pythonbpf/expr_pass.py b/pythonbpf/expr_pass.py index ca0fbf7..0bccc5b 100644 --- a/pythonbpf/expr_pass.py +++ b/pythonbpf/expr_pass.py @@ -43,7 +43,6 @@ def _handle_attribute_expr( 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"Variable type: {var_type}, Variable ptr: {var_ptr}") - metadata = structs_sym_tab[var_metadata] if attr_name in metadata.fields: gep = metadata.gep(builder, var_ptr, attr_name) diff --git a/pythonbpf/functions/functions_pass.py b/pythonbpf/functions/functions_pass.py index 00cbe75..80fa520 100644 --- a/pythonbpf/functions/functions_pass.py +++ b/pythonbpf/functions/functions_pass.py @@ -240,9 +240,13 @@ def handle_assign( logger.info("Unsupported assignment value type") -def handle_cond(func, module, builder, cond, local_sym_tab, map_sym_tab): +def handle_cond( + func, module, builder, cond, local_sym_tab, map_sym_tab, structs_sym_tab=None +): if True: - val = eval_expr(func, module, builder, cond, local_sym_tab, map_sym_tab)[0] + val = eval_expr( + func, module, builder, cond, local_sym_tab, map_sym_tab, structs_sym_tab + )[0] return convert_to_bool(builder, val) if isinstance(cond, ast.Constant): if isinstance(cond.value, bool) or isinstance(cond.value, int): @@ -321,7 +325,9 @@ def handle_if( else: else_block = None - cond = handle_cond(func, module, builder, stmt.test, local_sym_tab, map_sym_tab) + cond = handle_cond( + func, module, builder, stmt.test, local_sym_tab, map_sym_tab, structs_sym_tab + ) if else_block: builder.cbranch(cond, then_block, else_block) else: diff --git a/tests/failing_tests/conditionals/struct_access.py b/tests/passing_tests/conditionals/struct_access.py similarity index 96% rename from tests/failing_tests/conditionals/struct_access.py rename to tests/passing_tests/conditionals/struct_access.py index bbfbba4..5267290 100644 --- a/tests/failing_tests/conditionals/struct_access.py +++ b/tests/passing_tests/conditionals/struct_access.py @@ -13,7 +13,7 @@ class data_t: @section("tracepoint/syscalls/sys_enter_execve") def hello_world(ctx: c_void_p) -> c_int64: dat = data_t() - if dat.pid: + if dat.ts: print("Hello, World!") else: print("Goodbye, World!")