public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: Print debuginfod first-use notification
@ 2021-05-27  1:27 Aaron Merey
  2021-06-21 22:22 ` [PING][PATCH] " Aaron Merey
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Aaron Merey @ 2021-05-27  1:27 UTC (permalink / raw)
  To: gdb-patches

When querying debuginfod servers for the first time, notify the user
that GDB may automatically download debuginfo.  Helps ensure users are
aware that GDB may be relying on the correct operation of remote
debuginfod servers.

In order to determine whether debuginfod is being queried for the
first time, check for the presence of a local debuginfod cache.
If one cannot be found, the notification will be displayed before
performing the first query.

ChangeLog/gdb:

	* debuginfod-support.c (notify_first_use): New function.
---
 gdb/debuginfod-support.c | 41 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
index 2d626e335a0..3d8667d0367 100644
--- a/gdb/debuginfod-support.c
+++ b/gdb/debuginfod-support.c
@@ -104,6 +104,42 @@ progressfn (debuginfod_client *c, long cur, long total)
   return 0;
 }
 
+/* If this is the first time debuginfod is being used on this system, emit
+   a warning message indicating that GDB may automatically download debuginfo.
+
+   To determine whether debuginfod is being used for the first time, check for
+   the presence of a debuginfod cache.  If it cannot be found, then print the
+   warning.  */
+
+static void
+notify_first_use ()
+{
+  std::string cache_var (getenv (DEBUGINFOD_CACHE_PATH_ENV_VAR) ?: "");
+
+  if (access (cache_var.c_str (), F_OK) == 0)
+    return;
+
+  std::string xdg (getenv ("XDG_CACHE_HOME") ?: "");
+
+  if (!xdg.empty ())
+    {
+      xdg.append ("/debuginfod_client");
+      if (access (xdg.c_str (), F_OK) == 0)
+	return;
+    }
+
+  std::string home (getenv ("HOME") ?: "/");
+  std::string h1 = home + "/.debuginfod_client_cache";
+  std::string h2 = home + "/.cache/debuginfod_client";
+
+  if (access (h1.c_str (), F_OK) == 0 || access (h2.c_str (), F_OK) == 0)
+    return;
+
+  printf_filtered ("\nThis GDB is configured to auto-download debuginfo from:\n%s\n\n",
+		   getenv (DEBUGINFOD_URLS_ENV_VAR) ?: "(URLs missing!)");
+  return;
+}
+
 static debuginfod_client *
 get_debuginfod_client ()
 {
@@ -114,7 +150,10 @@ get_debuginfod_client ()
       global_client.reset (debuginfod_begin ());
 
       if (global_client != nullptr)
-	debuginfod_set_progressfn (global_client.get (), progressfn);
+	{
+	  notify_first_use ();
+	  debuginfod_set_progressfn (global_client.get (), progressfn);
+	}
     }
 
   return global_client.get ();
-- 
2.31.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-10-01  2:56 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27  1:27 [PATCH] gdb: Print debuginfod first-use notification Aaron Merey
2021-06-21 22:22 ` [PING][PATCH] " Aaron Merey
2021-07-13 23:01 ` [PING**2][PATCH] " Aaron Merey
2021-07-15  1:02 ` [PATCH] " Simon Marchi
2021-07-21  4:20   ` [PATCH v2] " Aaron Merey
2021-07-21 17:25     ` Lancelot SIX
2021-07-22 15:26     ` Simon Marchi
2021-09-29  1:09       ` Aaron Merey
2021-09-29 17:48         ` Keith Seitz
2021-09-30 15:43           ` Simon Marchi
2021-09-30 15:41         ` Simon Marchi
2021-09-30 17:03           ` Aaron Merey
2021-10-01  2:55             ` Simon Marchi
2021-09-30 17:07           ` Keith Seitz
2021-07-22 17:07 ` [PATCH] " Keith Seitz
2021-07-22 18:01   ` Aaron Merey
2021-07-23 17:13   ` Frank Ch. Eigler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).