Remove struct complain
[deliverable/binutils-gdb.git] / gdb / complaints.c
1 /* Support for complaint handling during symbol reading in GDB.
2
3 Copyright (C) 1990-2018 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "complaints.h"
22 #include "command.h"
23 #include "gdbcmd.h"
24 #include <unordered_map>
25
26 /* Should each complaint message be self explanatory, or should we
27 assume that a series of complaints is being produced? */
28
29 enum complaint_series {
30 /* Isolated self explanatory message. */
31 ISOLATED_MESSAGE,
32
33 /* First message of a series, but does not need to include any sort
34 of explanation. */
35 SHORT_FIRST_MESSAGE,
36 };
37
38 /* Map format strings to counters. */
39
40 static std::unordered_map<const char *, int> counters;
41
42 struct complaints
43 {
44 enum complaint_series series;
45 };
46
47 static struct complaints symfile_complaint_book = {
48 ISOLATED_MESSAGE
49 };
50
51 /* How many complaints about a particular thing should be printed
52 before we stop whining about it? Default is no whining at all,
53 since so many systems have ill-constructed symbol files. */
54
55 int stop_whining = 0;
56
57 /* See complaints.h. */
58
59 void
60 complaint_internal (const char *fmt, ...)
61 {
62 va_list args;
63 enum complaint_series series;
64
65 if (counters[fmt]++ > stop_whining)
66 return;
67
68 va_start (args, fmt);
69 series = symfile_complaint_book.series;
70
71 if (deprecated_warning_hook)
72 (*deprecated_warning_hook) (fmt, args);
73 else
74 {
75 std::string msg = string_vprintf (fmt, args);
76 wrap_here ("");
77 begin_line ();
78 if (series == ISOLATED_MESSAGE)
79 fprintf_filtered (gdb_stderr, "During symbol reading, %s.\n",
80 msg.c_str ());
81 else
82 fprintf_filtered (gdb_stderr, "%s...", msg.c_str ());
83 }
84
85 /* If GDB dumps core, we'd like to see the complaints first.
86 Presumably GDB will not be sending so many complaints that this
87 becomes a performance hog. */
88
89 gdb_flush (gdb_stderr);
90 va_end (args);
91 }
92
93 /* Clear out / initialize all complaint counters that have ever been
94 incremented. If LESS_VERBOSE is 1, be less verbose about
95 successive complaints, since the messages are appearing all
96 together during a command that is reporting a contiguous block of
97 complaints (rather than being interleaved with other messages). */
98
99 void
100 clear_complaints (int less_verbose)
101 {
102 struct complain *p;
103
104 counters.clear ();
105
106 if (!less_verbose)
107 symfile_complaint_book.series = ISOLATED_MESSAGE;
108 else
109 symfile_complaint_book.series = SHORT_FIRST_MESSAGE;
110 }
111
112 static void
113 complaints_show_value (struct ui_file *file, int from_tty,
114 struct cmd_list_element *cmd, const char *value)
115 {
116 fprintf_filtered (file, _("Max number of complaints about incorrect"
117 " symbols is %s.\n"),
118 value);
119 }
120
121 void
122 _initialize_complaints (void)
123 {
124 add_setshow_zinteger_cmd ("complaints", class_support,
125 &stop_whining, _("\
126 Set max number of complaints about incorrect symbols."), _("\
127 Show max number of complaints about incorrect symbols."), NULL,
128 NULL, complaints_show_value,
129 &setlist, &showlist);
130 }
This page took 0.033158 seconds and 5 git commands to generate.