From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 42966386F819 for ; Wed, 21 Jul 2021 04:20:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 42966386F819 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-437--2fU8WJZOAqQ2NXOBoAEMg-1; Wed, 21 Jul 2021 00:20:14 -0400 X-MC-Unique: -2fU8WJZOAqQ2NXOBoAEMg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 32F9D362F8; Wed, 21 Jul 2021 04:20:13 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-118-252.rdu2.redhat.com [10.10.118.252]) by smtp.corp.redhat.com (Postfix) with ESMTP id C42A810016F2; Wed, 21 Jul 2021 04:20:12 +0000 (UTC) From: Aaron Merey To: simon.marchi@polymtl.ca, gdb-patches@sourceware.org Subject: [PATCH v2] gdb: Print debuginfod first-use notification Date: Wed, 21 Jul 2021 00:20:12 -0400 Message-Id: <20210721042012.154980-1-amerey@redhat.com> In-Reply-To: <053ff125-c088-66fe-9e96-2c48f4b5999d@polymtl.ca> References: <053ff125-c088-66fe-9e96-2c48f4b5999d@polymtl.ca> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jul 2021 04:20:17 -0000 Hi Simon, On Wed, Jul 14, 2021 at 9:02 PM Simon Marchi wrote: > The use of "x ? : y" is a GNU extension, can we use that?  I don't > remember.  Perhaps it's better to do: > >   const char *cache_var = getenv (DEBUGINFOD_CACHE_PATH_ENV_VAR); >   if (cache_var == nullptr) >     return; > > Since it's useless to do the access call below with an empty string, we > know it will fail. Fixed. > > + > > +  if (access (cache_var.c_str (), F_OK) == 0) > > +    return; > > + > > +  std::string xdg (getenv ("XDG_CACHE_HOME") ?: ""); > > + > > +  if (!xdg.empty ()) > > +    { > > +      xdg.append ("/debuginfod_client"); > > Does debuginfod use XDG_CACHE_HOME regardless of the platform to find a > cache dir?  I think it would be much better if we could ask the > debuginfod library for the path to the local cache, so we don't bake-in > the location where we think debuginfod puts it (which could change in > the future). To avoid this problem I changed the heuristic used to determine first use. The presence of a 'debuginfod-used-p' file in the GDB config directory will signal to GDB that the first use notice has already been printed. If the file does not exist when the first query is about to happen then the file is created and the notice is printed. Aaron >From 0ee110b17624b187b6dfb55d4145756da582d8e3 Mon Sep 17 00:00:00 2001 From: Aaron Merey Date: Tue, 20 Jul 2021 23:36:59 -0400 Subject: gdb: Print debuginfod first-use notification 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 'debuginfod-used-p' file in the gdb config directory. If one cannot be found, the notification will be displayed before performing the first query. --- 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..2de703cc138 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -22,6 +22,7 @@ #include "gdbsupport/scoped_fd.h" #include "debuginfod-support.h" #include "gdbsupport/gdb_optional.h" +#include "gdbsupport/pathstuff.h" #ifndef HAVE_LIBDEBUGINFOD scoped_fd @@ -104,6 +105,41 @@ progressfn (debuginfod_client *c, long cur, long total) return 0; } +/* If this is the first time that GDB is using debuginfod 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-used-p' file in the GDB config directory. If + it is not found, then try to create the file and print the warning. */ + +static void +notify_first_use () +{ + const char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR); + if (urls == nullptr) + return; + + std::string used_p = get_standard_config_filename ("debuginfod-used-p"); + if (access (used_p.c_str (), F_OK) == 0) + return; + + std::string cache = get_standard_config_dir (); + if (cache.empty ()) + { + warning (_("Cannot determine GDB config directory.")); + } + else if (!mkdir_recursive (cache.c_str ()) + || open (used_p.c_str (), O_CREAT, 0) < 0) + { + warning (_("Cannot create debuginfod config file: %s"), + safe_strerror (errno)); + } + + printf_filtered ("\nThis GDB is configured to auto-download debuginfo from:\n%s\n\n", + urls); + 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