From: Vicent Marti Date: Wed, 30 Mar 2016 15:31:19 +0000 (+0200) Subject: bpf.lua: Add support for CFLAGS and LLVM debug flags X-Git-Tag: v0.2.0~128^2~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e7893607c904b2ee7bb7ab111adb32f0bb730e3c;p=platform%2Fupstream%2Fbcc.git bpf.lua: Add support for CFLAGS and LLVM debug flags --- diff --git a/examples/lua/bashreadline.lua b/examples/lua/bashreadline.lua index fc074dc..a66c630 100644 --- a/examples/lua/bashreadline.lua +++ b/examples/lua/bashreadline.lua @@ -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) diff --git a/examples/lua/memleak.lua b/examples/lua/memleak.lua index ba45a6f..1b30592 100644 --- a/examples/lua/memleak.lua +++ b/examples/lua/memleak.lua @@ -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 diff --git a/examples/lua/strlen_count.lua b/examples/lua/strlen_count.lua index d80f279..fde6976 100644 --- a/examples/lua/strlen_count.lua +++ b/examples/lua/strlen_count.lua @@ -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() diff --git a/examples/lua/task_switch.lua b/examples/lua/task_switch.lua index 3391f3d..d7f1c83 100644 --- a/examples/lua/task_switch.lua +++ b/examples/lua/task_switch.lua @@ -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...") diff --git a/src/lua/bcc/bpf.lua b/src/lua/bcc/bpf.lua index d543bd0..3c301ed 100644 --- a/src/lua/bcc/bpf.lua +++ b/src/lua/bcc/bpf.lua @@ -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 diff --git a/src/lua/bcc/vendor/helpers.lua b/src/lua/bcc/vendor/helpers.lua index 11ec647..126e3f2 100644 --- a/src/lua/bcc/vendor/helpers.lua +++ b/src/lua/bcc/vendor/helpers.lua @@ -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 = {}