Perform all tests in callfuncs.exp with and without C function prototypes
[deliverable/binutils-gdb.git] / gdb / utils.c
index 23055ce0cc11ae6ea2bddaeb96778cc8b57a9566..3915b58c047499ada2bbdf8ede3174a06316e5ac 100644 (file)
 
 #include "defs.h"
 #include "dyn-string.h"
-#include "gdb_assert.h"
 #include <ctype.h>
-#include <string.h>
 #include "gdb_wait.h"
 #include "event-top.h"
-#include "exceptions.h"
 #include "gdbthread.h"
 #include "fnmatch.h"
 #include "gdb_bfd.h"
@@ -522,8 +519,10 @@ vwarning (const char *string, va_list args)
     (*deprecated_warning_hook) (string, args);
   else
     {
-      target_terminal_ours ();
-      wrap_here ("");          /* Force out any buffered output.  */
+      if (target_supports_terminal_ours ())
+       target_terminal_ours ();
+      if (filtered_printing_initialized ())
+       wrap_here ("");         /* Force out any buffered output.  */
       gdb_flush (gdb_stdout);
       if (warning_pre_print)
        fputs_unfiltered (warning_pre_print, gdb_stderr);
@@ -532,22 +531,6 @@ vwarning (const char *string, va_list args)
     }
 }
 
-/* Print a warning message.
-   The first argument STRING is the warning message, used as a fprintf string,
-   and the remaining args are passed as arguments to it.
-   The primary difference between warnings and errors is that a warning
-   does not force the return to command level.  */
-
-void
-warning (const char *string, ...)
-{
-  va_list args;
-
-  va_start (args, string);
-  vwarning (string, args);
-  va_end (args);
-}
-
 /* Print an error message and return to command level.
    The first argument STRING is the error message, used as a fprintf string,
    and the remaining args are passed as arguments to it.  */
@@ -558,16 +541,6 @@ verror (const char *string, va_list args)
   throw_verror (GENERIC_ERROR, string, args);
 }
 
-void
-error (const char *string, ...)
-{
-  va_list args;
-
-  va_start (args, string);
-  throw_verror (GENERIC_ERROR, string, args);
-  va_end (args);
-}
-
 void
 error_stream (struct ui_file *stream)
 {
@@ -577,6 +550,19 @@ error_stream (struct ui_file *stream)
   error (("%s"), message);
 }
 
+/* Emit a message and abort.  */
+
+static void ATTRIBUTE_NORETURN
+abort_with_message (const char *msg)
+{
+  if (gdb_stderr == NULL)
+    fputs (msg, stderr);
+  else
+    fputs_unfiltered (msg, gdb_stderr);
+
+  abort ();            /* NOTE: GDB has only three calls to abort().  */
+}
+
 /* Dump core trying to increase the core soft limit to hard limit first.  */
 
 void
@@ -699,8 +685,7 @@ internal_vproblem (struct internal_problem *problem,
        break;
       case 1:
        dejavu = 2;
-       fputs_unfiltered (msg, gdb_stderr);
-       abort ();       /* NOTE: GDB has only three calls to abort().  */
+       abort_with_message (msg);
       default:
        dejavu = 3;
         /* Newer GLIBC versions put the warn_unused_result attribute
@@ -714,10 +699,6 @@ internal_vproblem (struct internal_problem *problem,
       }
   }
 
-  /* Try to get the message out and at the start of a new line.  */
-  target_terminal_ours ();
-  begin_line ();
-
   /* 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
@@ -735,18 +716,32 @@ internal_vproblem (struct internal_problem *problem,
     make_cleanup (xfree, reason);
   }
 
+  /* Fall back to abort_with_message if gdb_stderr is not set up.  */
+  if (gdb_stderr == NULL)
+    {
+      fputs (reason, stderr);
+      abort_with_message ("\n");
+    }
+
+  /* Try to get the message out and at the start of a new line.  */
+  if (target_supports_terminal_ours ())
+    target_terminal_ours ();
+  if (filtered_printing_initialized ())
+    begin_line ();
+
+  /* Emit the message unless query will emit it below.  */
+  if (problem->should_quit != internal_problem_ask
+      || !confirm
+      || !filtered_printing_initialized ())
+    fprintf_unfiltered (gdb_stderr, "%s\n", reason);
+
   if (problem->should_quit == internal_problem_ask)
     {
       /* Default (yes/batch case) is to quit GDB.  When in batch mode
         this lessens the likelihood of GDB going into an infinite
         loop.  */
-      if (!confirm)
-        {
-          /* Emit the message and quit.  */
-          fputs_unfiltered (reason, gdb_stderr);
-          fputs_unfiltered ("\n", gdb_stderr);
-          quit_p = 1;
-        }
+      if (!confirm || !filtered_printing_initialized ())
+       quit_p = 1;
       else
         quit_p = query (_("%s\nQuit this debugging session? "), reason);
     }
@@ -767,6 +762,8 @@ internal_vproblem (struct internal_problem *problem,
     {
       if (!can_dump_core_warn (LIMIT_MAX, reason))
        dump_core_p = 0;
+      else if (!filtered_printing_initialized ())
+       dump_core_p = 1;
       else
        {
          /* Default (yes/batch case) is to dump core.  This leaves a GDB
@@ -815,16 +812,6 @@ internal_verror (const char *file, int line, const char *fmt, va_list ap)
   throw_quit (_("Command aborted."));
 }
 
-void
-internal_error (const char *file, int line, const char *string, ...)
-{
-  va_list ap;
-
-  va_start (ap, string);
-  internal_verror (file, line, string, ap);
-  va_end (ap);
-}
-
 static struct internal_problem internal_warning_problem = {
   "internal-warning", 1, internal_problem_ask, 1, internal_problem_ask
 };
@@ -835,16 +822,6 @@ internal_vwarning (const char *file, int line, const char *fmt, va_list ap)
   internal_vproblem (&internal_warning_problem, file, line, fmt, ap);
 }
 
-void
-internal_warning (const char *file, int line, const char *string, ...)
-{
-  va_list ap;
-
-  va_start (ap, string);
-  internal_vwarning (file, line, string, ap);
-  va_end (ap);
-}
-
 static struct internal_problem demangler_warning_problem = {
   "demangler-warning", 1, internal_problem_ask, 0, internal_problem_no
 };
@@ -1739,6 +1716,13 @@ init_page_info (void)
   set_width ();
 }
 
+/* Return nonzero if filtered printing is initialized.  */
+int
+filtered_printing_initialized (void)
+{
+  return wrap_buffer != NULL;
+}
+
 /* Helper for make_cleanup_restore_page_info.  */
 
 static void
This page took 0.039446 seconds and 4 git commands to generate.