From: Brenden Blanco Date: Wed, 16 Sep 2015 21:06:06 +0000 (-0700) Subject: Fix probe reads on char[] types X-Git-Tag: v0.1.7~25^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9518e747874172a8897afd3693bab2ec925a920e;p=platform%2Fupstream%2Fbcc.git Fix probe reads on char[] types It is easy enough to wrap the type in a typeof(), otherwise the rewriter would need to do a deeper parsing of the type information to place it properly next to the variable name. Fixes: #219 Signed-off-by: Brenden Blanco --- diff --git a/src/cc/frontends/clang/b_frontend_action.cc b/src/cc/frontends/clang/b_frontend_action.cc index d6bf50e..eb0406d 100644 --- a/src/cc/frontends/clang/b_frontend_action.cc +++ b/src/cc/frontends/clang/b_frontend_action.cc @@ -304,7 +304,7 @@ bool BTypeVisitor::VisitMemberExpr(MemberExpr *E) { string rhs = rewriter_.getRewrittenText(SourceRange(rhs_start, E->getLocEnd())); string base_type = base->getType()->getPointeeType().getAsString(); string pre, post; - pre = "({ " + E->getType().getAsString() + " _val; memset(&_val, 0, sizeof(_val));"; + pre = "({ typeof(" + E->getType().getAsString() + ") _val; memset(&_val, 0, sizeof(_val));"; pre += " bpf_probe_read(&_val, sizeof(_val), (u64)"; post = " + offsetof(" + base_type + ", " + rhs + ")"; post += "); _val; })"; diff --git a/tests/cc/test_clang.py b/tests/cc/test_clang.py index 4cb4958..a62f80d 100755 --- a/tests/cc/test_clang.py +++ b/tests/cc/test_clang.py @@ -165,5 +165,12 @@ int trace_entry(struct pt_regs *ctx, struct file *file) { b = BPF(text=text, debug=0) fn = b.load_func("trace_entry", BPF.KPROBE) + def test_char_array_probe(self): + BPF(text="""#include +int kprobe__blk_update_request(struct pt_regs *ctx, struct request *req) { + bpf_trace_printk("%s\\n", req->rq_disk->disk_name); + return 0; +}""") + if __name__ == "__main__": main()