Skip to content

Commit 253944a

Browse files
authored
Merge pull request #18 from pythonbpf/fix-maps
Fix map calling convention
2 parents 62ca3b5 + 54993ce commit 253944a

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

examples/sys_sync.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ def last() -> HashMap:
2121
@section("tracepoint/syscalls/sys_enter_sync")
2222
def do_trace(ctx: c_void_p) -> c_int64:
2323
key = 0
24-
tsp = last().lookup(key)
24+
tsp = last.lookup(key)
2525
if tsp:
2626
kt = ktime()
2727
delta = kt - tsp
2828
if delta < 1000000000:
2929
time_ms = delta // 1000000
3030
print(f"sync called within last second, last {time_ms} ms ago")
31-
last().delete(key)
31+
last.delete(key)
3232
else:
3333
kt = ktime()
34-
last().update(key, kt)
34+
last.update(key, kt)
3535
return c_int64(0)
3636

3737

pythonbpf/functions_pass.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,23 @@ def handle_assign(
192192
elif isinstance(rval.func, ast.Attribute):
193193
logger.info(f"Assignment call attribute: {ast.dump(rval.func)}")
194194
if isinstance(rval.func.value, ast.Name):
195-
# TODO: probably a struct access
196-
logger.info(f"TODO STRUCT ACCESS {ast.dump(rval)}")
195+
if rval.func.value.id in map_sym_tab:
196+
map_name = rval.func.value.id
197+
method_name = rval.func.attr
198+
if HelperHandlerRegistry.has_handler(method_name):
199+
val = handle_helper_call(
200+
rval,
201+
module,
202+
builder,
203+
func,
204+
local_sym_tab,
205+
map_sym_tab,
206+
structs_sym_tab,
207+
)
208+
builder.store(val[0], local_sym_tab[var_name].var)
209+
else:
210+
# TODO: probably a struct access
211+
logger.info(f"TODO STRUCT ACCESS {ast.dump(rval)}")
197212
elif isinstance(rval.func.value, ast.Call) and isinstance(
198213
rval.func.value.func, ast.Name
199214
):

0 commit comments

Comments
 (0)