public inbox for dwarves@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alan Maguire <alan.maguire@oracle.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Jiri Olsa <jolsa@kernel.org>,
	dwarves@vger.kernel.org, bpf@vger.kernel.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH 1/1] pahole: Add option to obtain a vmlinux matching the running kernel
Date: Wed, 28 Aug 2024 16:35:11 -0300	[thread overview]
Message-ID: <Zs977_n0rkleEl94@x1> (raw)

To use in regression tests scripts, but in general its a nice utility to
use in other kinds of scripts.

All this matches:

  $ pahole --running_kernel_vmlinux
  /lib/modules/6.11.0-rc5+/build/vmlinux
  $ file `pahole --running_kernel_vmlinux`
  /lib/modules/6.11.0-rc5+/build/vmlinux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=4dd7f9c4507b82a5bf90671d524e5bb308104ffa, with debug_info, not stripped
  $ perf buildid-list -k
  4dd7f9c4507b82a5bf90671d524e5bb308104ffa
  $ perf buildid-list -i /lib/modules/6.11.0-rc5+/build/vmlinux
  4dd7f9c4507b82a5bf90671d524e5bb308104ffa
  $

Cc: Alan Maguire <alan.maguire@oracle.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 man-pages/pahole.1 |  4 ++++
 pahole.c           | 24 ++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/man-pages/pahole.1 b/man-pages/pahole.1
index 2f623b4e42619114..0a9d8ac49fbf94d5 100644
--- a/man-pages/pahole.1
+++ b/man-pages/pahole.1
@@ -339,6 +339,10 @@ Identical to \-\-btf_features above, but pahole will exit if it encounters an un
 .B \-\-supported_btf_features
 Show set of BTF features supported by \-\-btf_features option and exit.  Useful for checking which features are supported since \-\-btf_features will not emit an error if an unrecognized feature is specified.
 
+.TP
+.B \-\-running_kernel_vmlinux,
+Search for, possibly getting from a debuginfo server, a vmlinux matching the running kernel build-id (from /sys/kernel/notes).
+
 .TP
 .B \-l, \-\-show_first_biggest_size_base_type_member
 Show first biggest size base_type member.
diff --git a/pahole.c b/pahole.c
index 226361dcf349c777..a33490d698ead7d5 100644
--- a/pahole.c
+++ b/pahole.c
@@ -37,6 +37,7 @@ static bool ctf_encode;
 static bool sort_output;
 static bool need_resort;
 static bool first_obj_only;
+static bool show_running_kernel_vmlinux;
 static const char *base_btf_file;
 
 static const char *prettify_input_filename;
@@ -1237,6 +1238,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_btf_features_strict 343
 #define ARGP_contains_enumerator 344
 #define ARGP_reproducible_build 345
+#define ARGP_running_kernel_vmlinux 346
 
 /* --btf_features=feature1[,feature2,..] allows us to specify
  * a list of requested BTF features or "default" to enable all default
@@ -1851,6 +1853,11 @@ static const struct argp_option pahole__options[] = {
 		.key = ARGP_reproducible_build,
 		.doc = "Generate reproducile BTF output"
 	},
+	{
+		.name = "running_kernel_vmlinux",
+		.key = ARGP_running_kernel_vmlinux,
+		.doc = "Search for, possibly getting from a debuginfo server, a vmlinux matching the running kernel build-id (from /sys/kernel/notes)"
+	},
 	{
 		.name = NULL,
 	}
@@ -2032,6 +2039,8 @@ static error_t pahole__options_parser(int key, char *arg,
 		conf_load.skip_encoding_btf_inconsistent_proto = true; break;
 	case ARGP_reproducible_build:
 		conf_load.reproducible_build = true;	break;
+	case ARGP_running_kernel_vmlinux:
+		show_running_kernel_vmlinux = true;	break;
 	case ARGP_btf_features:
 		parse_btf_features(arg, false);		break;
 	case ARGP_supported_btf_features:
@@ -3707,6 +3716,21 @@ int main(int argc, char *argv[])
 		goto out;
 	}
 
+	if (show_running_kernel_vmlinux) {
+		const char *vmlinux = vmlinux_path__find_running_kernel();
+
+		if (vmlinux) {
+			fprintf(stdout, "%s\n", vmlinux);
+			rc = EXIT_SUCCESS;
+		} else {
+			fputs("pahole: couldn't find a vmlinux that matches the running kernel\n"
+			      "HINT: Maybe you're inside a container or missing a debuginfo package?\n",
+			      stderr);
+		}
+
+		return rc;
+	}
+
 	if (languages.str && parse_languages())
 		return rc;
 
-- 
2.46.0


             reply	other threads:[~2024-08-28 19:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-28 19:35 Arnaldo Carvalho de Melo [this message]
2024-08-29  0:08 ` [PATCH 1/1] pahole: Add option to obtain a vmlinux matching the running kernel Eduard Zingerman

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=Zs977_n0rkleEl94@x1 \
    --to=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=dwarves@vger.kernel.org \
    --cc=eddyz87@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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