Commit 9518e747 authored by Brenden Blanco's avatar Brenden Blanco

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: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 2d75aa0d
...@@ -304,7 +304,7 @@ bool BTypeVisitor::VisitMemberExpr(MemberExpr *E) { ...@@ -304,7 +304,7 @@ bool BTypeVisitor::VisitMemberExpr(MemberExpr *E) {
string rhs = rewriter_.getRewrittenText(SourceRange(rhs_start, E->getLocEnd())); string rhs = rewriter_.getRewrittenText(SourceRange(rhs_start, E->getLocEnd()));
string base_type = base->getType()->getPointeeType().getAsString(); string base_type = base->getType()->getPointeeType().getAsString();
string pre, post; 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)"; pre += " bpf_probe_read(&_val, sizeof(_val), (u64)";
post = " + offsetof(" + base_type + ", " + rhs + ")"; post = " + offsetof(" + base_type + ", " + rhs + ")";
post += "); _val; })"; post += "); _val; })";
......
...@@ -165,5 +165,12 @@ int trace_entry(struct pt_regs *ctx, struct file *file) { ...@@ -165,5 +165,12 @@ int trace_entry(struct pt_regs *ctx, struct file *file) {
b = BPF(text=text, debug=0) b = BPF(text=text, debug=0)
fn = b.load_func("trace_entry", BPF.KPROBE) fn = b.load_func("trace_entry", BPF.KPROBE)
def test_char_array_probe(self):
BPF(text="""#include <linux/blkdev.h>
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__": if __name__ == "__main__":
main() main()
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