diff options
author | Aaron Merey <amerey@redhat.com> | 2021-05-07 11:37:16 -0400 |
---|---|---|
committer | Aaron Merey <amerey@redhat.com> | 2021-05-07 11:37:16 -0400 |
commit | 1d1669e40f89a34ae2804ee040df2bf77ed29df8 (patch) | |
tree | 9bc08d10248d4a61d04e5e8ad029a43430f79fdf | |
parent | 2698f5ead62298979e44a212023027ebb582f3d1 (diff) | |
download | binutils-1d1669e40f89a34ae2804ee040df2bf77ed29df8.zip binutils-1d1669e40f89a34ae2804ee040df2bf77ed29df8.tar.gz binutils-1d1669e40f89a34ae2804ee040df2bf77ed29df8.tar.bz2 |
debuginfod-support.c: Use long-lived debuginfod_client
Instead of initializing a new debuginfod_client for each query, store
the first initialized client for the remainder of the GDB session and
use it for every debuginfod query.
In conjunction with upcoming changes to libdebuginfod, using one client
for all queries will avoid latency caused by unneccesarily setting up
TCP connections multiple times.
Tested on Fedora 33 x86_64.
gdb/ChangeLog:
* debuginfod-support.c (debuginfod_init): Remove.
(get_debuginfod_client): New function.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/debuginfod-support.c | 32 |
2 files changed, 25 insertions, 12 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 76ccb6b..50e87fb 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-05-07 Aaron Merey <amerey@redhat.com> + + * debuginfod-support.c (debuginfod_init): Remove. + (get_debuginfod_client): New function. + 2021-05-07 Tom Tromey <tom@tromey.com> * breakpoint.c (ambiguous_names_p): Use htab_eq_string. diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index 9778e2e..2d626e3 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -72,6 +72,7 @@ static int progressfn (debuginfod_client *c, long cur, long total) { user_data *data = static_cast<user_data *> (debuginfod_get_user_data (c)); + gdb_assert (data != nullptr); if (check_quit_flag ()) { @@ -103,15 +104,20 @@ progressfn (debuginfod_client *c, long cur, long total) return 0; } -static debuginfod_client_up -debuginfod_init () +static debuginfod_client * +get_debuginfod_client () { - debuginfod_client_up c (debuginfod_begin ()); + static debuginfod_client_up global_client; - if (c != nullptr) - debuginfod_set_progressfn (c.get (), progressfn); + if (global_client == nullptr) + { + global_client.reset (debuginfod_begin ()); + + if (global_client != nullptr) + debuginfod_set_progressfn (global_client.get (), progressfn); + } - return c; + return global_client.get (); } /* See debuginfod-support.h */ @@ -126,19 +132,20 @@ debuginfod_source_query (const unsigned char *build_id, if (urls_env_var == NULL || urls_env_var[0] == '\0') return scoped_fd (-ENOSYS); - debuginfod_client_up c = debuginfod_init (); + debuginfod_client *c = get_debuginfod_client (); if (c == nullptr) return scoped_fd (-ENOMEM); user_data data ("source file", srcpath); - debuginfod_set_user_data (c.get (), &data); - scoped_fd fd (debuginfod_find_source (c.get (), + debuginfod_set_user_data (c, &data); + scoped_fd fd (debuginfod_find_source (c, build_id, build_id_len, srcpath, nullptr)); + debuginfod_set_user_data (c, nullptr); /* TODO: Add 'set debug debuginfod' command to control when error messages are shown. */ if (fd.get () < 0 && fd.get () != -ENOENT) @@ -164,7 +171,7 @@ debuginfod_debuginfo_query (const unsigned char *build_id, if (urls_env_var == NULL || urls_env_var[0] == '\0') return scoped_fd (-ENOSYS); - debuginfod_client_up c = debuginfod_init (); + debuginfod_client *c = get_debuginfod_client (); if (c == nullptr) return scoped_fd (-ENOMEM); @@ -172,9 +179,10 @@ debuginfod_debuginfo_query (const unsigned char *build_id, char *dname = nullptr; user_data data ("separate debug info for", filename); - debuginfod_set_user_data (c.get (), &data); - scoped_fd fd (debuginfod_find_debuginfo (c.get (), build_id, build_id_len, + debuginfod_set_user_data (c, &data); + scoped_fd fd (debuginfod_find_debuginfo (c, build_id, build_id_len, &dname)); + debuginfod_set_user_data (c, nullptr); if (fd.get () < 0 && fd.get () != -ENOENT) printf_filtered (_("Download failed: %s. Continuing without debug info for %ps.\n"), |