Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751229AbbEXI3B (ORCPT ); Sun, 24 May 2015 04:29:01 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:41880 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751090AbbEXI2x (ORCPT ); Sun, 24 May 2015 04:28:53 -0400 From: He Kuang To: , , , , , , , , , , , CC: , Subject: [RFC PATCH v2 15/15] samples/bpf: Add sample for no-debuginfo case Date: Sun, 24 May 2015 08:28:11 +0000 Message-ID: <1432456091-73384-16-git-send-email-hekuang@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1432456091-73384-1-git-send-email-hekuang@huawei.com> References: <1432456091-73384-1-git-send-email-hekuang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.197.210] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3674 Lines: 103 Sample code for testing bpf fetch args without debuginfo. Works as following steps: $ perf bpf record --object /mnt/9p/sample_bpf_fetch_args_without_debug.o -- dd if=/dev/zero of=/mnt/data/test bs=4k count=3 show result in ringbuffer: $ perf script dd 1183 [000] 88000.240137: perf_bpf_probe:generic_perform_write: (ffffffff81130770) arg1=0xffff88007c36cb00 arg2=0xffff88007c167e70 arg3=0x0 arg4=0x0 arg5=0x55617215 arg6=0x1839010 dd 1183 [000] 88000.240137: perf_bpf_probe:generic_perform_write: (ffffffff81130770) arg1=0xffff88007c36cb00 arg2=0xffff88007c167e70 arg3=0x1000 arg4=0x0 arg5=0x55617215 arg6=0x1839010 dd 1183 [000] 88000.240137: perf_bpf_probe:generic_perform_write: (ffffffff81130770) arg1=0xffff88007c36cb00 arg2=0xffff88007c167e70 arg3=0x2000 arg4=0x0 arg5=0x55617215 arg6=0x1839010 dd 1183 [000] 88000.240137: perf_bpf_probe:submit_bio: (ffffffff81310ca0) arg1=0x1 arg2=0xffff88007c9d8000 arg3=0x8b9 arg4=0x8ba arg5=0x1b8e0 arg6=0xffff88007fc1b8e0 show result in bpf prog: $ cat /sys/kernel/debug/tracing/trace | grep dd- dd-1183 [000] d... 88072.038971: : generic_perform_write: file=ffff88007c36cb00, i=ffff88007c167e70, pos=0 dd-1183 [000] d... 88072.039625: : generic_perform_write: file=ffff88007c36cb00, i=ffff88007c167e70, pos=4096 dd-1183 [000] d... 88072.039833: : generic_perform_write: file=ffff88007c36cb00, i=ffff88007c167e70, pos=8192 dd-1183 [000] d... 88072.040533: : submit_bio rw=1, bio=ffff88007c9d8000 Signed-off-by: He Kuang --- samples/bpf/Makefile | 1 + samples/bpf/sample_bpf_fetch_args_without_debug.c | 49 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 samples/bpf/sample_bpf_fetch_args_without_debug.c diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index dc0b0e8..282c959 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile @@ -31,6 +31,7 @@ always += tracex3_kern.o always += tracex4_kern.o always += tcbpf1_kern.o always += sample_bpf_fetch_args.o +always += sample_bpf_fetch_args_without_debug.o HOSTCFLAGS += -I$(objtree)/usr/include diff --git a/samples/bpf/sample_bpf_fetch_args_without_debug.c b/samples/bpf/sample_bpf_fetch_args_without_debug.c new file mode 100644 index 0000000..69519ed --- /dev/null +++ b/samples/bpf/sample_bpf_fetch_args_without_debug.c @@ -0,0 +1,49 @@ +/* + Sample code for bpf_fetch_args() without debuginfo. +*/ + +#include +#include + +#include +#include +#include "bpf_helpers.h" + +/* + * Prototype: + * ssize_t generic_perform_write(struct file *file, + * struct iov_iter *i, loff_t pos) + */ +SEC("generic_perform_write=generic_perform_write $params") +int NODE_generic_perform_write(struct pt_regs *ctx, + void *file, + void *i, + void *pos) +{ + char fmt[] = "generic_perform_write: file=%p, i=%p, pos=%lu\n"; + + bpf_trace_printk(fmt, sizeof(fmt), + file, i, (unsigned long)pos); + + return 1; +} + +/* + * Prototype: + * void submit_bio(int rw, struct bio *bio) + */ +SEC("submit_bio=submit_bio $params") +int NODE_submit_bio(struct pt_regs *ctx, + void *rw, + void *bio) +{ + char fmt[] = "submit_bio rw=%d, bio=%p\n"; + + bpf_trace_printk(fmt, sizeof(fmt), + (int)rw, bio); + + return 1; +} + +char _license[] SEC("license") = "GPL"; +u32 _version SEC("version") = LINUX_VERSION_CODE; -- 1.8.5.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/