From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: netdev@vger.kernel.org
Cc: oss-drivers@netronome.com,
Quentin Monnet <quentin.monnet@netronome.com>,
Jakub Kicinski <jakub.kicinski@netronome.com>
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 [thread overview]
Message-ID: <20171019224626.31608-7-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20171019224626.31608-1-jakub.kicinski@netronome.com>
From: Quentin Monnet <quentin.monnet@netronome.com>
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 <program>`).
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
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
next prev parent reply other threads:[~2017-10-19 22:47 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-19 22:46 [PATCH net-next 0/8] tools: bpftool: add a "version" command, and fix several items Jakub Kicinski
2017-10-19 22:46 ` [PATCH net-next 1/8] tools: bpftool: add pointer to file argument to print_hex() Jakub Kicinski
2017-10-20 10:55 ` Daniel Borkmann
2017-10-19 22:46 ` [PATCH net-next 2/8] tools: bpftool: fix return value when all eBPF programs have been shown Jakub Kicinski
2017-10-20 10:55 ` Daniel Borkmann
2017-10-19 22:46 ` [PATCH net-next 3/8] tools: bpftool: use err() instead of info() if there are too many insns Jakub Kicinski
2017-10-20 10:55 ` Daniel Borkmann
2017-10-19 22:46 ` [PATCH net-next 4/8] tools: bpftool: add `bpftool prog help` as real command i.r.t exit code Jakub Kicinski
2017-10-20 10:56 ` Daniel Borkmann
2017-10-19 22:46 ` [PATCH net-next 5/8] tools: bpftool: print only one error message on byte parsing failure Jakub Kicinski
2017-10-20 10:56 ` Daniel Borkmann
2017-10-19 22:46 ` Jakub Kicinski [this message]
2017-10-20 9:59 ` [PATCH net-next 6/8] tools: bpftool: print all relevant byte opcodes for "load double word" David Laight
2017-10-20 15:50 ` Quentin Monnet
2017-10-20 16:12 ` Daniel Borkmann
2017-10-20 16:41 ` Quentin Monnet
2017-10-20 10:56 ` Daniel Borkmann
2017-10-19 22:46 ` [PATCH net-next 7/8] tools: bpftool: show that `opcodes` or `file FILE` should be exclusive Jakub Kicinski
2017-10-20 10:56 ` Daniel Borkmann
2017-10-19 22:46 ` [PATCH net-next 8/8] tools: bpftool: add a command to display bpftool version Jakub Kicinski
2017-10-20 10:57 ` Daniel Borkmann
2017-10-19 23:42 ` [PATCH net-next 0/8] tools: bpftool: add a "version" command, and fix several items Alexei Starovoitov
2017-10-22 1:11 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171019224626.31608-7-jakub.kicinski@netronome.com \
--to=jakub.kicinski@netronome.com \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
--cc=quentin.monnet@netronome.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).