* sparc64-tdep.h (sparc64_regnum): Fix comment.
[deliverable/binutils-gdb.git] / gdb / utils.c
index e72aec72a2baf113fdb903a598175adfe544f0e1..ae28c04bed9f084b677030b1d368477cf68debe0 100644 (file)
@@ -578,7 +578,7 @@ vwarning (const char *string, va_list args)
       wrap_here ("");          /* Force out any buffered output */
       gdb_flush (gdb_stdout);
       if (warning_pre_print)
-       fprintf_unfiltered (gdb_stderr, warning_pre_print);
+       fputs_unfiltered (warning_pre_print, gdb_stderr);
       vfprintf_unfiltered (gdb_stderr, string, args);
       fprintf_unfiltered (gdb_stderr, "\n");
       va_end (args);
@@ -644,7 +644,7 @@ error_stream (struct ui_file *stream)
   gdb_flush (gdb_stdout);
   annotate_error_begin ();
   if (error_pre_print)
-    fprintf_filtered (gdb_stderr, error_pre_print);
+    fputs_filtered (error_pre_print, gdb_stderr);
   ui_file_put (stream, do_write, gdb_stderr);
   fprintf_filtered (gdb_stderr, "\n");
 
@@ -689,42 +689,49 @@ static void
 internal_vproblem (struct internal_problem *problem,
                   const char *file, int line, const char *fmt, va_list ap)
 {
-  static char msg[] = "Recursive internal problem.\n";
   static int dejavu;
   int quit_p;
   int dump_core_p;
+  char *reason;
 
   /* Don't allow infinite error/warning recursion.  */
-  switch (dejavu)
-    {
-    case 0:
-      dejavu = 1;
-      break;
-    case 1:
-      dejavu = 2;
-      fputs_unfiltered (msg, gdb_stderr);
-      abort ();                        /* NOTE: GDB has only three calls to abort().  */
-    default:
-      dejavu = 3;
-      write (STDERR_FILENO, msg, sizeof (msg));
-      exit (1);
-    }
+  {
+    static char msg[] = "Recursive internal problem.\n";
+    switch (dejavu)
+      {
+      case 0:
+       dejavu = 1;
+       break;
+      case 1:
+       dejavu = 2;
+       fputs_unfiltered (msg, gdb_stderr);
+       abort ();       /* NOTE: GDB has only three calls to abort().  */
+      default:
+       dejavu = 3;
+       write (STDERR_FILENO, msg, sizeof (msg));
+       exit (1);
+      }
+  }
 
   /* Try to get the message out and at the start of a new line.  */
   target_terminal_ours ();
   begin_line ();
 
-  /* The error/warning message.  Format using a style similar to a
-     compiler error message.  */
-  fprintf_unfiltered (gdb_stderr, "%s:%d: %s: ", file, line, problem->name);
-  vfprintf_unfiltered (gdb_stderr, fmt, ap);
-  fputs_unfiltered ("\n", gdb_stderr);
-
-  /* Provide more details so that the user knows that they are living
-     on the edge.  */
-  fprintf_unfiltered (gdb_stderr, "\
-A problem internal to GDB has been detected.  Further\n\
-debugging may prove unreliable.\n");
+  /* Create a string containing the full error/warning message.  Need
+     to call query with this full string, as otherwize the reason
+     (error/warning) and question become separated.  Format using a
+     style similar to a compiler error message.  Include extra detail
+     so that the user knows that they are living on the edge.  */
+  {
+    char *msg;
+    xvasprintf (&msg, fmt, ap);
+    xasprintf (&reason, "\
+%s:%d: %s: %s\n\
+A problem internal to GDB has been detected,\n\
+further debugging may prove unreliable.", file, line, problem->name, msg);
+    xfree (msg);
+    make_cleanup (xfree, reason);
+  }
 
   switch (problem->should_quit)
     {
@@ -732,7 +739,7 @@ debugging may prove unreliable.\n");
       /* Default (yes/batch case) is to quit GDB.  When in batch mode
          this lessens the likelhood of GDB going into an infinate
          loop.  */
-      quit_p = query ("Quit this debugging session? ");
+      quit_p = query ("%s\nQuit this debugging session? ", reason);
       break;
     case AUTO_BOOLEAN_TRUE:
       quit_p = 1;
@@ -750,7 +757,7 @@ debugging may prove unreliable.\n");
       /* Default (yes/batch case) is to dump core.  This leaves a GDB
          `dropping' so that it is easier to see that something went
          wrong in GDB.  */
-      dump_core_p = query ("Create a core file of GDB? ");
+      dump_core_p = query ("%s\nCreate a core file of GDB? ", reason);
       break;
       break;
     case AUTO_BOOLEAN_TRUE:
@@ -915,7 +922,7 @@ quit (void)
 
   /* Don't use *_filtered; we don't want to prompt the user to continue.  */
   if (quit_pre_print)
-    fprintf_unfiltered (gdb_stderr, quit_pre_print);
+    fputs_unfiltered (quit_pre_print, gdb_stderr);
 
 #ifdef __MSDOS__
   /* No steenking SIGINT will ever be coming our way when the
@@ -1073,16 +1080,15 @@ xmmalloc (void *md, size_t size)
 {
   void *val;
 
+  /* See libiberty/xmalloc.c.  This function need's to match that's
+     semantics.  It never returns NULL.  */
   if (size == 0)
-    {
-      val = NULL;
-    }
-  else
-    {
-      val = mmalloc (md, size);
-      if (val == NULL)
-       nomem (size);
-    }
+    size = 1;
+
+  val = mmalloc (md, size);
+  if (val == NULL)
+    nomem (size);
+
   return (val);
 }
 
@@ -1091,27 +1097,18 @@ xmrealloc (void *md, void *ptr, size_t size)
 {
   void *val;
 
+  /* See libiberty/xmalloc.c.  This function need's to match that's
+     semantics.  It never returns NULL.  */
   if (size == 0)
-    {
-      if (ptr != NULL)
-       mfree (md, ptr);
-      val = NULL;
-    }
+    size = 1;
+
+  if (ptr != NULL)
+    val = mrealloc (md, ptr, size);
   else
-    {
-      if (ptr != NULL)
-       {
-         val = mrealloc (md, ptr, size);
-       }
-      else
-       {
-         val = mmalloc (md, size);
-       }
-      if (val == NULL)
-       {
-         nomem (size);
-       }
-    }
+    val = mmalloc (md, size);
+  if (val == NULL)
+    nomem (size);
+
   return (val);
 }
 
@@ -1119,14 +1116,19 @@ void *
 xmcalloc (void *md, size_t number, size_t size)
 {
   void *mem;
+
+  /* See libiberty/xmalloc.c.  This function need's to match that's
+     semantics.  It never returns NULL.  */
   if (number == 0 || size == 0)
-    mem = NULL;
-  else
     {
-      mem = mcalloc (md, number, size);
-      if (mem == NULL)
-       nomem (number * size);
+      number = 1;
+      size = 1;
     }
+
+  mem = mcalloc (md, number, size);
+  if (mem == NULL)
+    nomem (number * size);
+
   return mem;
 }
 
@@ -1176,6 +1178,17 @@ xfree (void *ptr)
 /* Like asprintf/vasprintf but get an internal_error if the call
    fails. */
 
+char *
+xstrprintf (const char *format, ...)
+{
+  char *ret;
+  va_list args;
+  va_start (args, format);
+  xvasprintf (&ret, format, args);
+  va_end (args);
+  return ret;
+}
+
 void
 xasprintf (char **ret, const char *format, ...)
 {
This page took 0.039462 seconds and 4 git commands to generate.