Re: [RFC bpf-next v1 4/8] selftests/bpf: extract utility function for BPF disassembly

Eduard Zingerman
2024-07-02T20:59:45Z

On Mon, 2024-07-01 at 17:41 -0700, Andrii Nakryiko wrote:
> On Sat, Jun 29, 2024 at 2:48 AM Eduard Zingerman <eddyz87@gmail.com> wrote:
> >
> > uint32_t disasm_insn(struct bpf_insn *insn, char *buf, size_t buf_sz);
>
> or you can return `struct bpf_insn *` which will point to the next
> hypothetical instruction?

Not sure if it simplifies clients, e.g. from this patch, the following:

+ for (i = skip_first_insn ? 1 : 0; i < cnt;) {
+ i += disasm_insn(buf + i, insn_buf, sizeof(insn_buf));
+ fprintf(prog_out, "%s\n", insn_buf);
+ }

Would become:

+ for (i = buf + skip_first_insn ? 1 : 0; i < buf + cnt;) {
+ i = disasm_insn(buf + i, insn_buf, sizeof(insn_buf));
+ fprintf(prog_out, "%s\n", insn_buf);
+ }

idk, can change if you insist.

[...]

> > + sscanf(buf, "(%*[^)]) %n", &pfx_end);
>
> let me simplify this a bit ;)
>
> pfx_end = 5;
>
> not as sophisticated, but equivalent

Okay :(

>
> > + sscanf(buf, "(%*[^)]) call %*[^#]%n", &sfx_start);
>
> is it documented that sfx_start won't be updated if sscanf() doesn't
> successfully match?
>
> if not, maybe let's do something like below
>
> if (strcmp(buf + 5, "call ", 5) == 0 && (tmp = strrchr(buf, '#')))
> sfx_start = tmp - buf;

Will change, the doc is obscure. …