netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>, Martin Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	john fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@kernel.org>, Jiri Olsa <jolsa@kernel.org>,
	Yucong Sun <sunyucong@gmail.com>,
	Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH v3 bpf-next 3/4] selftests/bpf: add get_lib_path() helper
Date: Fri, 4 Feb 2022 11:24:17 -0800	[thread overview]
Message-ID: <CAEf4BzbyWd6bfWFGLX-c7s2YLjFTQXAc=NOEFChwu2ApvJNeFQ@mail.gmail.com> (raw)
In-Reply-To: <1643645554-28723-4-git-send-email-alan.maguire@oracle.com>

On Mon, Jan 31, 2022 at 8:13 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> get_lib_path(path_substr) returns full path to a library
> containing path_substr (such as "libc-") found via
> /proc/self/maps.  Caller is responsible for freeing
> the returned string.
>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---
>  tools/testing/selftests/bpf/trace_helpers.c | 17 +++++++++++++++++
>  tools/testing/selftests/bpf/trace_helpers.h |  2 ++
>  2 files changed, 19 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c
> index ca6abae..49e5f0d 100644
> --- a/tools/testing/selftests/bpf/trace_helpers.c
> +++ b/tools/testing/selftests/bpf/trace_helpers.c
> @@ -216,3 +216,20 @@ ssize_t get_rel_offset(uintptr_t addr)
>         fclose(f);
>         return -EINVAL;
>  }
> +
> +char *get_lib_path(const char *path_substr)
> +{
> +       char *found = NULL;
> +       char lib_path[512];
> +       FILE *f;
> +
> +       f = fopen("/proc/self/maps", "r");
> +       while (fscanf(f, "%*s %*s %*s %*s %*s %[^\n]", lib_path) == 1) {

I think it can be followed by " (deleted)", right? Do we want to
detect that and do something about it?

> +               if (strstr(lib_path, path_substr) == NULL)
> +                       continue;
> +               found = strdup(lib_path);
> +               break;
> +       }
> +       fclose(f);
> +       return found;
> +}
> diff --git a/tools/testing/selftests/bpf/trace_helpers.h b/tools/testing/selftests/bpf/trace_helpers.h
> index 238a9c9..ff379f6 100644
> --- a/tools/testing/selftests/bpf/trace_helpers.h
> +++ b/tools/testing/selftests/bpf/trace_helpers.h
> @@ -20,5 +20,7 @@ struct ksym {
>
>  ssize_t get_uprobe_offset(const void *addr);
>  ssize_t get_rel_offset(uintptr_t addr);
> +/* Return allocated string path to library that contains path_substr. */
> +char *get_lib_path(const char *path_substr);
>
>  #endif
> --
> 1.8.3.1
>

  reply	other threads:[~2022-02-04 19:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-31 16:12 [PATCH v3 bpf-next 0/4] libbpf: name-based u[ret]probe attach Alan Maguire
2022-01-31 16:12 ` [PATCH v3 bpf-next 1/4] libbpf: support function name-based attach uprobes Alan Maguire
2022-02-04 19:17   ` Andrii Nakryiko
2022-02-25 16:12     ` Alan Maguire
2022-01-31 16:12 ` [PATCH v3 bpf-next 2/4] libbpf: add auto-attach for uprobes based on section name Alan Maguire
2022-02-04 19:22   ` Andrii Nakryiko
2022-02-23  9:32     ` Alan Maguire
2022-02-24  1:49       ` Andrii Nakryiko
2022-02-24 15:39         ` Alan Maguire
2022-03-01  1:45           ` Andrii Nakryiko
2022-01-31 16:12 ` [PATCH v3 bpf-next 3/4] selftests/bpf: add get_lib_path() helper Alan Maguire
2022-02-04 19:24   ` Andrii Nakryiko [this message]
2022-01-31 16:12 ` [PATCH v3 bpf-next 4/4] selftests/bpf: add tests for u[ret]probe attach by name Alan Maguire
2022-02-04 19:30   ` Andrii Nakryiko
2022-02-26 16:00   ` Jiri Olsa
2022-02-01  8:52 ` [PATCH v3 bpf-next 0/4] libbpf: name-based u[ret]probe attach Daniel Borkmann

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='CAEf4BzbyWd6bfWFGLX-c7s2YLjFTQXAc=NOEFChwu2ApvJNeFQ@mail.gmail.com' \
    --to=andrii.nakryiko@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=songliubraving@fb.com \
    --cc=sunyucong@gmail.com \
    --cc=yhs@fb.com \
    /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).