Commit e7893607 authored by Vicent Marti's avatar Vicent Marti

bpf.lua: Add support for CFLAGS and LLVM debug flags

parent a978401e
......@@ -16,7 +16,7 @@ limitations under the License.
local ffi = require("ffi")
return function(BPF)
local b = BPF:new{src_file="bashreadline.c", debug=true}
local b = BPF:new{src_file="bashreadline.c", debug=0}
b:attach_uprobe{name="/bin/bash", sym="readline", fn_name="printret", retprobe=true}
local function print_readline(cpu, event)
......
......@@ -123,7 +123,7 @@ return function(BPF, utils)
text = text:gsub("SHOULD_PRINT", args.trace and "1" or "0")
text = text:gsub("SAMPLE_EVERY_N", tostring(args.sample_rate))
local bpf = BPF:new{text=text, debug=true}
local bpf = BPF:new{text=text, debug=0}
local syms = nil
local min_age_ns = args.older * 1e6
......
......@@ -32,7 +32,7 @@ int printarg(struct pt_regs *ctx) {
]], "PID", arg[1])
return function(BPF)
local b = BPF:new{text=program, debug=true}
local b = BPF:new{text=program, debug=0}
b:attach_uprobe{name="c", sym="strlen", fn_name="printarg"}
local pipe = b:pipe()
......
......@@ -38,7 +38,7 @@ int count_sched(struct pt_regs *ctx, struct task_struct *prev) {
]]
return function(BPF)
local b = BPF:new{text=program, debug=true}
local b = BPF:new{text=program, debug=0}
b:attach_kprobe{event="finish_task_switch", fn_name="count_sched"}
print("Press any key...")
......
......@@ -27,6 +27,11 @@ Bpf.static.open_uprobes = {}
Bpf.static.process_symbols = {}
Bpf.static.KPROBE_LIMIT = 1000
Bpf.static.tracer_pipe = nil
Bpf.static.DEFAULT_CFLAGS = {
'-D__HAVE_BUILTIN_BSWAP16__',
'-D__HAVE_BUILTIN_BSWAP32__',
'-D__HAVE_BUILTIN_BSWAP64__',
}
function Bpf.static.check_probe_quota(n)
local cur = table.count(Bpf.static.open_kprobes) + table.count(Bpf.static.open_uprobes)
......@@ -101,17 +106,23 @@ function Bpf:initialize(args)
self.funcs = {}
self.tables = {}
local cflags = table.join(Bpf.DEFAULT_CFLAGS, args.cflags)
local cflags_ary = ffi.new("const char *[?]", #cflags, cflags)
local llvm_debug = args.debug or 0
assert(type(llvm_debug) == "number")
if args.text then
log.info("\n%s\n", args.text)
self.module = libbcc.bpf_module_create_c_from_string(args.text, args.llvm_debug or 0, nil, 0)
self.module = libbcc.bpf_module_create_c_from_string(args.text, llvm_debug, cflags_ary, #cflags)
elseif args.src_file then
local src = _find_file(Bpf.SCRIPT_ROOT, args.src_file)
if src:ends(".b") then
local hdr = _find_file(Bpf.SCRIPT_ROOT, args.hdr_file)
self.module = libbcc.bpf_module_create_b(src, hdr, args.llvm_debug or 0)
self.module = libbcc.bpf_module_create_b(src, hdr, llvm_debug)
else
self.module = libbcc.bpf_module_create_c(src, args.llvm_debug or 0, nil, 0)
self.module = libbcc.bpf_module_create_c(src, llvm_debug, cflags_ary, #cflags)
end
end
......
......@@ -65,6 +65,22 @@ function table.bsearch(list, value, mkval)
return nil
end
function table.join(a, b)
assert(a)
if b == nil or #b == 0 then
return a
end
local res = {}
for _, v in ipairs(a) do
table.insert(res, v)
end
for _, v in ipairs(b) do
table.insert(res, v)
end
return res
end
function table.build(iterator_fn, build_fn)
build_fn = (build_fn or function(arg) return arg end)
local res = {}
......
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