summaryrefslogtreecommitdiff
path: root/libdwfl
diff options
context:
space:
mode:
authorAaron Merey <amerey@redhat.com>2019-10-28 13:29:26 -0400
committerMark Wielaard <mark@klomp.org>2019-11-22 22:49:21 +0100
commit288f6b199a8b1a60d4fb1f54ca7b883cdd5afca2 (patch)
treeb7d6a0dbcc0773de051aacdef8947d4adf72c941 /libdwfl
parent4bad7d1eada6a0690ab30eed2e5ae42c6fd7dacd (diff)
downloadelfutils-288f6b199a8b1a60d4fb1f54ca7b883cdd5afca2.tar.gz
debuginfod 1/2: client side
Introduce the debuginfod/ subdirectory, containing the client for a new debuginfo-over-http service, in shared-library and command-line forms. Two functions in libdwfl make calls into the client library to fetch elf/dwarf files by buildid, as a fallback. Instead of normal dynamic linking (thus pulling in a variety of curl dependencies), the libdwfl hooks use dlopen/dlsym. Server & tests coming in patch 2. Signed-off-by: Aaron Merey <amerey@redhat.com> Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Diffstat (limited to 'libdwfl')
-rw-r--r--libdwfl/ChangeLog6
-rw-r--r--libdwfl/Makefile.am3
-rw-r--r--libdwfl/dwfl_build_id_find_elf.c32
-rw-r--r--libdwfl/find-debuginfo.c31
4 files changed, 67 insertions, 5 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 07a1e8df..b8222189 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,9 @@
+2019-10-28 Aaron Merey <amerey@redhat.com>
+
+ * dwfl_build_id_find_elf.c (dwfl_build_id_find_elf): Call debuginfod
+ client functions via dlopen to look for elf/dwarf files as fallback.
+ * find-debuginfo.c (dwfl_standard_find_debuginfo): Ditto.
+
2019-10-07 Omar Sandoval <osandov@fb.com>
* dwfl_frame.c (dwfl_getthreads): Get rid of unnecessary
diff --git a/libdwfl/Makefile.am b/libdwfl/Makefile.am
index 89ca92ed..29046e9e 100644
--- a/libdwfl/Makefile.am
+++ b/libdwfl/Makefile.am
@@ -31,7 +31,7 @@
##
include $(top_srcdir)/config/eu.am
AM_CPPFLAGS += -I$(srcdir) -I$(srcdir)/../libelf -I$(srcdir)/../libebl \
- -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf
+ -I$(srcdir)/../libdw -I$(srcdir)/../libdwelf -I$(srcdir)/../debuginfod
VERSION = 1
noinst_LIBRARIES = libdwfl.a
@@ -39,6 +39,7 @@ noinst_LIBRARIES += libdwfl_pic.a
pkginclude_HEADERS = libdwfl.h
+
libdwfl_a_SOURCES = dwfl_begin.c dwfl_end.c dwfl_error.c dwfl_version.c \
dwfl_module.c dwfl_report_elf.c relocate.c \
dwfl_module_build_id.c dwfl_module_report_build_id.c \
diff --git a/libdwfl/dwfl_build_id_find_elf.c b/libdwfl/dwfl_build_id_find_elf.c
index cc6c3f62..b775f50a 100644
--- a/libdwfl/dwfl_build_id_find_elf.c
+++ b/libdwfl/dwfl_build_id_find_elf.c
@@ -1,5 +1,5 @@
/* Find an ELF file for a module from its build ID.
- Copyright (C) 2007-2010, 2014, 2015 Red Hat, Inc.
+ Copyright (C) 2007-2010, 2014, 2015, 2019 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -34,7 +34,9 @@
#include <inttypes.h>
#include <fcntl.h>
#include <unistd.h>
+#include <dlfcn.h>
#include "system.h"
+#include "debuginfod.h"
int
@@ -187,7 +189,33 @@ dwfl_build_id_find_elf (Dwfl_Module *mod,
free (*file_name);
*file_name = NULL;
}
- else if (errno == 0 && mod->build_id_len > 0)
+ else {
+ /* NB: this is slightly thread-unsafe */
+ static __typeof__ (debuginfod_find_executable) *fp_debuginfod_find_executable;
+
+ if (fp_debuginfod_find_executable == NULL)
+ {
+ void *debuginfod_so = dlopen("libdebuginfod-" VERSION ".so", RTLD_LAZY);
+ if (debuginfod_so == NULL)
+ debuginfod_so = dlopen("libdebuginfod.so", RTLD_LAZY);
+ if (debuginfod_so != NULL)
+ fp_debuginfod_find_executable = dlsym (debuginfod_so, "debuginfod_find_executable");
+ if (fp_debuginfod_find_executable == NULL)
+ fp_debuginfod_find_executable = (void *) -1; /* never try again */
+ }
+
+ if (fp_debuginfod_find_executable != NULL && fp_debuginfod_find_executable != (void *) -1)
+ {
+ /* If all else fails and a build-id is available, query the
+ debuginfo-server if enabled. */
+ if (fd < 0 && mod->build_id_len > 0)
+ fd = (*fp_debuginfod_find_executable) (mod->build_id_bits,
+ mod->build_id_len,
+ NULL);
+ }
+ }
+
+ if (fd < 0 && errno == 0 && mod->build_id_len > 0)
/* Setting this with no file yet loaded is a marker that
the build ID is authoritative even if we also know a
putative *FILE_NAME. */
diff --git a/libdwfl/find-debuginfo.c b/libdwfl/find-debuginfo.c
index 9267788d..ffc07f92 100644
--- a/libdwfl/find-debuginfo.c
+++ b/libdwfl/find-debuginfo.c
@@ -1,5 +1,5 @@
/* Standard find_debuginfo callback for libdwfl.
- Copyright (C) 2005-2010, 2014, 2015 Red Hat, Inc.
+ Copyright (C) 2005-2010, 2014, 2015, 2019 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -31,9 +31,11 @@
#endif
#include "libdwflP.h"
+#include "debuginfod.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
+#include <dlfcn.h>
#include <sys/stat.h>
#include "system.h"
@@ -359,7 +361,8 @@ dwfl_standard_find_debuginfo (Dwfl_Module *mod,
other than just by finding nothing, that's all we do. */
const unsigned char *bits;
GElf_Addr vaddr;
- if (INTUSE(dwfl_module_build_id) (mod, &bits, &vaddr) > 0)
+ int bits_len;
+ if ((bits_len = INTUSE(dwfl_module_build_id) (mod, &bits, &vaddr)) > 0)
{
/* Dropping most arguments means we cannot rely on them in
dwfl_build_id_find_debuginfo. But leave it that way since
@@ -397,6 +400,30 @@ dwfl_standard_find_debuginfo (Dwfl_Module *mod,
free (canon);
}
+ {
+ /* NB: this is slightly thread-unsafe */
+ static __typeof__ (debuginfod_find_debuginfo) *fp_debuginfod_find_debuginfo;
+
+ if (fp_debuginfod_find_debuginfo == NULL)
+ {
+ void *debuginfod_so = dlopen("libdebuginfod-" VERSION ".so", RTLD_LAZY);
+ if (debuginfod_so == NULL)
+ debuginfod_so = dlopen("libdebuginfod.so", RTLD_LAZY);
+ if (debuginfod_so != NULL)
+ fp_debuginfod_find_debuginfo = dlsym (debuginfod_so, "debuginfod_find_debuginfo");
+ if (fp_debuginfod_find_debuginfo == NULL)
+ fp_debuginfod_find_debuginfo = (void *) -1; /* never try again */
+ }
+
+ if (fp_debuginfod_find_debuginfo != NULL && fp_debuginfod_find_debuginfo != (void *) -1)
+ {
+ /* If all else fails and a build-id is available, query the
+ debuginfo-server if enabled. */
+ if (fd < 0 && bits_len > 0)
+ fd = (*fp_debuginfod_find_debuginfo) (bits, bits_len, NULL);
+ }
+ }
+
return fd;
}
INTDEF (dwfl_standard_find_debuginfo)