Fix error message in compile-object-load.c
[deliverable/binutils-gdb.git] / gdb / utils.c
index 18d81903d195174b2128a1dcc215423c75d54143..0b470120a22f60b9309743d016e4f1df035c9128 100644 (file)
@@ -1,6 +1,6 @@
 /* General utility routines for GDB, the GNU debugger.
 
-   Copyright (C) 1986-2019 Free Software Foundation, Inc.
+   Copyright (C) 1986-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -186,7 +186,7 @@ abort_with_message (const char *msg)
   else
     fputs_unfiltered (msg, gdb_stderr);
 
-  abort ();            /* NOTE: GDB has only three calls to abort().  */
+  abort ();            /* ARI: abort */
 }
 
 /* Dump core trying to increase the core soft limit to hard limit first.  */
@@ -200,7 +200,7 @@ dump_core (void)
   setrlimit (RLIMIT_CORE, &rlim);
 #endif /* HAVE_SETRLIMIT */
 
-  abort ();            /* NOTE: GDB has only three calls to abort().  */
+  abort ();            /* ARI: abort */
 }
 
 /* Check whether GDB will be able to dump core using the dump_core
@@ -320,7 +320,7 @@ internal_vproblem (struct internal_problem *problem,
            does not fix this problem.  This is the solution suggested
            at http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509.  */
        if (write (STDERR_FILENO, msg, sizeof (msg)) != sizeof (msg))
-          abort (); /* NOTE: GDB has only three calls to abort().  */
+          abort (); /* ARI: abort */
        exit (1);
       }
   }
@@ -582,9 +582,7 @@ add_internal_problem_command (struct internal_problem *problem)
 static std::string
 perror_string (const char *prefix)
 {
-  char *err;
-
-  err = safe_strerror (errno);
+  const char *err = safe_strerror (errno);
   return std::string (prefix) + ": " + err;
 }
 
@@ -630,19 +628,11 @@ perror_warning_with_name (const char *string)
 void
 print_sys_errmsg (const char *string, int errcode)
 {
-  char *err;
-  char *combined;
-
-  err = safe_strerror (errcode);
-  combined = (char *) alloca (strlen (err) + strlen (string) + 3);
-  strcpy (combined, string);
-  strcat (combined, ": ");
-  strcat (combined, err);
-
+  const char *err = safe_strerror (errcode);
   /* We want anything which was printed on stdout to come out first, before
      this message.  */
   gdb_flush (gdb_stdout);
-  fprintf_unfiltered (gdb_stderr, "%s.\n", combined);
+  fprintf_unfiltered (gdb_stderr, "%s: %s.\n", string, err);
 }
 
 /* Control C eventually causes this to be called, at a convenient time.  */
@@ -1281,13 +1271,13 @@ init_page_info (void)
          || getenv ("EMACS") || getenv ("INSIDE_EMACS"))
        {
          /* The number of lines per page is not mentioned in the terminal
-            description or EMACS evironment variable is set.  This probably
+            description or EMACS environment variable is set.  This probably
             means that paging is not useful, so disable paging.  */
          lines_per_page = UINT_MAX;
        }
 
       /* If the output is not a terminal, don't paginate it.  */
-      if (!ui_file_isatty (gdb_stdout))
+      if (!gdb_stdout->isatty ())
        lines_per_page = UINT_MAX;
 #endif
     }
@@ -1415,7 +1405,7 @@ emit_style_escape (const ui_file_style &style,
   if (stream == nullptr)
     wrap_buffer.append (style.to_ansi ());
   else
-    fputs_unfiltered (style.to_ansi ().c_str (), stream);
+    stream->puts (style.to_ansi ().c_str ());
 }
 
 /* Set the current output style.  This will affect future uses of the
@@ -1549,11 +1539,20 @@ flush_wrap_buffer (struct ui_file *stream)
 {
   if (stream == gdb_stdout && !wrap_buffer.empty ())
     {
-      fputs_unfiltered (wrap_buffer.c_str (), stream);
+      stream->puts (wrap_buffer.c_str ());
       wrap_buffer.clear ();
     }
 }
 
+/* See utils.h.  */
+
+void
+gdb_flush (struct ui_file *stream)
+{
+  flush_wrap_buffer (stream);
+  stream->flush ();
+}
+
 /* Indicate that if the next sequence of characters overflows the line,
    a newline should be inserted here rather than when it hits the end.
    If INDENT is non-null, it is a string to be printed to indent the
@@ -1698,7 +1697,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
       || top_level_interpreter ()->interp_ui_out ()->is_mi_like_p ())
     {
       flush_wrap_buffer (stream);
-      fputs_unfiltered (linebuffer, stream);
+      stream->puts (linebuffer);
       return;
     }
 
@@ -1777,7 +1776,12 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
                     newline -- if chars_per_line is right, we
                     probably just overflowed anyway; if it's wrong,
                     let us keep going.  */
-                 fputc_unfiltered ('\n', stream);
+                 /* XXX: The ideal thing would be to call
+                    'stream->putc' here, but we can't because it
+                    currently calls 'fputc_unfiltered', which ends up
+                    calling us, which generates an infinite
+                    recursion.  */
+                 stream->puts ("\n");
                }
              else
                {
@@ -1798,7 +1802,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
              /* Now output indentation and wrapped string.  */
              if (wrap_column)
                {
-                 fputs_unfiltered (wrap_indent, stream);
+                 stream->puts (wrap_indent);
                  if (stream->can_emit_style_escape ())
                    emit_style_escape (save_style, stream);
                  /* FIXME, this strlen is what prevents wrap_indent from
@@ -1822,7 +1826,12 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream,
          wrap_here ((char *) 0);       /* Spit out chars, cancel
                                           further wraps.  */
          lines_printed++;
-         fputc_unfiltered ('\n', stream);
+         /* XXX: The ideal thing would be to call
+            'stream->putc' here, but we can't because it
+            currently calls 'fputc_unfiltered', which ends up
+            calling us, which generates an infinite
+            recursion.  */
+         stream->puts ("\n");
          lineptr++;
        }
     }
@@ -1836,6 +1845,12 @@ fputs_filtered (const char *linebuffer, struct ui_file *stream)
   fputs_maybe_filtered (linebuffer, stream, 1);
 }
 
+void
+fputs_unfiltered (const char *linebuffer, struct ui_file *stream)
+{
+  fputs_maybe_filtered (linebuffer, stream, 0);
+}
+
 /* See utils.h.  */
 
 void
@@ -1911,10 +1926,7 @@ fputs_highlighted (const char *str, const compiled_regex &highlight,
 int
 putchar_unfiltered (int c)
 {
-  char buf = c;
-
-  ui_file_write (gdb_stdout, &buf, 1);
-  return c;
+  return fputc_unfiltered (c, gdb_stdout);
 }
 
 /* Write character C to gdb_stdout using GDB's paging mechanism and return C.
@@ -1929,9 +1941,11 @@ putchar_filtered (int c)
 int
 fputc_unfiltered (int c, struct ui_file *stream)
 {
-  char buf = c;
+  char buf[2];
 
-  ui_file_write (stream, &buf, 1);
+  buf[0] = c;
+  buf[1] = 0;
+  fputs_unfiltered (buf, stream);
   return c;
 }
 
@@ -3043,21 +3057,10 @@ gdb_argv::reset (const char *s)
 {
   char **argv = buildargv (s);
 
-  if (s != NULL && argv == NULL)
-    malloc_failure (0);
-
   freeargv (m_argv);
   m_argv = argv;
 }
 
-int
-compare_positive_ints (const void *ap, const void *bp)
-{
-  /* Because we know we're comparing two ints which are positive,
-     there's no danger of overflow here.  */
-  return * (int *) ap - * (int *) bp;
-}
-
 #define AMBIGUOUS_MESS1        ".\nMatching formats:"
 #define AMBIGUOUS_MESS2        \
   ".\nUse \"set gnutarget format-name\" to specify the format."
@@ -3106,7 +3109,7 @@ parse_pid_to_attach (const char *args)
   return pid;
 }
 
-/* Substitute all occurences of string FROM by string TO in *STRINGP.  *STRINGP
+/* Substitute all occurrences of string FROM by string TO in *STRINGP.  *STRINGP
    must come from xrealloc-compatible allocator and it may be updated.  FROM
    needs to be delimited by IS_DIR_SEPARATOR or DIRNAME_SEPARATOR (or be
    located at the start or end of *STRINGP.  */
@@ -3436,8 +3439,9 @@ copy_bitwise (gdb_byte *dest, ULONGEST dest_offset,
     }
 }
 
+void _initialize_utils ();
 void
-_initialize_utils (void)
+_initialize_utils ()
 {
   add_setshow_uinteger_cmd ("width", class_support, &chars_per_line, _("\
 Set number of characters where GDB should wrap lines of its output."), _("\
This page took 0.032264 seconds and 4 git commands to generate.