]> granicus.if.org Git - strace/commitdiff
bpf: print xlated_prog_insns only when xlated_prog_len had not been 0
authorEugene Syromyatnikov <evgsyr@gmail.com>
Fri, 1 Jun 2018 00:44:04 +0000 (02:44 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Sat, 2 Jun 2018 16:32:10 +0000 (16:32 +0000)
If xlated_prog_len is zero on entering syscall and non-zero on exiting,
the program itself is not written into xlated_prog_insns.

* bpf.c (print_ebpf_prog): Add decode argument, print the address only
if decode is false.
(BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)): Specify decode == true argument
to print_ebpf_prog.
(print_bpf_prog_info): Specify saved xlated_prog_len as decode argument
to print_ebpf_prog.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
bpf.c

diff --git a/bpf.c b/bpf.c
index 9abc21409a0de51307dc5f96f6ed8f11c9d81358..83c6ea8d5fb5365dcd8a56b0b8cabcbae701a57e 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -163,10 +163,10 @@ print_ebpf_insn(struct tcb * const tcp, void * const elem_buf,
 
 static void
 print_ebpf_prog(struct tcb *const tcp, const uint64_t addr,
-               const uint32_t len)
+               const uint32_t len, bool decode)
 {
        print_big_u64_addr(addr);
-       if (abbrev(tcp)) {
+       if (abbrev(tcp) || !decode) {
                printaddr(addr);
        } else {
                struct ebpf_insns_data eid = {};
@@ -275,7 +275,7 @@ BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD)
                               "BPF_PROG_TYPE_???");
        PRINT_FIELD_U(", ", attr, insn_cnt);
        tprints(", insns=");
-       print_ebpf_prog(tcp, attr.insns, attr.insn_cnt);
+       print_ebpf_prog(tcp, attr.insns, attr.insn_cnt, true);
 
        tprintf(", license=");
        print_big_u64_addr(attr.license);
@@ -504,7 +504,8 @@ print_bpf_prog_info(struct tcb * const tcp, uint32_t bpf_fd,
        tprintf("%" PRIu32, info.xlated_prog_len);
 
        tprints(", xlated_prog_insns=");
-       print_ebpf_prog(tcp, info.xlated_prog_insns, info.xlated_prog_len / 8);
+       print_ebpf_prog(tcp, info.xlated_prog_insns, info.xlated_prog_len / 8,
+                       !!saved->xlated_prog_len);
 
        PRINT_FIELD_U(", ", info, load_time);
        PRINT_FIELD_UID(", ", info, created_by_uid);