Skip to content

Commit caa5d92

Browse files
committed
Fix struct_access in eval_expr, move struct_access conditional test to passing
1 parent f41693b commit caa5d92

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

pythonbpf/expr_pass.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def _handle_attribute_expr(
4343
var_ptr, var_type, var_metadata = local_sym_tab[var_name]
4444
logger.info(f"Loading attribute {attr_name} from variable {var_name}")
4545
logger.info(f"Variable type: {var_type}, Variable ptr: {var_ptr}")
46-
4746
metadata = structs_sym_tab[var_metadata]
4847
if attr_name in metadata.fields:
4948
gep = metadata.gep(builder, var_ptr, attr_name)

pythonbpf/functions/functions_pass.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,13 @@ def handle_assign(
240240
logger.info("Unsupported assignment value type")
241241

242242

243-
def handle_cond(func, module, builder, cond, local_sym_tab, map_sym_tab):
243+
def handle_cond(
244+
func, module, builder, cond, local_sym_tab, map_sym_tab, structs_sym_tab=None
245+
):
244246
if True:
245-
val = eval_expr(func, module, builder, cond, local_sym_tab, map_sym_tab)[0]
247+
val = eval_expr(
248+
func, module, builder, cond, local_sym_tab, map_sym_tab, structs_sym_tab
249+
)[0]
246250
return convert_to_bool(builder, val)
247251
if isinstance(cond, ast.Constant):
248252
if isinstance(cond.value, bool) or isinstance(cond.value, int):
@@ -321,7 +325,9 @@ def handle_if(
321325
else:
322326
else_block = None
323327

324-
cond = handle_cond(func, module, builder, stmt.test, local_sym_tab, map_sym_tab)
328+
cond = handle_cond(
329+
func, module, builder, stmt.test, local_sym_tab, map_sym_tab, structs_sym_tab
330+
)
325331
if else_block:
326332
builder.cbranch(cond, then_block, else_block)
327333
else:

tests/failing_tests/conditionals/struct_access.py renamed to tests/passing_tests/conditionals/struct_access.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class data_t:
1313
@section("tracepoint/syscalls/sys_enter_execve")
1414
def hello_world(ctx: c_void_p) -> c_int64:
1515
dat = data_t()
16-
if dat.pid:
16+
if dat.ts:
1717
print("Hello, World!")
1818
else:
1919
print("Goodbye, World!")

0 commit comments

Comments
 (0)