<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/tools/bpf/bpftool/xlated_dumper.c, branch master</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=master</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2025-03-17T20:50:56Z</updated>
<entry>
<title>bpftool: Using the right format specifiers</title>
<updated>2025-03-17T20:50:56Z</updated>
<author>
<name>Jiayuan Chen</name>
</author>
<published>2025-03-11T11:28:09Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3775be3417cc3243b0df0492bd308559dcf0560b'/>
<id>urn:sha1:3775be3417cc3243b0df0492bd308559dcf0560b</id>
<content type='text'>
Fixed some formatting specifiers errors, such as using %d for int and %u
for unsigned int, as well as other byte-length types.

Perform type cast using the type derived from the data type itself, for
example, if it's originally an int, it will be cast to unsigned int if
forced to unsigned.

Signed-off-by: Jiayuan Chen &lt;jiayuan.chen@linux.dev&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20250311112809.81901-3-jiayuan.chen@linux.dev
</content>
</entry>
<entry>
<title>tools/bpf: Fix the wrong format specifier</title>
<updated>2024-07-30T20:41:20Z</updated>
<author>
<name>Zhu Jun</name>
</author>
<published>2024-07-24T11:11:20Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=781f0bbbdade00f91490a3f64212e8cc8d75905c'/>
<id>urn:sha1:781f0bbbdade00f91490a3f64212e8cc8d75905c</id>
<content type='text'>
The format specifier of "unsigned int" in printf() should be "%u", not
"%d".

Signed-off-by: Zhu Jun &lt;zhujun2@cmss.chinamobile.com&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Acked-by: Quentin Monnet &lt;qmo@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20240724111120.11625-1-zhujun2@cmss.chinamobile.com
</content>
</entry>
<entry>
<title>bpftool: Dump the kernel symbol's module name</title>
<updated>2023-07-12T03:07:50Z</updated>
<author>
<name>Yafang Shao</name>
</author>
<published>2023-07-09T02:56:22Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=dc6519445b33bcd9c0ce69c914979a3c0c6e80ce'/>
<id>urn:sha1:dc6519445b33bcd9c0ce69c914979a3c0c6e80ce</id>
<content type='text'>
If the kernel symbol is in a module, we will dump the module name as
well. The square brackets around the module name are trimmed.

Signed-off-by: Yafang Shao &lt;laoar.shao@gmail.com&gt;
Reviewed-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Acked-by: Jiri Olsa &lt;jolsa@kernel.org&gt;
Link: https://lore.kernel.org/r/20230709025630.3735-3-laoar.shao@gmail.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Support printing opcodes and source file references in CFG</title>
<updated>2023-04-06T04:27:27Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2023-04-05T13:21:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7483a7a70a12d7c00c9f80574d533b01689d39a7'/>
<id>urn:sha1:7483a7a70a12d7c00c9f80574d533b01689d39a7</id>
<content type='text'>
Add support for displaying opcodes or/and file references (filepath,
line and column numbers) when dumping the control flow graphs of loaded
BPF programs with bpftool.

The filepaths in the records are absolute. To avoid blocks on the graph
to get too wide, we truncate them when they get too long (but we always
keep the entire file name). In the unlikely case where the resulting
file name is ambiguous, it remains possible to get the full path with a
regular dump (no CFG).

Signed-off-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Link: https://lore.kernel.org/r/20230405132120.59886-7-quentin@isovalent.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Support inline annotations when dumping the CFG of a program</title>
<updated>2023-04-06T04:27:27Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2023-04-05T13:21:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9fd496848b1c4cd04fee5f152bb7bcec11e1b901'/>
<id>urn:sha1:9fd496848b1c4cd04fee5f152bb7bcec11e1b901</id>
<content type='text'>
We support dumping the control flow graph of loaded programs to the DOT
format with bpftool, but so far this feature wouldn't display the source
code lines available through BTF along with the eBPF bytecode. Let's add
support for these annotations, to make it easier to read the graph.

In prog.c, we move the call to dump_xlated_cfg() in order to pass and
use the full struct dump_data, instead of creating a minimal one in
draw_bb_node().

We pass the pointer to this struct down to dump_xlated_for_graph() in
xlated_dumper.c, where most of the logics is added. We deal with BTF
mostly like we do for plain or JSON output, except that we cannot use a
"nr_skip" value to skip a given number of linfo records (we don't
process the BPF instructions linearly, and apart from the root of the
graph we don't know how many records we should skip, so we just store
the last linfo and make sure the new one we find is different before
printing it).

When printing the source instructions to the label of a DOT graph node,
there are a few subtleties to address. We want some special newline
markers, and there are some characters that we must escape. To deal with
them, we introduce a new dedicated function btf_dump_linfo_dotlabel() in
btf_dumper.c. We'll reuse this function in a later commit to format the
filepath, line, and column references as well.

Signed-off-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Link: https://lore.kernel.org/r/20230405132120.59886-4-quentin@isovalent.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Fix bug for long instructions in program CFG dumps</title>
<updated>2023-04-06T04:27:27Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2023-04-05T13:21:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=67cf52cdb6c8fa6365d29106555dacf95c9fd374'/>
<id>urn:sha1:67cf52cdb6c8fa6365d29106555dacf95c9fd374</id>
<content type='text'>
When dumping the control flow graphs for programs using the 16-byte long
load instruction, we need to skip the second part of this instruction
when looking for the next instruction to process. Otherwise, we end up
printing "BUG_ld_00" from the kernel disassembler in the CFG.

Fixes: efcef17a6d65 ("tools: bpftool: generate .dot graph from CFG information")
Signed-off-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Link: https://lore.kernel.org/r/20230405132120.59886-3-quentin@isovalent.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Define _GNU_SOURCE only once</title>
<updated>2022-10-25T17:11:56Z</updated>
<author>
<name>Quentin Monnet</name>
</author>
<published>2022-10-25T15:03:22Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b3d84af7cdfc079ef86d94f7cf125821559925fa'/>
<id>urn:sha1:b3d84af7cdfc079ef86d94f7cf125821559925fa</id>
<content type='text'>
_GNU_SOURCE is defined in several source files for bpftool, but only one
of them takes the precaution of checking whether the value is already
defined. Add #ifndef for other occurrences too.

This is in preparation for the support of disassembling JIT-ed programs
with LLVM, with $(llvm-config --cflags) passing -D_GNU_SOURCE as a
compilation argument.

Signed-off-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Tested-by: Niklas Söderlund &lt;niklas.soderlund@corigine.com&gt;
Acked-by: Song Liu &lt;song@kernel.org&gt;
Link: https://lore.kernel.org/r/20221025150329.97371-2-quentin@isovalent.com
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
</content>
</entry>
<entry>
<title>bpftool: Remove usage of reallocarray()</title>
<updated>2022-02-23T21:55:01Z</updated>
<author>
<name>Mauricio Vásquez</name>
</author>
<published>2022-02-21T12:56:17Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=a19df7139440258e02126f1c795ba64932a8e949'/>
<id>urn:sha1:a19df7139440258e02126f1c795ba64932a8e949</id>
<content type='text'>
This commit fixes a compilation error on systems with glibc &lt; 2.26 [0]:

```
In file included from main.h:14:0,
                 from gen.c:24:
linux/tools/include/tools/libc_compat.h:11:21: error: attempt to use poisoned "reallocarray"
 static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
```

This happens because gen.c pulls &lt;bpf/libbpf_internal.h&gt;, and then
&lt;tools/libc_compat.h&gt; (through main.h). When
COMPAT_NEED_REALLOCARRAY is set, libc_compat.h defines reallocarray()
which libbpf_internal.h poisons with a GCC pragma.

This commit reuses libbpf_reallocarray() implemented in commit
029258d7b228 ("libbpf: Remove any use of reallocarray() in libbpf").

v1 -&gt; v2:
- reuse libbpf_reallocarray() instead of reimplementing it

Fixes: a9caaba399f9 ("bpftool: Implement "gen min_core_btf" logic")
Reported-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Signed-off-by: Mauricio Vásquez &lt;mauricio@kinvolk.io&gt;
Signed-off-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Reviewed-by: Quentin Monnet &lt;quentin@isovalent.com&gt;
Acked-by: Song Liu &lt;songliubraving@fb.com&gt;
Link: https://lore.kernel.org/bpf/20220221125617.39610-1-mauricio@kinvolk.io

[0]: https://lore.kernel.org/bpf/3bf2bd49-9f2d-a2df-5536-bc0dde70a83b@isovalent.com/
</content>
</entry>
<entry>
<title>bpftool: Use syscall/loader program in "prog load" and "gen skeleton" command.</title>
<updated>2021-05-18T22:41:31Z</updated>
<author>
<name>Alexei Starovoitov</name>
</author>
<published>2021-05-14T00:36:19Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d510296d331accd4afaa13498220c93ae690628a'/>
<id>urn:sha1:d510296d331accd4afaa13498220c93ae690628a</id>
<content type='text'>
Add -L flag to bpftool to use libbpf gen_trace facility and syscall/loader program
for skeleton generation and program loading.

"bpftool gen skeleton -L" command will generate a "light skeleton" or "loader skeleton"
that is similar to existing skeleton, but has one major difference:
$ bpftool gen skeleton lsm.o &gt; lsm.skel.h
$ bpftool gen skeleton -L lsm.o &gt; lsm.lskel.h
$ diff lsm.skel.h lsm.lskel.h
@@ -5,34 +4,34 @@
 #define __LSM_SKEL_H__

 #include &lt;stdlib.h&gt;
-#include &lt;bpf/libbpf.h&gt;
+#include &lt;bpf/bpf.h&gt;

The light skeleton does not use majority of libbpf infrastructure.
It doesn't need libelf. It doesn't parse .o file.
It only needs few sys_bpf wrappers. All of them are in bpf/bpf.h file.
In future libbpf/bpf.c can be inlined into bpf.h, so not even libbpf.a would be
needed to work with light skeleton.

"bpftool prog load -L file.o" command is introduced for debugging of syscall/loader
program generation. Just like the same command without -L it will try to load
the programs from file.o into the kernel. It won't even try to pin them.

"bpftool prog load -L -d file.o" command will provide additional debug messages
on how syscall/loader program was generated.
Also the execution of syscall/loader program will use bpf_trace_printk() for
each step of loading BTF, creating maps, and loading programs.
The user can do "cat /.../trace_pipe" for further debug.

An example of fexit_sleep.lskel.h generated from progs/fexit_sleep.c:
struct fexit_sleep {
	struct bpf_loader_ctx ctx;
	struct {
		struct bpf_map_desc bss;
	} maps;
	struct {
		struct bpf_prog_desc nanosleep_fentry;
		struct bpf_prog_desc nanosleep_fexit;
	} progs;
	struct {
		int nanosleep_fentry_fd;
		int nanosleep_fexit_fd;
	} links;
	struct fexit_sleep__bss {
		int pid;
		int fentry_cnt;
		int fexit_cnt;
	} *bss;
};

Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Signed-off-by: Daniel Borkmann &lt;daniel@iogearbox.net&gt;
Acked-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210514003623.28033-18-alexei.starovoitov@gmail.com
</content>
</entry>
<entry>
<title>bpftool: Print subprog address properly</title>
<updated>2021-02-26T21:23:53Z</updated>
<author>
<name>Yonghong Song</name>
</author>
<published>2021-02-26T20:49:31Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f1f9f0d8d737b9a1c5d15635bf5696643626fd39'/>
<id>urn:sha1:f1f9f0d8d737b9a1c5d15635bf5696643626fd39</id>
<content type='text'>
With later hashmap example, using bpftool xlated output may
look like:
  int dump_task(struct bpf_iter__task * ctx):
  ; struct task_struct *task = ctx-&gt;task;
     0: (79) r2 = *(u64 *)(r1 +8)
  ; if (task == (void *)0 || called &gt; 0)
  ...
    19: (18) r2 = subprog[+17]
    30: (18) r2 = subprog[+25]
  ...
  36: (95) exit
  __u64 check_hash_elem(struct bpf_map * map, __u32 * key, __u64 * val,
                        struct callback_ctx * data):
  ; struct bpf_iter__task *ctx = data-&gt;ctx;
    37: (79) r5 = *(u64 *)(r4 +0)
  ...
    55: (95) exit
  __u64 check_percpu_elem(struct bpf_map * map, __u32 * key,
                          __u64 * val, void * unused):
  ; check_percpu_elem(struct bpf_map *map, __u32 *key, __u64 *val, void *unused)
    56: (bf) r6 = r3
  ...
    83: (18) r2 = subprog[-47]

Signed-off-by: Yonghong Song &lt;yhs@fb.com&gt;
Signed-off-by: Alexei Starovoitov &lt;ast@kernel.org&gt;
Acked-by: Andrii Nakryiko &lt;andrii@kernel.org&gt;
Link: https://lore.kernel.org/bpf/20210226204931.3885458-1-yhs@fb.com
</content>
</entry>
</feed>
