From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jakub Kicinski Subject: [PATCH net-next 6/8] tools: bpftool: print all relevant byte opcodes for "load double word" Date: Thu, 19 Oct 2017 15:46:24 -0700 Message-ID: <20171019224626.31608-7-jakub.kicinski@netronome.com> References: <20171019224626.31608-1-jakub.kicinski@netronome.com> Cc: oss-drivers@netronome.com, Quentin Monnet , Jakub Kicinski To: netdev@vger.kernel.org Return-path: Received: from mail-pf0-f194.google.com ([209.85.192.194]:52088 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752180AbdJSWrN (ORCPT ); Thu, 19 Oct 2017 18:47:13 -0400 Received: by mail-pf0-f194.google.com with SMTP id n14so8101830pfh.8 for ; Thu, 19 Oct 2017 15:47:13 -0700 (PDT) In-Reply-To: <20171019224626.31608-1-jakub.kicinski@netronome.com> Sender: netdev-owner@vger.kernel.org List-ID: From: Quentin Monnet The eBPF instruction permitting to load double words (8 bytes) into a register need 8-byte long "immediate" field, and thus occupy twice the space of other instructions. bpftool was aware of this and would increment the instruction counter only once on meeting such instruction, but it would only print the first four bytes of the immediate value to load. Make it able to dump the whole 16 byte-long double instruction instead (as would `llvm-objdump -d `). Signed-off-by: Quentin Monnet Signed-off-by: Jakub Kicinski --- tools/bpf/bpftool/prog.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index 355c14325622..57edbea2fbe8 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -313,20 +313,29 @@ static void print_insn(struct bpf_verifier_env *env, const char *fmt, ...) static void dump_xlated(void *buf, unsigned int len, bool opcodes) { struct bpf_insn *insn = buf; + bool double_insn = false; unsigned int i; for (i = 0; i < len / sizeof(*insn); i++) { + if (double_insn) { + double_insn = false; + continue; + } + + double_insn = insn[i].code == (BPF_LD | BPF_IMM | BPF_DW); + printf("% 4d: ", i); print_bpf_insn(print_insn, NULL, insn + i, true); if (opcodes) { printf(" "); fprint_hex(stdout, insn + i, 8, " "); + if (double_insn && i < len - 1) { + printf(" "); + fprint_hex(stdout, insn + i + 1, 8, " "); + } printf("\n"); } - - if (insn[i].code == (BPF_LD | BPF_IMM | BPF_DW)) - i++; } } -- 2.14.1