diff options
Diffstat (limited to 'libdwfl/find-debuginfo.c')
-rw-r--r-- | libdwfl/find-debuginfo.c | 31 |
1 files changed, 29 insertions, 2 deletions
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) |