Remove struct complain
[deliverable/binutils-gdb.git] / gdb / complaints.c
index c22d213d602a26cec3514c0d4200b53971ff50c8..2c69b8ca2c9493309e5409eba0c6a9cd1e6e0fa3 100644 (file)
@@ -1,11 +1,12 @@
 /* Support for complaint handling during symbol reading in GDB.
-   Copyright (C) 1990, 1991, 1992  Free Software Foundation, Inc.
+
+   Copyright (C) 1990-2018 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include "defs.h"
 #include "complaints.h"
+#include "command.h"
 #include "gdbcmd.h"
+#include <unordered_map>
 
-extern void _initialize_complaints PARAMS ((void));
+/* Should each complaint message be self explanatory, or should we
+   assume that a series of complaints is being produced?  */
 
-/* Structure to manage complaints about symbol file contents.  */
+enum complaint_series {
+  /* Isolated self explanatory message.  */
+  ISOLATED_MESSAGE,
 
-struct complaint complaint_root[1] =
-{
-  {
-    (char *) NULL,             /* Complaint message */
-    0,                         /* Complaint counter */
-    complaint_root             /* Next complaint. */
-  }
+  /* First message of a series, but does not need to include any sort
+     of explanation.  */
+  SHORT_FIRST_MESSAGE,
 };
 
-/* How many complaints about a particular thing should be printed before
-   we stop whining about it?  Default is no whining at all, since so many
-   systems have ill-constructed symbol files.  */
+/* Map format strings to counters.  */
 
-static unsigned int stop_whining = 0;
+static std::unordered_map<const char *, int> counters;
 
-/* Should each complaint be self explanatory, or should we assume that
-   a series of complaints is being produced? 
-   case 0:  self explanatory message.
-   case 1:  First message of a series that must start off with explanation.
-   case 2:  Subsequent message, when user already knows we are reading
-   symbols and we can just state our piece.  */
-
-static int complaint_series = 0;
+struct complaints
+{
+  enum complaint_series series;
+};
 
-/* External variables and functions referenced. */
+static struct complaints symfile_complaint_book = {
+  ISOLATED_MESSAGE
+};
 
-extern int info_verbose;
-\f
+/* How many complaints about a particular thing should be printed
+   before we stop whining about it?  Default is no whining at all,
+   since so many systems have ill-constructed symbol files.  */
 
-/* Functions to handle complaints during symbol reading.  */
+int stop_whining = 0;
 
-/* Print a complaint about the input symbols, and link the complaint block
-   into a chain for later handling.  */
+/* See complaints.h.  */
 
 void
-complain (struct complaint *complaint,...)
+complaint_internal (const char *fmt, ...)
 {
   va_list args;
-  va_start (args, complaint);
+  enum complaint_series series;
 
-  complaint->counter++;
-  if (complaint->next == NULL)
-    {
-      complaint->next = complaint_root->next;
-      complaint_root->next = complaint;
-    }
-  if (complaint->counter > stop_whining)
-    {
-      return;
-    }
-  wrap_here ("");
+  if (counters[fmt]++ > stop_whining)
+    return;
 
-  switch (complaint_series + (info_verbose << 1))
-    {
+  va_start (args, fmt);
+  series = symfile_complaint_book.series;
 
-      /* Isolated messages, must be self-explanatory.  */
-    case 0:
-      begin_line ();
-      fputs_filtered ("During symbol reading, ", gdb_stderr);
+  if (deprecated_warning_hook)
+    (*deprecated_warning_hook) (fmt, args);
+  else
+    {
+      std::string msg = string_vprintf (fmt, args);
       wrap_here ("");
-      vfprintf_filtered (gdb_stderr, complaint->message, args);
-      fputs_filtered (".\n", gdb_stderr);
-      break;
-
-      /* First of a series, without `set verbose'.  */
-    case 1:
       begin_line ();
-      fputs_filtered ("During symbol reading...", gdb_stderr);
-      vfprintf_filtered (gdb_stderr, complaint->message, args);
-      fputs_filtered ("...", gdb_stderr);
-      wrap_here ("");
-      complaint_series++;
-      break;
-
-      /* Subsequent messages of a series, or messages under `set verbose'.
-         (We'll already have produced a "Reading in symbols for XXX..."
-         message and will clean up at the end with a newline.)  */
-    default:
-      vfprintf_filtered (gdb_stderr, complaint->message, args);
-      fputs_filtered ("...", gdb_stderr);
-      wrap_here ("");
+      if (series == ISOLATED_MESSAGE)
+       fprintf_filtered (gdb_stderr, "During symbol reading, %s.\n",
+                         msg.c_str ());
+      else
+       fprintf_filtered (gdb_stderr, "%s...", msg.c_str ());
     }
-  /* If GDB dumps core, we'd like to see the complaints first.  Presumably
-     GDB will not be sending so many complaints that this becomes a
-     performance hog.  */
+
+  /* If GDB dumps core, we'd like to see the complaints first.
+     Presumably GDB will not be sending so many complaints that this
+     becomes a performance hog.  */
+
   gdb_flush (gdb_stderr);
   va_end (args);
 }
 
-/* Clear out all complaint counters that have ever been incremented.
-   If sym_reading is 1, be less verbose about successive complaints,
-   since the messages are appearing all together during a command that
-   reads symbols (rather than scattered around as psymtabs get fleshed
-   out into symtabs at random times).  If noisy is 1, we are in a
-   noisy symbol reading command, and our caller will print enough
-   context for the user to figure it out.  */
+/* Clear out / initialize all complaint counters that have ever been
+   incremented.  If LESS_VERBOSE is 1, be less verbose about
+   successive complaints, since the messages are appearing all
+   together during a command that is reporting a contiguous block of
+   complaints (rather than being interleaved with other messages).  */
 
 void
-clear_complaints (sym_reading, noisy)
-     int sym_reading;
-     int noisy;
+clear_complaints (int less_verbose)
 {
-  struct complaint *p;
+  struct complain *p;
 
-  for (p = complaint_root->next; p != complaint_root; p = p->next)
-    {
-      p->counter = 0;
-    }
+  counters.clear ();
 
-  if (!sym_reading && !noisy && complaint_series > 1)
-    {
-      /* Terminate previous series, since caller won't.  */
-      puts_filtered ("\n");
-    }
+  if (!less_verbose)
+    symfile_complaint_book.series = ISOLATED_MESSAGE;
+  else
+    symfile_complaint_book.series = SHORT_FIRST_MESSAGE;
+}
 
-  complaint_series = sym_reading ? 1 + noisy : 0;
+static void
+complaints_show_value (struct ui_file *file, int from_tty,
+                      struct cmd_list_element *cmd, const char *value)
+{
+  fprintf_filtered (file, _("Max number of complaints about incorrect"
+                           " symbols is %s.\n"),
+                   value);
 }
 
 void
-_initialize_complaints ()
+_initialize_complaints (void)
 {
-  add_show_from_set
-    (add_set_cmd ("complaints", class_support, var_zinteger,
-                 (char *) &stop_whining,
-                 "Set max number of complaints about incorrect symbols.",
-                 &setlist),
-     &showlist);
-
+  add_setshow_zinteger_cmd ("complaints", class_support, 
+                           &stop_whining, _("\
+Set max number of complaints about incorrect symbols."), _("\
+Show max number of complaints about incorrect symbols."), NULL,
+                           NULL, complaints_show_value,
+                           &setlist, &showlist);
 }
This page took 0.028415 seconds and 4 git commands to generate.