From: Alan Maguire <alan.maguire@oracle.com>
To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net
Cc: kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org, jolsa@kernel.org,
sunyucong@gmail.com, netdev@vger.kernel.org, bpf@vger.kernel.org,
Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH v3 bpf-next 3/4] selftests/bpf: add get_lib_path() helper
Date: Mon, 31 Jan 2022 16:12:33 +0000 [thread overview]
Message-ID: <1643645554-28723-4-git-send-email-alan.maguire@oracle.com> (raw)
In-Reply-To: <1643645554-28723-1-git-send-email-alan.maguire@oracle.com>
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) {
+ 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
next prev parent reply other threads:[~2022-01-31 16:13 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 ` Alan Maguire [this message]
2022-02-04 19:24 ` [PATCH v3 bpf-next 3/4] selftests/bpf: add get_lib_path() helper Andrii Nakryiko
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=1643645554-28723-4-git-send-email-alan.maguire@oracle.com \
--to=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).