1 /* Support for complaint handling during symbol reading in GDB.
3 Copyright (C) 1990-2022 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "complaints.h"
24 #include "gdbsupport/selftest.h"
25 #include <unordered_map>
27 /* Map format strings to counters. */
29 static std::unordered_map
<const char *, int> counters
;
31 /* How many complaints about a particular thing should be printed
32 before we stop whining about it? Default is no whining at all,
33 since so many systems have ill-constructed symbol files. */
37 /* See complaints.h. */
40 complaint_internal (const char *fmt
, ...)
44 if (++counters
[fmt
] > stop_whining
)
49 if (deprecated_warning_hook
)
50 (*deprecated_warning_hook
) (fmt
, args
);
53 fputs_filtered (_("During symbol reading: "), gdb_stderr
);
54 vfprintf_filtered (gdb_stderr
, fmt
, args
);
55 fputs_filtered ("\n", gdb_stderr
);
61 /* See complaints.h. */
70 complaints_show_value (struct ui_file
*file
, int from_tty
,
71 struct cmd_list_element
*cmd
, const char *value
)
73 fprintf_filtered (file
, _("Max number of complaints about incorrect"
81 /* Entry point for complaints unit tests. */
86 std::unordered_map
<const char *, int> tmp
;
87 scoped_restore reset_counters
= make_scoped_restore (&counters
, tmp
);
88 scoped_restore reset_stop_whining
= make_scoped_restore (&stop_whining
, 2);
90 #define CHECK_COMPLAINT(STR, CNT) \
94 execute_fn_to_string (output, []() { complaint (STR); }, false); \
95 std::string expected \
96 = _("During symbol reading: ") + std::string (STR "\n"); \
97 SELF_CHECK (output == expected); \
98 SELF_CHECK (counters[STR] == CNT); \
101 #define CHECK_COMPLAINT_SILENT(STR, CNT) \
104 std::string output; \
105 execute_fn_to_string (output, []() { complaint (STR); }, false); \
106 SELF_CHECK (output.empty ()); \
107 SELF_CHECK (counters[STR] == CNT); \
110 CHECK_COMPLAINT ("maintenance complaint 0", 1);
111 CHECK_COMPLAINT ("maintenance complaint 0", 2);
112 CHECK_COMPLAINT_SILENT ("maintenance complaint 0", 3);
113 CHECK_COMPLAINT ("maintenance complaint 1", 1);
115 CHECK_COMPLAINT ("maintenance complaint 0", 1);
117 #undef CHECK_COMPLAINT
118 #undef CHECK_COMPLAINT_SILENT
122 } // namespace selftests
123 #endif /* GDB_SELF_TEST */
125 void _initialize_complaints ();
127 _initialize_complaints ()
129 add_setshow_zinteger_cmd ("complaints", class_support
,
131 Set max number of complaints about incorrect symbols."), _("\
132 Show max number of complaints about incorrect symbols."), NULL
,
133 NULL
, complaints_show_value
,
134 &setlist
, &showlist
);
137 selftests::register_test ("complaints", selftests::test_complaints
);
138 #endif /* GDB_SELF_TEST */