mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Fix struct_access in eval_expr, move struct_access conditional test to passing
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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!")
|
||||
Reference in New Issue
Block a user