2019-12-18 Anthony Green <green@moxielogic.com>
[deliverable/binutils-gdb.git] / gdb / gdbserver / utils.c
index ec37a9bc1c34b5294b816ff1b24a7877fcaf562f..b72dd0ec2b2c9bd35bc1dd01a6b5f1d375345abf 100644 (file)
@@ -1,5 +1,5 @@
 /* General utility routines for the remote server for GDB.
-   Copyright (C) 1986-2014 Free Software Foundation, Inc.
+   Copyright (C) 1986-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -17,9 +17,6 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "server.h"
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
 
 #ifdef IN_PROCESS_AGENT
 #  define PREFIX "ipa: "
@@ -40,18 +37,6 @@ malloc_failure (long size)
   exit (1);
 }
 
-/* Copy a string into a memory buffer.
-   If malloc fails, this will print a message to stderr and exit.  */
-
-char *
-xstrdup (const char *s)
-{
-  char *ret = strdup (s);
-  if (ret == NULL)
-    malloc_failure (strlen (s) + 1);
-  return ret;
-}
-
 /* Print the system error message for errno, and also mention STRING
    as the file name for which the error was encountered.
    Then return to command level.  */
@@ -62,7 +47,7 @@ perror_with_name (const char *string)
   const char *err;
   char *combined;
 
-  err = strerror (errno);
+  err = safe_strerror (errno);
   if (err == NULL)
     err = "unknown error";
 
@@ -74,71 +59,50 @@ perror_with_name (const char *string)
   error ("%s.", combined);
 }
 
-/* Print an error message and return to command level.
-   STRING is the error message, used as a fprintf string,
-   and ARG is passed as an argument to it.  */
+/* Print an error message and return to top level.  */
 
 void
-error (const char *string,...)
+verror (const char *string, va_list args)
 {
-#ifndef IN_PROCESS_AGENT
-  extern jmp_buf toplevel;
-#endif
-  va_list args;
-  va_start (args, string);
+#ifdef IN_PROCESS_AGENT
   fflush (stdout);
   vfprintf (stderr, string, args);
   fprintf (stderr, "\n");
-#ifndef IN_PROCESS_AGENT
-  longjmp (toplevel, 1);
-#else
   exit (1);
+#else
+  throw_verror (GENERIC_ERROR, string, args);
 #endif
 }
 
-/* Print an error message and exit reporting failure.
-   This is for a error that we cannot continue from.
-   STRING and ARG are passed to fprintf.  */
-
-/* VARARGS */
 void
-fatal (const char *string,...)
+vwarning (const char *string, va_list args)
 {
-  va_list args;
-  va_start (args, string);
   fprintf (stderr, PREFIX);
   vfprintf (stderr, string, args);
   fprintf (stderr, "\n");
-  va_end (args);
-  exit (1);
 }
 
-/* VARARGS */
+/* Report a problem internal to GDBserver, and exit.  */
+
 void
-warning (const char *string,...)
+internal_verror (const char *file, int line, const char *fmt, va_list args)
 {
-  va_list args;
-  va_start (args, string);
-  fprintf (stderr, PREFIX);
-  vfprintf (stderr, string, args);
+  fprintf (stderr,  "\
+%s:%d: A problem internal to " TOOLNAME " has been detected.\n", file, line);
+  vfprintf (stderr, fmt, args);
   fprintf (stderr, "\n");
-  va_end (args);
+  exit (1);
 }
 
-/* Report a problem internal to GDBserver, and exit.  */
+/* Report a problem internal to GDBserver.  */
 
 void
-internal_error (const char *file, int line, const char *fmt, ...)
+internal_vwarning (const char *file, int line, const char *fmt, va_list args)
 {
-  va_list args;
-  va_start (args, fmt);
-
   fprintf (stderr,  "\
 %s:%d: A problem internal to " TOOLNAME " has been detected.\n", file, line);
   vfprintf (stderr, fmt, args);
   fprintf (stderr, "\n");
-  va_end (args);
-  exit (1);
 }
 
 /* Convert a CORE_ADDR into a HEX string, like %lx.
This page took 0.025736 seconds and 4 git commands to generate.