gdb/netbsd: add missing header file
[binutils-gdb.git] / gdb / debuginfod-support.c
index 22944ce50bbe112295ffe98deb21a0a3850b0a4f..5f04a2b38ca25ab3ccb52a1bcdd0a630b7fc9b28 100644 (file)
@@ -17,6 +17,7 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
+#include "diagnostics.h"
 #include <errno.h>
 #include "gdbsupport/scoped_fd.h"
 #include "debuginfod-support.h"
@@ -173,10 +174,11 @@ get_debuginfod_client ()
 static bool
 debuginfod_is_enabled ()
 {
-  const char *urls = getenv (DEBUGINFOD_URLS_ENV_VAR);
+  const char *urls = skip_spaces (getenv (DEBUGINFOD_URLS_ENV_VAR));
 
-  if (urls == nullptr || urls[0] == '\0'
-      || debuginfod_enabled == debuginfod_off)
+  if (debuginfod_enabled == debuginfod_off
+      || urls == nullptr
+      || *urls == '\0')
     return false;
 
   if (debuginfod_enabled == debuginfod_ask)
@@ -187,10 +189,18 @@ debuginfod_is_enabled ()
       gdb::string_view url_view (urls);
       while (true)
        {
-         url_view = url_view.substr (url_view.find_first_not_of (' '));
-         if (url_view.empty ())
+         size_t off = url_view.find_first_not_of (' ');
+         if (off == gdb::string_view::npos)
            break;
-         size_t off = url_view.find_first_of (' ');
+         url_view = url_view.substr (off);
+         /* g++ 11.2.1 on s390x, g++ 11.3.1 on ppc64le and g++ 11 on
+            hppa seem convinced url_view might be of SIZE_MAX length.
+            And so complains because the length of an array can only
+            be PTRDIFF_MAX.  */
+         DIAGNOSTIC_PUSH
+         DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD
+         off = url_view.find_first_of (' ');
+         DIAGNOSTIC_POP
          gdb_printf
            (_("  <%ps>\n"),
             styled_string (file_name_style.style (),
@@ -254,7 +264,7 @@ debuginfod_source_query (const unsigned char *build_id,
                                        &dname));
   debuginfod_set_user_data (c, nullptr);
 
-  if (debuginfod_verbose > 0 && fd.get () < 0 && fd.get () != -ENOENT)
+  if (fd.get () < 0 && fd.get () != -ENOENT)
     gdb_printf (_("Download failed: %s.  Continuing without source file %ps.\n"),
                safe_strerror (-fd.get ()),
                styled_string (file_name_style.style (),  srcpath));
@@ -296,7 +306,7 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
                                           &dname));
   debuginfod_set_user_data (c, nullptr);
 
-  if (debuginfod_verbose > 0 && fd.get () < 0 && fd.get () != -ENOENT)
+  if (fd.get () < 0 && fd.get () != -ENOENT)
     gdb_printf (_("Download failed: %s.  Continuing without debug info for %ps.\n"),
                safe_strerror (-fd.get ()),
                styled_string (file_name_style.style (),  filename));
@@ -337,7 +347,7 @@ debuginfod_exec_query (const unsigned char *build_id,
   scoped_fd fd (debuginfod_find_executable (c, build_id, build_id_len, &dname));
   debuginfod_set_user_data (c, nullptr);
 
-  if (debuginfod_verbose > 0 && fd.get () < 0 && fd.get () != -ENOENT)
+  if (fd.get () < 0 && fd.get () != -ENOENT)
     gdb_printf (_("Download failed: %s. " \
                  "Continuing without executable for %ps.\n"),
                safe_strerror (-fd.get ()),
@@ -358,7 +368,9 @@ set_debuginfod_enabled (const char *value)
 #if defined(HAVE_LIBDEBUGINFOD)
   debuginfod_enabled = value;
 #else
-  error (NO_IMPL);
+  /* Disabling debuginfod when gdb is not built with it is a no-op.  */
+  if (value != debuginfod_off)
+    error (NO_IMPL);
 #endif
 }