aboutsummaryrefslogtreecommitdiff
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
parent3246bd8ec50fa312403a8629bcad798a1dbbbc0f (diff)
downloadgdb-d2b31b672955162463cd47bdb28baf2687bebe28.zip
gdb-d2b31b672955162463cd47bdb28baf2687bebe28.tar.gz
gdb-d2b31b672955162463cd47bdb28baf2687bebe28.tar.bz2
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
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/debuginfod-support.c35
2 files changed, 32 insertions, 11 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9ae4900..7ed944a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2020-09-14 Simon Marchi <simon.marchi@polymtl.ca>
+ * 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.
+
+2020-09-14 Simon Marchi <simon.marchi@polymtl.ca>
+
* debuginfod-support.c (debuginfod_source_query): Use
make_unique_xstrdup.
diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index 73db536..ae0f4c6 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