Skip to contentSkip to conversation

pfunct: Add support for split BTF

PATCH New Alan Maguire 1 participant 3 messages Sep 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 pfunct: Add support for split BTF

pahole supports split BTF loading for the BTF loader; align pfunct to do the same.

---
 pfunct.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
pfunct.c +36 -0
index 015ff0a..1dc88a5 100644
@@ -15,6 +15,8 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <bpf/btf.h>
+#include <bpf/libbpf.h>
 
 #include "dwarves.h"
 #include "dwarves_emit.h"
@@ -36,6 +38,7 @@ static struct type_emissions emissions;
 static uint64_t addr;
 static char *class_name;
 static char *function_name;
+static const char *base_btf_file;
 
 static struct conf_fprintf conf;
 
@@ -544,6 +547,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_no_parm_names	301
 #define ARGP_compile		302
 #define ARGP_devel_version	303
+#define ARGP_btf_base		304
 
 static const struct argp_option pfunct__options[] = {
 	{
@@ -585,6 +589,12 @@ static const struct argp_option pfunct__options[] = {
 		.arg  = "FORMAT_LIST",
 		.doc  = "List of debugging formats to try"
 	},
+	{
+		.name = "btf_base",
+		.key  = ARGP_btf_base,
+		.arg  = "PATH",
+		.doc  = "Path to the base BTF file for split BTF input",
+	},
 	{
 		.key  = 'g',
 		.name = "goto_labels",
@@ -727,6 +737,7 @@ static error_t pfunct__options_parser(int key, char *arg,
 		  conf_load.extra_dbg_info = true;
 		  conf_load.get_addr_info = true;	 break;
 	case ARGP_symtab: symtab_name = arg ?: ".symtab";  break;
+	case ARGP_btf_base: base_btf_file = arg;             break;
 	case ARGP_no_parm_names: conf.no_parm_names = 1; break;
 	case ARGP_compile:
 		  expand_types = true;
@@ -780,6 +791,29 @@ int main(int argc, char *argv[])
 
 	dwarves__resolve_cacheline_size(&conf_load, 0);
 
+	/* Kernel module BTF in sysfs is split against vmlinux BTF. */
+	if (base_btf_file == NULL) {
+		const char *filename = argv[remaining];
+
+		if (filename &&
+		    strstarts(filename, "/sys/kernel/btf/") &&
+		    strstr(filename, "/vmlinux") == NULL)
+			base_btf_file = vmlinux_path__btf_filename();
+	}
+
+	if (base_btf_file) {
+		conf_load.base_btf = btf__parse(base_btf_file, NULL);
+		if (libbpf_get_error(conf_load.base_btf)) {
+			fprintf(stderr, "pfunct: Failed to parse base BTF '%s': %ld\n",
+				base_btf_file, libbpf_get_error(conf_load.base_btf));
+			goto out_dwarves_exit;
+		}
+
+		/* A base BTF is meaningful only when loading BTF input. */
+		if (conf_load.format_path == NULL)
+			conf_load.format_path = "btf";
+	}
+
 	struct cus *cus = cus__new();
 	if (cus == NULL) {
 		fputs("pfunct: insufficient memory\n", stderr);
@@ -833,6 +867,8 @@ out_cus_delete:
 	cus__delete(cus);
 	fn_stats__delete_list();
 out_dwarves_exit:
+	btf__free(conf_load.base_btf);
+	conf_load.base_btf = NULL;
 	dwarves__exit();
 out:
 	return rc;
Signature · 1 line
2.43.5
#1 lore raw

PATCH 2/3 tests: Add pfunct split BTF test to btf_split

Validate newly-added --btf_base pfunct support.

---
 tests/btf_split.sh | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
tests/btf_split.sh +15 -1
index 135f721..09329fd 100755
@@ -14,6 +14,7 @@
 #  3. bpftool -B can resolve and dump the split BTF using the base BTF
 #  4. split BTF type IDs start strictly above the vmlinux type count
 #     (i.e. the module references base types by the correct offset)
+#  5. pfunct can load the split BTF using the base BTF
 #
 # Requirements:
 #  - bpftool with --base-btf (-B) support
@@ -29,7 +30,7 @@ trap cleanup EXIT
 
 title_log "Split BTF encoding (vmlinux base + kernel module)."
 
-for cmd in bpftool python3 debuginfod-find; do
+for cmd in bpftool pfunct python3 debuginfod-find; do
 	if ! command -v "$cmd" > /dev/null 2>&1; then
 		info_log "skip: $cmd not available"
 		test_skip
@@ -147,4 +148,17 @@ if [ "$first_split_id" -le "$last_base_id" ]; then
 fi
 info_log "split type IDs ($first_split_id+) above last base type ID ($last_base_id): ok"
 
+# --- Check 4: pfunct can load the split BTF with its base ---
+
+if ! pfunct --btf_base="$base_btf" --all "$split_btf" > "$outdir/pfunct.out" 2>&1; then
+	error_log "FAIL: pfunct could not load split BTF with its base"
+	cat "$outdir/pfunct.out" >&2
+	test_fail
+fi
+if ! [ -s "$outdir/pfunct.out" ]; then
+	error_log "FAIL: pfunct produced no output for split BTF"
+	test_fail
+fi
+info_log "pfunct split BTF loading: ok"
+
 test_pass
Signature · 1 line
2.43.5
#2 lore raw

PATCH 3/3 pfunct: add man page

In reply to Alan Maguire

Add a man page documenting pfunct options.

---
 CMakeLists.txt         |   1 +
 man-pages/pfunct.1     | 223 +++++++++++++++++++++++++++++++++++++++++
 rpm/SPECS/dwarves.spec |   1 +
 3 files changed, 225 insertions(+)
 create mode 100644 man-pages/pfunct.1
CMakeLists.txt +1 -0
index cbe5100..a0e3a85 100644
@@ -226,6 +226,7 @@ install(FILES dwarves.h dwarves_emit.h dwarves_reorganize.h
 	      elfcreator.h elf_symtab.h hash.h libctf.h
 	DESTINATION ${CMAKE_INSTALL_PREFIX}/include/dwarves/)
 install(FILES man-pages/pahole.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1/)
+install(FILES man-pages/pfunct.1 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1/)
 if(Python3_FOUND)
 	install(PROGRAMS ostra/ostra-cg DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
 	install(FILES ostra/python/ostra.py DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dwarves/runtime/python)
man-pages/pfunct.1 new file +223 -0

223 lines not on this page · raw message

rpm/SPECS/dwarves.spec +1 -0
index d58285d..10cb2d0 100644
@@ -99,6 +99,7 @@ rm -Rf %{buildroot}
 %dir %{_datadir}/dwarves/runtime/python/
 %defattr(0644,root,root,0755)
 %{_mandir}/man1/pahole.1*
+%{_mandir}/man1/pfunct.1*
 %{_datadir}/dwarves/runtime/Makefile
 %{_datadir}/dwarves/runtime/linux.blacklist.cu
 %{_datadir}/dwarves/runtime/ctracer_relay.c
Signature · 1 line
2.43.5