Commit 81990c32 authored by Vicent Marti's avatar Vicent Marti

bpf.lua: Implement `dump_func`

parent 72d7aa3c
......@@ -157,7 +157,8 @@ function Bpf:load_func(fn_name, prog_type)
return self.funcs[fn_name]
end
assert(libbcc.bpf_function_start(self.module, fn_name), "unknown program: "..fn_name)
assert(libbcc.bpf_function_start(self.module, fn_name) ~= nil,
"unknown program: "..fn_name)
local fd = libbcc.bpf_prog_load(prog_type,
libbcc.bpf_function_start(self.module, fn_name),
......@@ -173,6 +174,14 @@ function Bpf:load_func(fn_name, prog_type)
return fn
end
function Bpf:dump_func(fn_name)
local start = libbcc.bpf_function_start(self.module, fn_name)
assert(start ~= nil, "unknown program")
local len = libbcc.bpf_function_size(self.module, fn_name)
return ffi.string(start, tonumber(len))
end
function Bpf:attach_uprobe(args)
Bpf.check_probe_quota(1)
......
require("test_helper")
function test_dump_func()
local raw = "\xb7\x00\x00\x00\x01\x00\x00\x00\x95\x00\x00\x00\x00\x00\x00\x00"
local b = BPF:new{text=[[int entry(void) { return 1; }]]}
assert_equals(b:dump_func("entry"), raw)
end
os.exit(LuaUnit.run())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment