]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/complaints.c
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / complaints.c
CommitLineData
c906108c 1/* Support for complaint handling during symbol reading in GDB.
b9caf505 2
4a94e368 3 Copyright (C) 1990-2022 Free Software Foundation, Inc.
c906108c 4
c5aa993b 5 This file is part of GDB.
c906108c 6
c5aa993b
JM
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
c5aa993b 10 (at your option) any later version.
c906108c 11
c5aa993b
JM
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.
c906108c 16
c5aa993b 17 You should have received a copy of the GNU General Public License
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
19
20#include "defs.h"
d55e5aa6 21#include "complaints.h"
4de283e4 22#include "command.h"
c906108c 23#include "gdbcmd.h"
86fe51fc 24#include "gdbsupport/selftest.h"
4de283e4 25#include <unordered_map>
c906108c 26
ff1cf532 27/* Map format strings to counters. */
c906108c 28
ff1cf532 29static std::unordered_map<const char *, int> counters;
c906108c 30
b9caf505
AC
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. */
34
62d7ae92 35int stop_whining = 0;
b9caf505 36
de54e1a5 37/* See complaints.h. */
b9caf505 38
de54e1a5
TT
39void
40complaint_internal (const char *fmt, ...)
b9caf505 41{
de54e1a5 42 va_list args;
c5504eaf 43
9fdd7193 44 if (++counters[fmt] > stop_whining)
b9caf505
AC
45 return;
46
de54e1a5 47 va_start (args, fmt);
b9caf505 48
7ff88174 49 if (deprecated_warning_hook)
77b64a49 50 (*deprecated_warning_hook) (fmt, args);
b9caf505 51 else
c906108c 52 {
5ca8c39f
TT
53 fputs_filtered (_("During symbol reading: "), gdb_stderr);
54 vfprintf_filtered (gdb_stderr, fmt, args);
55 fputs_filtered ("\n", gdb_stderr);
c906108c 56 }
c906108c 57
b9caf505
AC
58 va_end (args);
59}
60
5ca8c39f 61/* See complaints.h. */
c906108c
SS
62
63void
5ca8c39f 64clear_complaints ()
c906108c 65{
ff1cf532 66 counters.clear ();
c906108c
SS
67}
68
335cca0d 69static void
08546159
AC
70complaints_show_value (struct ui_file *file, int from_tty,
71 struct cmd_list_element *cmd, const char *value)
335cca0d
AC
72{
73 fprintf_filtered (file, _("Max number of complaints about incorrect"
08546159 74 " symbols is %s.\n"),
335cca0d
AC
75 value);
76}
77
86fe51fc
TV
78#if GDB_SELF_TEST
79namespace selftests {
80
81/* Entry point for complaints unit tests. */
82
83static void
84test_complaints ()
85{
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);
89
90#define CHECK_COMPLAINT(STR, CNT) \
91 do \
92 { \
93 std::string output; \
84a6adfd 94 execute_fn_to_string (output, []() { complaint (STR); }, false); \
86fe51fc
TV
95 std::string expected \
96 = _("During symbol reading: ") + std::string (STR "\n"); \
97 SELF_CHECK (output == expected); \
98 SELF_CHECK (counters[STR] == CNT); \
99 } while (0)
100
101#define CHECK_COMPLAINT_SILENT(STR, CNT) \
102 do \
103 { \
104 std::string output; \
84a6adfd 105 execute_fn_to_string (output, []() { complaint (STR); }, false); \
86fe51fc
TV
106 SELF_CHECK (output.empty ()); \
107 SELF_CHECK (counters[STR] == CNT); \
108 } while (0)
109
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);
114 clear_complaints ();
115 CHECK_COMPLAINT ("maintenance complaint 0", 1);
116
117#undef CHECK_COMPLAINT
118#undef CHECK_COMPLAINT_SILENT
119}
120
121
122} // namespace selftests
123#endif /* GDB_SELF_TEST */
124
6c265988 125void _initialize_complaints ();
c906108c 126void
6c265988 127_initialize_complaints ()
c906108c 128{
aff410f1
MS
129 add_setshow_zinteger_cmd ("complaints", class_support,
130 &stop_whining, _("\
3d263c1d 131Set max number of complaints about incorrect symbols."), _("\
335cca0d 132Show max number of complaints about incorrect symbols."), NULL,
08546159 133 NULL, complaints_show_value,
b3f42336 134 &setlist, &showlist);
86fe51fc
TV
135
136#if GDB_SELF_TEST
137 selftests::register_test ("complaints", selftests::test_complaints);
138#endif /* GDB_SELF_TEST */
c906108c 139}