1 /* Support for complaint handling during symbol reading in GDB.
3 Copyright (C) 1990-2018 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"
25 /* Should each complaint message be self explanatory, or should we
26 assume that a series of complaints is being produced? */
28 enum complaint_series {
29 /* Isolated self explanatory message. */
32 /* First message of a series, but does not need to include any sort
37 /* Structure to manage complaints about symbol file contents. */
45 struct complain *next;
48 /* The explanatory message that should accompany the complaint. The
49 message is in two parts - pre and post - that are printed around
50 the complaint text. */
59 struct complain *root;
61 enum complaint_series series;
63 /* The explanatory messages that should accompany the complaint.
64 NOTE: cagney/2002-08-14: In a desperate attempt at being vaguely
65 i18n friendly, this is an array of two messages. When present,
66 the PRE and POST EXPLANATION[SERIES] are used to wrap the
68 const struct explanation *explanation;
71 static struct complain complaint_sentinel;
73 /* The symbol table complaint table. */
75 static struct explanation symfile_explanations[] = {
76 { "During symbol reading, ", "." },
81 static struct complaints symfile_complaint_book = {
86 struct complaints *symfile_complaints = &symfile_complaint_book;
88 /* Wrapper function to, on-demand, fill in a complaints object. */
90 static struct complaints *
91 get_complaints (struct complaints **c)
95 (*c) = XNEW (struct complaints);
96 (*c)->root = &complaint_sentinel;
97 (*c)->series = ISOLATED_MESSAGE;
98 (*c)->explanation = NULL;
102 static struct complain * ATTRIBUTE_PRINTF (4, 0)
103 find_complaint (struct complaints *complaints, const char *file,
104 int line, const char *fmt)
106 struct complain *complaint;
108 /* Find the complaint in the table. A more efficient search
109 algorithm (based on hash table or something) could be used. But
110 that can wait until someone shows evidence that this lookup is
111 a real bottle neck. */
112 for (complaint = complaints->root;
114 complaint = complaint->next)
116 if (complaint->fmt == fmt
117 && complaint->file == file
118 && complaint->line == line)
122 /* Oops not seen before, fill in a new complaint. */
123 complaint = XNEW (struct complain);
124 complaint->fmt = fmt;
125 complaint->file = file;
126 complaint->line = line;
127 complaint->counter = 0;
128 complaint->next = NULL;
130 /* File it, return it. */
131 complaint->next = complaints->root;
132 complaints->root = complaint;
137 /* How many complaints about a particular thing should be printed
138 before we stop whining about it? Default is no whining at all,
139 since so many systems have ill-constructed symbol files. */
141 int stop_whining = 0;
143 /* Print a complaint, and link the complaint block into a chain for
146 static void ATTRIBUTE_PRINTF (4, 0)
147 vcomplaint (struct complaints **c, const char *file,
148 int line, const char *fmt,
151 struct complaints *complaints = get_complaints (c);
152 struct complain *complaint = find_complaint (complaints, file,
154 enum complaint_series series;
156 gdb_assert (complaints != NULL);
158 complaint->counter++;
159 if (complaint->counter > stop_whining)
162 series = complaints->series;
164 /* Pass 'fmt' instead of 'complaint->fmt' to printf-like callees
165 from here on, to avoid "format string is not a string literal"
166 warnings. 'fmt' is this function's printf-format parameter, so
167 the compiler can assume the passed in argument is a literal
168 string somewhere up the call chain. */
169 gdb_assert (complaint->fmt == fmt);
171 if (complaint->file != NULL)
172 internal_vwarning (complaint->file, complaint->line, fmt, args);
173 else if (deprecated_warning_hook)
174 (*deprecated_warning_hook) (fmt, args);
177 if (complaints->explanation == NULL)
178 /* A [v]warning() call always appends a newline. */
179 vwarning (fmt, args);
182 std::string msg = string_vprintf (fmt, args);
186 fprintf_filtered (gdb_stderr, "%s%s%s",
187 complaints->explanation[series].prefix,
189 complaints->explanation[series].postfix);
190 /* Force a line-break after any isolated message. */
191 if (series == ISOLATED_MESSAGE)
192 /* It would be really nice to use begin_line() here.
193 Unfortunately that function doesn't track GDB_STDERR and
194 consequently will sometimes supress a line when it
196 fputs_filtered ("\n", gdb_stderr);
202 /* If GDB dumps core, we'd like to see the complaints first.
203 Presumably GDB will not be sending so many complaints that this
204 becomes a performance hog. */
206 gdb_flush (gdb_stderr);
210 complaint_internal (struct complaints **complaints, const char *fmt, ...)
214 va_start (args, fmt);
215 vcomplaint (complaints, NULL/*file*/, 0/*line*/, fmt, args);
219 /* Clear out / initialize all complaint counters that have ever been
220 incremented. If LESS_VERBOSE is 1, be less verbose about
221 successive complaints, since the messages are appearing all
222 together during a command that is reporting a contiguous block of
223 complaints (rather than being interleaved with other messages). If
224 noisy is 1, we are in a noisy command, and our caller will print
225 enough context for the user to figure it out. */
228 clear_complaints (struct complaints **c, int less_verbose, int noisy)
230 struct complaints *complaints = get_complaints (c);
233 for (p = complaints->root; p != NULL; p = p->next)
239 complaints->series = ISOLATED_MESSAGE;
241 complaints->series = SHORT_FIRST_MESSAGE;
245 complaints_show_value (struct ui_file *file, int from_tty,
246 struct cmd_list_element *cmd, const char *value)
248 fprintf_filtered (file, _("Max number of complaints about incorrect"
249 " symbols is %s.\n"),
254 _initialize_complaints (void)
256 add_setshow_zinteger_cmd ("complaints", class_support,
258 Set max number of complaints about incorrect symbols."), _("\
259 Show max number of complaints about incorrect symbols."), NULL,
260 NULL, complaints_show_value,
261 &setlist, &showlist);