/* Support for complaint handling during symbol reading in GDB.
- Copyright (C) 1990-2018 Free Software Foundation, Inc.
+ Copyright (C) 1990-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "complaints.h"
#include "command.h"
#include "gdbcmd.h"
+#include "gdbsupport/selftest.h"
#include <unordered_map>
-/* Should each complaint message be self explanatory, or should we
- assume that a series of complaints is being produced? */
-
-enum complaint_series {
- /* Isolated self explanatory message. */
- ISOLATED_MESSAGE,
-
- /* First message of a series, but does not need to include any sort
- of explanation. */
- SHORT_FIRST_MESSAGE,
-};
-
/* Map format strings to counters. */
static std::unordered_map<const char *, int> counters;
-/* How to print the next complaint. */
-
-static complaint_series series;
-
/* 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. */
{
va_list args;
- if (counters[fmt]++ > stop_whining)
+ if (++counters[fmt] > stop_whining)
return;
va_start (args, fmt);
(*deprecated_warning_hook) (fmt, args);
else
{
- std::string msg = string_vprintf (fmt, args);
- wrap_here ("");
- begin_line ();
- 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 ());
+ fputs_filtered (_("During symbol reading: "), gdb_stderr);
+ vfprintf_filtered (gdb_stderr, fmt, args);
+ fputs_filtered ("\n", gdb_stderr);
}
- /* 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 / 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). */
+/* See complaints.h. */
void
-clear_complaints (int less_verbose)
+clear_complaints ()
{
counters.clear ();
-
- if (!less_verbose)
- series = ISOLATED_MESSAGE;
- else
- series = SHORT_FIRST_MESSAGE;
}
static void
value);
}
+#if GDB_SELF_TEST
+namespace selftests {
+
+/* Entry point for complaints unit tests. */
+
+static void
+test_complaints ()
+{
+ std::unordered_map<const char *, int> tmp;
+ scoped_restore reset_counters = make_scoped_restore (&counters, tmp);
+ scoped_restore reset_stop_whining = make_scoped_restore (&stop_whining, 2);
+
+#define CHECK_COMPLAINT(STR, CNT) \
+ do \
+ { \
+ std::string output; \
+ execute_fn_to_string (output, []() { complaint (STR); }, false); \
+ std::string expected \
+ = _("During symbol reading: ") + std::string (STR "\n"); \
+ SELF_CHECK (output == expected); \
+ SELF_CHECK (counters[STR] == CNT); \
+ } while (0)
+
+#define CHECK_COMPLAINT_SILENT(STR, CNT) \
+ do \
+ { \
+ std::string output; \
+ execute_fn_to_string (output, []() { complaint (STR); }, false); \
+ SELF_CHECK (output.empty ()); \
+ SELF_CHECK (counters[STR] == CNT); \
+ } while (0)
+
+ CHECK_COMPLAINT ("maintenance complaint 0", 1);
+ CHECK_COMPLAINT ("maintenance complaint 0", 2);
+ CHECK_COMPLAINT_SILENT ("maintenance complaint 0", 3);
+ CHECK_COMPLAINT ("maintenance complaint 1", 1);
+ clear_complaints ();
+ CHECK_COMPLAINT ("maintenance complaint 0", 1);
+
+#undef CHECK_COMPLAINT
+#undef CHECK_COMPLAINT_SILENT
+}
+
+
+} // namespace selftests
+#endif /* GDB_SELF_TEST */
+
+void _initialize_complaints ();
void
-_initialize_complaints (void)
+_initialize_complaints ()
{
add_setshow_zinteger_cmd ("complaints", class_support,
&stop_whining, _("\
Show max number of complaints about incorrect symbols."), NULL,
NULL, complaints_show_value,
&setlist, &showlist);
+
+#if GDB_SELF_TEST
+ selftests::register_test ("complaints", selftests::test_complaints);
+#endif /* GDB_SELF_TEST */
}