linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Changbin Du <changbin.du@huawei.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	"Liang, Kan" <kan.liang@linux.intel.com>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev, Hui Wang <hw.huiwang@huawei.com>
Subject: Re: [PATCH v6 6/8] perf: build-id: extend build_id_cache__find_debug() to find local debugging vdso
Date: Wed, 11 Sep 2024 11:04:39 +0300	[thread overview]
Message-ID: <04bd63d3-e76b-4a6e-912c-6306062c91a8@intel.com> (raw)
In-Reply-To: <20240725021549.880167-7-changbin.du@huawei.com>

On 25/07/24 05:15, Changbin Du wrote:
> Just like vmlinux, try to search vdso in predefined paths when collecting
> build-ids. The searched paths usually have debugging info.
> 
> For example, the vdso can be found in
> /lib/modules/<version>/build/arch/x86/entry/vdso/vdso*.so.dbg for local
> build on x86.
> 
> Cc: Adrian Hunter <adrian.hunter@intel.com>
> Signed-off-by: Changbin Du <changbin.du@huawei.com>
> 
> ---
> v3:
>   - continue to try build_id_cache__find_debug_normal() if
>     build_id_cache__find_debug_vdso() failed.
> v2:
>   - Searching the vdso in record stage instead of report. So the debugging
>     vdso will be in build-id cache. This is friendly for cross-machine
>     analysis.
> ---
>  tools/perf/util/build-id.c | 48 ++++++++++++++++++++++++++++++++++----
>  tools/perf/util/symbol.c   | 17 ++++++++++++++
>  tools/perf/util/symbol.h   |  1 +
>  3 files changed, 62 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
> index 5bda47de5cf2..67f88b492279 100644
> --- a/tools/perf/util/build-id.c
> +++ b/tools/perf/util/build-id.c
> @@ -593,9 +593,8 @@ static int build_id_cache__add_sdt_cache(const char *sbuild_id,
>  #define build_id_cache__add_sdt_cache(sbuild_id, realname, nsi) (0)
>  #endif
>  
> -static char *build_id_cache__find_debug(const char *sbuild_id,
> -					struct nsinfo *nsi,
> -					const char *root_dir)
> +static char *build_id_cache__find_debug_normal(const char *sbuild_id,

"normal" is a bit vague.  Perhaps just "__build_id_cache__find_debug"

> +				struct nsinfo *nsi, const char *root_dir)
>  {
>  	const char *dirname = "/usr/lib/debug/.build-id/";
>  	char *realname = NULL;
> @@ -646,6 +645,47 @@ static char *build_id_cache__find_debug(const char *sbuild_id,
>  	return realname;
>  }
>  
> +static char *build_id_cache__find_debug_vdso(const char *sbuild_id)
> +{
> +	char sbuild_id_tmp[SBUILD_ID_SIZE];
> +	struct build_id bid;
> +	int i, ret = 0;
> +
> +	if (!vdso_paths.paths)
> +		return NULL;
> +
> +	pr_debug("Looking at the vdso_path (%d entries long)\n",
> +		 vdso_paths.nr_entries + 1);
> +
> +	for (i = 0; i < vdso_paths.nr_entries; ++i) {
> +		ret = filename__read_build_id(vdso_paths.paths[i], &bid);
> +		if (ret < 0)
> +			continue;
> +
> +		build_id__sprintf(&bid, sbuild_id_tmp);
> +		if (!strcmp(sbuild_id, sbuild_id_tmp)) {
> +			pr_debug("Found debugging vdso %s\n", vdso_paths.paths[i]);
> +			return strdup(vdso_paths.paths[i]);
> +		}
> +	}

Doesn't cover symfs or mount namespace like the other one does.

> +
> +	return NULL;
> +}
> +
> +static char *build_id_cache__find_debug(const char *sbuild_id,
> +					struct nsinfo *nsi,
> +					bool is_vdso,
> +					const char *root_dir)
> +{
> +	char *name = NULL;
> +
> +	if (is_vdso)
> +		name = build_id_cache__find_debug_vdso(sbuild_id);
> +	if (!name)
> +		name = build_id_cache__find_debug_normal(sbuild_id, nsi, root_dir);
> +	return name;
> +}
> +
>  int
>  build_id_cache__add(const char *sbuild_id, const char *name, const char *realname,
>  		    struct nsinfo *nsi, bool is_kallsyms, bool is_vdso,
> @@ -702,7 +742,7 @@ build_id_cache__add(const char *sbuild_id, const char *name, const char *realnam
>  	 * symtab.
>  	 */
>  	if (!is_kallsyms && strncmp(".ko", name + strlen(name) - 3, 3)) {
> -		debugfile = build_id_cache__find_debug(sbuild_id, nsi, root_dir);
> +		debugfile = build_id_cache__find_debug(sbuild_id, nsi, is_vdso, root_dir);
>  		if (debugfile) {
>  			zfree(&filename);
>  			if (asprintf(&filename, "%s/%s", dir_name,
> diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
> index 6bf75c98e1f2..8e982e68b717 100644
> --- a/tools/perf/util/symbol.c
> +++ b/tools/perf/util/symbol.c
> @@ -49,6 +49,7 @@ static int dso__load_vdso_sym(struct dso *dso, struct map *map);
>  static bool symbol__is_idle(const char *name);
>  
>  struct dso_filename_paths vmlinux_paths;
> +struct dso_filename_paths vdso_paths;
>  
>  struct symbol_conf symbol_conf = {
>  	.nanosecs		= false,
> @@ -2303,6 +2304,16 @@ struct dso_filename_pattern vmlinux_patterns[] = {
>  	{"/usr/lib/debug/boot/vmlinux-%s.debug", 1},
>  };
>  
> +struct dso_filename_pattern vdso_patterns[] = {
> +	{"/lib/modules/%s/vdso/vdso.so", 1},
> +	{"/lib/modules/%s/vdso/vdso64.so", 1},
> +	{"/lib/modules/%s/vdso/vdso32.so", 1},
> +	{"/lib/modules/%s/build/arch/%s/vdso/vdso.so.dbg", 2},
> +	{"/lib/modules/%s/build/arch/%s/kernel/vdso/vdso.so.dbg", 2},
> +	{"/lib/modules/%s/build/arch/%s/entry/vdso/vdso32.so.dbg", 2},
> +	{"/lib/modules/%s/build/arch/%s/entry/vdso/vdso64.so.dbg", 2},
> +};
> +
>  static int dso_filename_path__add(struct dso_filename_paths *paths, const char *new_entry)
>  {
>  	paths->paths[paths->nr_entries] = strdup(new_entry);
> @@ -2565,6 +2576,11 @@ int symbol__init(struct perf_env *env)
>  		return -1;
>  	}
>  
> +	if (dso_filename_path__init(&vdso_paths, vdso_patterns,
> +				    ARRAY_SIZE(vdso_patterns), env) < 0) {
> +		return -1;
> +	}
> +
>  	if (symbol_conf.field_sep && *symbol_conf.field_sep == '.') {
>  		pr_err("'.' is the only non valid --field-separator argument\n");
>  		return -1;
> @@ -2641,6 +2657,7 @@ void symbol__exit(void)
>  	intlist__delete(symbol_conf.pid_list);
>  	intlist__delete(symbol_conf.addr_list);
>  	dso_filename_path__exit(&vmlinux_paths);
> +	dso_filename_path__exit(&vdso_paths);
>  	symbol_conf.sym_list = symbol_conf.dso_list = symbol_conf.comm_list = NULL;
>  	symbol_conf.bt_stop_list = NULL;
>  	symbol_conf.initialized = false;
> diff --git a/tools/perf/util/symbol.h b/tools/perf/util/symbol.h
> index 30056884945b..08c339594d4e 100644
> --- a/tools/perf/util/symbol.h
> +++ b/tools/perf/util/symbol.h
> @@ -107,6 +107,7 @@ struct dso_filename_paths {
>  };
>  
>  extern struct dso_filename_paths vmlinux_paths;
> +extern struct dso_filename_paths vdso_paths;
>  
>  static inline void *symbol__priv(struct symbol *sym)
>  {


  reply	other threads:[~2024-09-11  8:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-25  2:15 [PATCH v6 0/8] perf: Support searching local debugging vdso or specify vdso path in cmdline Changbin Du
2024-07-25  2:15 ` [PATCH v6 1/8] perf: support " Changbin Du
2024-09-11  8:03   ` Adrian Hunter
2024-09-12 10:09     ` duchangbin
2024-07-25  2:15 ` [PATCH v6 2/8] perf: disasm: refactor function dso__disassemble_filename Changbin Du
2024-07-25  2:15 ` [PATCH v6 3/8] perf: disasm: use build_id_path if fallback failed Changbin Du
2024-07-25  2:15 ` [PATCH v6 4/8] perf: symbol: generalize vmlinux path searching Changbin Du
2024-09-11  8:03   ` Adrian Hunter
2024-07-25  2:15 ` [PATCH v6 5/8] perf: build-id: add support for build-id cache vdso debug Changbin Du
2024-09-11  8:04   ` Adrian Hunter
2024-07-25  2:15 ` [PATCH v6 6/8] perf: build-id: extend build_id_cache__find_debug() to find local debugging vdso Changbin Du
2024-09-11  8:04   ` Adrian Hunter [this message]
2024-07-25  2:15 ` [PATCH v6 7/8] perf: disasm: prefer debugging files in build-id cache Changbin Du
2024-09-11  8:05   ` Adrian Hunter
2024-07-25  2:15 ` [PATCH v6 8/8] perf buildid-cache: recognize vdso when adding files Changbin Du
2024-09-11  8:05   ` Adrian Hunter
2024-09-12 11:10     ` duchangbin
  -- strict thread matches above, loose matches on Subject: below --
2024-08-16 10:58 [RESEND PATCH v6 0/8] perf: Support searching local debugging vdso or specify vdso path in cmdline Changbin Du
2024-08-16 10:58 ` [PATCH v6 6/8] perf: build-id: extend build_id_cache__find_debug() to find local debugging vdso Changbin Du

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=04bd63d3-e76b-4a6e-912c-6306062c91a8@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=changbin.du@huawei.com \
    --cc=hw.huiwang@huawei.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=morbo@google.com \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.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;
as well as URLs for NNTP newsgroup(s).