43 Commits

Author SHA1 Message Date
lizhenlin efba194008 update version to 0.193
Signed-off-by: lizhenlin <lizhenlin2@h-partners.com>
2025-11-12 14:48:40 +08:00
unknown 705c22626b update to v0.190
Signed-off-by: unknown <zhangchun39@huawei.com>
2024-12-06 15:48:16 +08:00
zhanghaibo e660ab2124 upgrade to v0.188
Signed-off-by: zhanghaibo <zhanghaibo0@huawei.com>
Change-Id: I83c8756f5ce0a464b037bc963cfdce43df82921b
2023-04-25 18:45:37 +08:00
Frank Ch. Eigler 0b454c7e19 PR27859: correct 404-latch bug in debuginfod client reuse
PR27701 implemented curl handle reuse in debuginfod_client objects,
but with an unexpected bug.  Server responses returning an error
"latched" because the curl_easy handles for error cases weren't all
systematically removed from the curl multi handle.  This prevented
their proper re-addition the next time.

This version of the code simplfies matters by making only the curl
curl_multi handle long-lived.  This turns out to be enough, because it
can maintain a pool of long-lived http/https connections and related
data, and lend them out to short-lived curl_easy handles.  This mode
handles errors or hung downloads even better, because the easy handles
don't undergo complex state transitions between reuse.

A new test case confirms this correction via the federating debuginfod
instance (cleaning caches between subtests to make sure http* is being
used and reused).

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-05-16 17:51:16 -04:00
Martin Liska adc201f819 Come up with startswith function.
New function in system.h that returns true if a string has a given
prefix, false otherwise.  Use it in place of strncmp.

Signed-off-by: Martin Liška <mliska@suse.cz>
2021-05-12 11:56:57 +02:00
Alice Zhang via Elfutils-devel 5f72c51a7e debuginfod: debuginfod client should cache negative results.
Add debuginfod_config_cache for reading and writing to cache
configuration files, make use of the function within
debuginfod_clean_cache and debuginfod_query_server.

In debuginfod_query_server, create 000-permission file on failed
queries. Before querying each BUILDID, if corresponding 000 file
detected, compare its stat mtime with parameter from
.cache/cache_miss_s. If mtime is fresher, then return ENOENT and
exit; otherwise unlink the 000 file and proceed to a new query.

tests: add test in run-debuginfod-find.sh

test if the 000 file is created on failed query; if querying the
same failed BUILDID, whether the query should proceed without
going through server; set the cache_miss_s to 0 and query the same
buildid, and this time should go through the server.

Signed-off-by: Alice Zhang <alizhang@redhat.com>
2021-05-06 23:04:26 +02:00
Frank Ch. Eigler 92980edc82 PR27571: debuginfod client cache - file permissions
Files in the download cache should be read-only.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-05-01 14:15:32 -04:00
Frank Ch. Eigler 95edde45e5 PR26125: debuginfod client cache - rmdir harder
With PR25365, we accidentally lost the ability to rmdir client-cache
directories corresponding to buildids.  Bring this back, with some
attention to a possible race between a client doing cleanup and
another client doing lookups at the same time.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-05-01 14:03:01 -04:00
Frank Ch. Eigler 6c8b68b024 PR27701: debuginfod client: encourage reused debuginfod_client objects
Client objects now carry long-lived curl handles for outgoing
connections.  This makes it more efficient for multiple sequential
queries, because the TCP connections and/or TLS state info are kept
around awhile, avoiding O(100ms) setup latencies.  debuginfod is
adjusted to take advantage of this for federation.  Other clients
should gradually do this too, perhaps including elfutils itself (in
the libdwfl->debuginfod_client hooks).

A large gdb session with 117 debuginfo downloads was observed to run
twice as fast (45s vs. 1m30s wall-clock time), just in nuking this
extra setup latency.  This was tested via a debuginfod intermediary:
it should be even faster once gdb reuses its own debuginfod_client.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2021-04-30 21:26:27 -04:00
Timm Bäder a51f278371 debuginfod-client: Don't compare a double to a long
Clang warns about this:

../../debuginfod/debuginfod-client.c:899:28: error: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion]
                pa = (dl > LONG_MAX ? LONG_MAX : (long)dl);
                         ~ ^~~~~~~~
/usr/lib64/clang/10.0.1/include/limits.h:47:19: note: expanded from macro 'LONG_MAX'
                  ^~~~~~~~~~~~
<built-in>:38:22: note: expanded from here
                     ^~~~~~~~~~~~~~~~~~~~

Modified for jakub's observation about LONG_MAX overflow.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-07 13:08:15 -05:00
Timm Bäder f82f46fc68 debuginfod-client: Fix typo in curl feature detection
CURLINFO_CURLINFO_CONTENT_LENGTH_DOWNLOAD_T is one CURLINFO_ too much.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
2021-03-05 13:36:15 -05:00
Dmitry V. Levin 0f0e6c5372 debuginfod: fix spelling typos in error diagnostics and comments
Initalize -> Initialize
Unsucessful -> Unsuccessful
expession -> expression
incompatiblity -> incompatibility

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-12 18:06:28 +01:00
Mark Wielaard 6b82ac67d8 debuginfod-client: Initialize struct handle_data errbuf to the empty string.
Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-11-23 17:52:02 +01:00
Mark Wielaard 609053a588 debuginfod-client: Add debuginfod_set_verbose_fd and DEBUGINFOD_VERBOSE
Introduce a new function debuginfod_set_verbose_fd which will produce
verbose output on a given file descriptor (STDERR_FILENO if the
environment variable DEBUGINFOD_VERBOSE is set) showing how the search
for a particular client query is going.

Example output:

debuginfod_find_debuginfo 1234567890
server urls "https://debuginfod.elfutils.org/ http://dbgd.usersys.com:3632/"
checking build-id
checking cache dir /home/mark/.cache/debuginfod_client
using timeout 90
init server 0 https://debuginfod.elfutils.org/
url 0 https://debuginfod.elfutils.org/buildid/1234567890/debuginfo
init server 1 http://dbgd.usersys.com:3632/
url 1 http://dbgd.usersys.com:3632/buildid/1234567890/debuginfo
query 2 urls in parallel
server response HTTP response code said error
url 0 The requested URL returned error: 404 Not Found
server response HTTP response code said error
url 1 The requested URL returned error: 404 Not Found
not found No such file or directory (err=-2)

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-11-23 16:58:36 +01:00
Érico Rolim ced66615bd Switch from numerical to defined constants for permissions.
Use defined constants for permission values. Also add fallback
definitions for them in system.h, to allow for compatibility with
systems that don't provide these macros.

Include system.h in all tests/ files that required it.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-11-03 15:54:14 +01:00
Mark Wielaard 747a84b60e debuginfod: Translate CURLE_PEER_FAILED_VERIFICATION to ECONNREFUSED.
When a file couldn't be retrieved because of an bad HTTPS certificate
find-debuginfod currently says:
Server query failed: No such file or directory

With this patch it will say:
Server query failed: Connection refused

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-10-26 22:55:29 +01:00
Alice Zhang 8de6f9af46 debuginfod: DEBUGINFOD_URLS should accept scheme-free urls
Check scheme instead of effective url so that user may abbreviate
DEBUGINFOD_URL. Add one test for scheme free http url.

Notice that libcurl does not provide an almighty scheme free url
support, /path/to/something without FILE:// can not be recognized
in most circumstances, therefore for the neatness of our code
structure, DEBUGINFOD_ URL of scheme "FILE" must be input as URI.

Signed-off-by: Alice Zhang <alizhang@redhat.com>
2020-07-05 17:00:33 +02:00
Mark Wielaard f7f0cdc59a debuginfod: Add --disable-libdebuginfod and --enable-libdebuginfod=dummy.
Make it possible to build just the debuginfod client or to create a
dummy libdebuginfod that doesn't link against libcurl. The dummy library
can be used for bootstrapping. For testing purposes you can also build
debuginfod against the dummy libdebuginfod but then the debuginfod
server will not be able to do delegation.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-07-04 01:30:07 +02:00
Mark Wielaard d45cc8a04a debuginfod: Make sure handle_data can be allocated and is always freed.
When allocating handle_data we should check for out of memory failures.
Also when the allocation has succeeded make sure we always clean up by
going to out1 on any future errors. So move the curl_multi_init call
earlier, because that goes to out0 on failure.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-06-24 16:37:35 +02:00
Mark Wielaard 90808ed559 debuginfod: Fix build_id hexadecimal length check.
When is debuginfod_query_server is given an hexadecimal string as
build-id build_id_len will be zero. We were checking the size of
the build_id_bytes destination string instead of the string length
of build_id input string. Make sure the input string is not too
big or strcpy might overwrite then end of the build_id_bytes array.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-06-24 16:37:35 +02:00
Mark Wielaard 6b677bf8e3 debuginfod: Make sure suffix can place zero terminator when copying filename
We need to make sure that we can always place a zero terminator at
the end of suffix when we are copying the filename. So add one more
char to the suffix array. And make sure that we can always add an
extra escape character when we need to escape the current character.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-06-24 16:37:35 +02:00
Mark Wielaard a7c5e3004b debuginfod: Handle not being able to fopen interval_path.
Although we check for and/or create the interval_path right before,
there is still a possibility that the fopen call fails. Handle that
as if the file is unreadable.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-06-24 16:37:35 +02:00
Mark Wielaard 7ddceee2b6 debuginfod: Document and sanity check debuginfod_add_http_header format.
Document and sanity check the format of the header string form that can
be passed to debuginfod_add_http_header. It should contain precisely
one colon, which cannot be the first or last character. And the function
should only be used to add optional headers, not replace any existing
standard ones. Anything else isn't supported.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-03-30 00:57:30 +02:00
Frank Ch. Eigler 03bb9dbb2d debuginfod-client default_progressfn: formatting fix
The saga of clean $DEBUGINFOD_PROGRESS=1 output continues.  Previous
code would sometimes insert a \n (a blank line) into the output
stream, even if the target file was found in a cache and thus the
progressfn was never called.  New code sets a client flag to track
this case more precisely.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-03-29 15:13:47 -04:00
Frank Ch. Eigler dbfaf36ac2 debuginfod: User-Agent and X-Forwarded-For header relay
Extend the debuginfod client API with a function to stuff outgoing
headers into libcurl http transfers.  Use this from debuginfod so
federated trees of debuginfod/httpd can trace back to to the
originating client for administrative purposes.  Docs & test included.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-03-27 12:44:42 -04:00
Frank Ch. Eigler dbd41ebdfe PR25548: CURLOPT_PATH_AS_IS backward compatibility
old libcurl lacks the CURL_AT_LEAST_VERSION macro, so use
LIBCURL_VERSION_NUM testing instead.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-03-26 11:21:23 -04:00
Frank Ch. Eigler 610149d320 PR25548: CURLOPT_PATH_AS_IS backward compatibility
libcurl < 7.42 lacks the CURLOPT_PATH_AS_IS flag, but extraneous
client-side canonicalization is mostly harmless.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Reported-by: Mark Wielaard <mark@klomp.org>
2020-03-26 11:12:49 -04:00
Frank Ch. Eigler d63a809da4 PR25548: support canonicalized source-path names in debuginfod webapi
Programs are sometimes compiled with source path names containing
noise like /./ or // or /foo/../, and these survive into DWARF.  This
code allows either raw or canonicalized pathnames in the webapi, by
letting the client pass things verbatim, and letting the server
store/accept both raw and canonicalized path names for source files.
Tests included & docs updated.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Reported-by: Eli Schwartz <eschwartz@archlinux.org>
Tested-by: Eli Schwartz <eschwartz@archlinux.org>
2020-03-26 10:35:38 -04:00
Frank Ch. Eigler ea7eb6934b debuginfod-client thinko: non-default progressfn extra output
A previous commit changed the default_progressfn output format
to \rFOOBAR, to be terminated by an \n when the download finished.
The \n terminator was conditional on the wrong thing (env var
setting, rather than actual progressfn setting), so the \n could
be printed even if an app overrode the default.
2020-03-24 21:34:37 -04:00
Frank Ch. Eigler 5d67e9d3ea debuginfod client API: add get_url function
This function lets a client know, during or after a progressfn
callback, what the url of the winning outgoing download is/was.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-03-22 16:46:16 -04:00
Frank Ch. Eigler b40e255683 debuginfod client API: add get/set user_data functions
Add a pair of functions to associate a void* parameter with a client
object.  Requested by GDB team as a way to pass file names and such
user-interface data through to a progressfn callback.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2020-03-22 16:46:14 -04:00
Aaron Merey a5cf9ba6bb debuginfod-client: Update cache_path when the new default path exists
Update cache_path with the path of the new default directory when this
directory already exists. Previously cache_path was updated only when
creating the new default directory and would otherwise be set to the
old default path.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2020-03-04 11:38:05 +01:00
Aaron Merey e939590219 debuginfod-client: default to XDG cache.
PR25502: debuginfod client should default to XDG cache

Location of client cache now defaults to $XDG_CACHE_HOME/debuginfod_client.
If XDG_CACHE_HOME is not set then fallback to $HOME/.cache/debuginfod_client.
Also maintain backwards compatibility with the previous default path-
if $HOME/.debuginfod_client_cache exists, use that instead of the new
defaults.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2020-02-28 14:21:55 +01:00
Konrad Kleine 4c1de9608b debuginfod: file:// URLs: handle curl resp. code
When file:// is used for DEBUGINFOD_URLS, then the response code for a
successful server query is 0 and not 200.

Using file:// can be helpful when you want to test your
debuginfod-client integration against a mocked file tree that mimics the
HTTP URLs from the debuginfod server. This way you don't have to run the
debuginfod server at all.

Fixes https://sourceware.org/bugzilla/show_bug.cgi?id=25600

Signed-off-by: Konrad Kleine <kkleine@redhat.com>
2020-02-26 21:10:40 +01:00
Aaron Merey 889edd912c PR25365: debuginfod-client: restrict cleanup to client-pattern files
Avoid deleting general files and directories in case a user
mis-sets $DEBUGINFOD_CACHE_PATH or accidentally moves a file
into the cache.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2020-02-19 14:01:33 -05:00
Mark Wielaard b8d85ed024 debuginfod: Use DEBUGINFOD_TIMEOUT as seconds to get at least 100K.
Use just one timeout using CURLOPT_LOW_SPEED_TIME (default 90 seconds)
and CURLOPT_LOW_SPEED_LIMIT (100K).

Signed-off-by: Mark Wielaard <mark@klomp.org>
2020-01-10 00:12:00 +01:00
Frank Ch. Eigler 288c76775f debuginfod: pass a distro-summary User-Agent request header
It may be useful for a debuginfod server operator to know what kinds
of clients make webapi requests.  This is mainly as a
telemetry/diagnostic (though the data cannot be really trusted).  It
may also be useful to automate downloading of distro packages to a
debuginfod server in the case of an unknown hex buildid.  doc/testing
not affected as these are diagnostics.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2020-01-09 16:14:51 -05:00
Frank Ch. Eigler 76ad56c430 debuginfod: usability tweaks, incl. $DEBUGINFOD_PROGRESS client support
This facility allows a default progress-printing function to be
installed if the given environment variable is set.  Some larger usage
experience (systemtap fetching kernels) indicates the default timeout
is too short, so forked it into a connection timeout (default short)
and a transfer timeout (default unlimited).

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2019-12-19 09:57:13 -05:00
Mark Wielaard ef99c78204 debuginfod: Check the DEBUGINFOD_URLS environment variable early in client.
If the debuginfod-client isn't configured we should do as little
as possible. Simply return early with ENOSYS if no servers are
configured. This means we won't check

This does change the behavior of the debuginfod_find calls slightly.
Previously we would setup and check the cache if the given build-id
was valid. Which might have provided a result if an earlier client
had run with the same cache and valid server URLs which knew about
that particular build-id. Now we don't return any cached results
unless at least one server is configured.

This prevents selinux errors when the library is used in a confined
setup.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-12-11 22:31:00 +01:00
Mark Wielaard 374fbed3da debuginfod: Fix implicit conversion from 'CURLcode' to 'CURLMcode'
GCC10 warns when converting the value of one enum type into another:

debuginfod-client.c:530:24: error: implicit conversion from ‘CURLcode’
                                   to ‘CURLMcode’ [-Werror=enum-conversion]
  530 |               curl_res = curl_easy_getinfo(target_handle,
      |                        ^

libcurl has different error code enums. The "easy" interfaces return
a CURLcode error. The "multi" interface functions return a CURLMcode.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-12-09 20:26:15 +01:00
Mark Wielaard fa0226a78a debuginfod: add client context
Add a mandatory debuginfod_begin()/_end() call pair to manage a client
object that represents persistent but non-global state.  From libdwfl,
dlopen the debuginfod.so client library early on.  This hopefully
makes sure that the code (and the libcurl.so dependency) is loaded
before the program goes into multi-threaded mode.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2019-11-23 01:03:13 +01:00
Frank Ch. Eigler 3d7a08d5d3 debuginfod 3/3: client interruptability
For interactive clients such as gdb, interruptibility is important for
usability during longer downloads.  This patchset adds a
download-progress callback function to the debuginfod client library,
with which a caller app can interrupt a download as well as be
notified of its quantitative progress.
2019-11-22 23:26:21 +01:00
Aaron Merey 288f6b199a 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>
2019-11-22 22:49:21 +01:00