[PATCH 25/26] perf tools: Move debuginfo download code into get_debuginfo

From: Jiri Olsa
Date: Sun Sep 13 2020 - 17:06:21 EST


Moving debuginfo download code into get_debuginfo
to align with get_executable function added earlier.
The functionality stays intact apart from some extra
debug output.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/build-id.c | 45 ++++++++++++++++++++++++++------------
1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c
index 9335a535e547..ea217bb30626 100644
--- a/tools/perf/util/build-id.c
+++ b/tools/perf/util/build-id.c
@@ -626,6 +626,35 @@ 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

+#ifdef HAVE_DEBUGINFOD_SUPPORT
+static int get_debuginfo(const char *sbuild_id, char **path)
+{
+ debuginfod_client *c;
+ int fd;
+
+ c = debuginfod_begin();
+ if (c == NULL)
+ return -1;
+
+ pr_debug("trying debuginfod for debuginfo <%s> ... ", sbuild_id);
+
+ fd = debuginfod_find_debuginfo(c, (const unsigned char *) sbuild_id,
+ 0, path);
+ if (fd >= 0)
+ close(fd); /* retaining reference by realname */
+
+ debuginfod_end(c);
+ pr_debug("%s%s\n", *path ? "OK " : "FAILED", *path ? *path : "");
+ return *path ? 0 : -1;
+}
+#else
+static int get_debuginfo(const char *sbuild_id __maybe_unused,
+ char **path __maybe_unused)
+{
+ return -1;
+}
+#endif
+
static char *build_id_cache__find_debug(const char *sbuild_id,
struct nsinfo *nsi)
{
@@ -649,20 +678,8 @@ static char *build_id_cache__find_debug(const char *sbuild_id,
zfree(&realname);
nsinfo__mountns_exit(&nsc);

-#ifdef HAVE_DEBUGINFOD_SUPPORT
- if (realname == NULL) {
- debuginfod_client* c = debuginfod_begin();
- if (c != NULL) {
- int fd = debuginfod_find_debuginfo(c,
- (const unsigned char*)sbuild_id, 0,
- &realname);
- if (fd >= 0)
- close(fd); /* retaining reference by realname */
- debuginfod_end(c);
- }
- }
-#endif
-
+ if (realname == NULL)
+ get_debuginfo(sbuild_id, &realname);
out:
free(debugfile);
return realname;
--
2.26.2