summaryrefslogtreecommitdiff
path: root/gdb/debuginfod-support.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2020-09-14 22:28:42 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2020-09-14 22:28:42 -0400
commitd2b31b672955162463cd47bdb28baf2687bebe28 (patch)
tree42ae1f1000d747df74b0b2e64bb98f80c39b407d /gdb/debuginfod-support.c
parent3246bd8ec50fa312403a8629bcad798a1dbbbc0f (diff)
downloadbinutils-gdb-d2b31b672955162463cd47bdb28baf2687bebe28.tar.gz
gdb: introduce debuginfod_client_up type
Introduce and use a unique pointer specialization for the debuginfod_client type. The deleter calls debuginfod_end to free the client. gdb/ChangeLog: * debuginfod-support.c (debuginfod_client_deleter): New. (debuginfod_client_up): New. (debuginfod_init): Return debuginfod_client_up. (debuginfod_source_query): Adjust. (debuginfod_debuginfo_query): Adjust. Change-Id: Ie56441e123ab80b78e5311c824c162cd804f68c0
Diffstat (limited to 'gdb/debuginfod-support.c')
-rw-r--r--gdb/debuginfod-support.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index 73db5360c41..ae0f4c6c437 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -54,6 +54,19 @@ struct user_data
bool has_printed;
};
+/* Deleter for a debuginfod_client. */
+
+struct debuginfod_client_deleter
+{
+ void operator() (debuginfod_client *c)
+ {
+ debuginfod_end (c);
+ }
+};
+
+using debuginfod_client_up
+ = std::unique_ptr<debuginfod_client, debuginfod_client_deleter>;
+
static int
progressfn (debuginfod_client *c, long cur, long total)
{
@@ -79,13 +92,13 @@ progressfn (debuginfod_client *c, long cur, long total)
return 0;
}
-static debuginfod_client *
+static debuginfod_client_up
debuginfod_init ()
{
- debuginfod_client *c = debuginfod_begin ();
+ debuginfod_client_up c (debuginfod_begin ());
if (c != nullptr)
- debuginfod_set_progressfn (c, progressfn);
+ debuginfod_set_progressfn (c.get (), progressfn);
return c;
}
@@ -101,15 +114,15 @@ debuginfod_source_query (const unsigned char *build_id,
if (getenv (DEBUGINFOD_URLS_ENV_VAR) == NULL)
return scoped_fd (-ENOSYS);
- debuginfod_client *c = debuginfod_init ();
+ debuginfod_client_up c = debuginfod_init ();
if (c == nullptr)
return scoped_fd (-ENOMEM);
user_data data ("source file", srcpath);
- debuginfod_set_user_data (c, &data);
- scoped_fd fd (debuginfod_find_source (c,
+ debuginfod_set_user_data (c.get (), &data);
+ scoped_fd fd (debuginfod_find_source (c.get (),
build_id,
build_id_len,
srcpath,
@@ -123,7 +136,6 @@ debuginfod_source_query (const unsigned char *build_id,
else
*destname = make_unique_xstrdup (srcpath);
- debuginfod_end (c);
return fd;
}
@@ -138,7 +150,7 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
if (getenv (DEBUGINFOD_URLS_ENV_VAR) == NULL)
return scoped_fd (-ENOSYS);
- debuginfod_client *c = debuginfod_init ();
+ debuginfod_client_up c = debuginfod_init ();
if (c == nullptr)
return scoped_fd (-ENOMEM);
@@ -146,8 +158,9 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
char *dname = nullptr;
user_data data ("separate debug info for", filename);
- debuginfod_set_user_data (c, &data);
- scoped_fd fd (debuginfod_find_debuginfo (c, build_id, build_id_len, &dname));
+ debuginfod_set_user_data (c.get (), &data);
+ scoped_fd fd (debuginfod_find_debuginfo (c.get (), build_id, build_id_len,
+ &dname));
if (fd.get () < 0 && fd.get () != -ENOENT)
printf_filtered (_("Download failed: %s. Continuing without debug info for %ps.\n"),
@@ -155,7 +168,7 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
styled_string (file_name_style.style (), filename));
destname->reset (dname);
- debuginfod_end (c);
+
return fd;
}
#endif