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 = {
87 static struct complain * ATTRIBUTE_PRINTF (4, 0)
88 find_complaint (struct complaints *complaints, const char *file,
89 int line, const char *fmt)
91 struct complain *complaint;
93 /* Find the complaint in the table. A more efficient search
94 algorithm (based on hash table or something) could be used. But
95 that can wait until someone shows evidence that this lookup is
96 a real bottle neck. */
97 for (complaint = complaints->root;
99 complaint = complaint->next)
101 if (complaint->fmt == fmt
102 && complaint->file == file
103 && complaint->line == line)
107 /* Oops not seen before, fill in a new complaint. */
108 complaint = XNEW (struct complain);
109 complaint->fmt = fmt;
110 complaint->file = file;
111 complaint->line = line;
112 complaint->counter = 0;
113 complaint->next = NULL;
115 /* File it, return it. */
116 complaint->next = complaints->root;
117 complaints->root = complaint;
122 /* How many complaints about a particular thing should be printed
123 before we stop whining about it? Default is no whining at all,
124 since so many systems have ill-constructed symbol files. */
126 int stop_whining = 0;
128 /* Print a complaint, and link the complaint block into a chain for
131 static void ATTRIBUTE_PRINTF (3, 0)
132 vcomplaint (const char *file,
133 int line, const char *fmt,
136 struct complain *complaint = find_complaint (&symfile_complaint_book, file,
138 enum complaint_series series;
140 complaint->counter++;
141 if (complaint->counter > stop_whining)
144 series = symfile_complaint_book.series;
146 /* Pass 'fmt' instead of 'complaint->fmt' to printf-like callees
147 from here on, to avoid "format string is not a string literal"
148 warnings. 'fmt' is this function's printf-format parameter, so
149 the compiler can assume the passed in argument is a literal
150 string somewhere up the call chain. */
151 gdb_assert (complaint->fmt == fmt);
153 if (complaint->file != NULL)
154 internal_vwarning (complaint->file, complaint->line, fmt, args);
155 else if (deprecated_warning_hook)
156 (*deprecated_warning_hook) (fmt, args);
159 if (symfile_complaint_book.explanation == NULL)
160 /* A [v]warning() call always appends a newline. */
161 vwarning (fmt, args);
164 std::string msg = string_vprintf (fmt, args);
168 fprintf_filtered (gdb_stderr, "%s%s%s",
169 symfile_complaint_book.explanation[series].prefix,
171 symfile_complaint_book.explanation[series].postfix);
172 /* Force a line-break after any isolated message. */
173 if (series == ISOLATED_MESSAGE)
174 /* It would be really nice to use begin_line() here.
175 Unfortunately that function doesn't track GDB_STDERR and
176 consequently will sometimes supress a line when it
178 fputs_filtered ("\n", gdb_stderr);
184 /* If GDB dumps core, we'd like to see the complaints first.
185 Presumably GDB will not be sending so many complaints that this
186 becomes a performance hog. */
188 gdb_flush (gdb_stderr);
192 complaint_internal (const char *fmt, ...)
196 va_start (args, fmt);
197 vcomplaint (NULL/*file*/, 0/*line*/, fmt, args);
201 /* Clear out / initialize all complaint counters that have ever been
202 incremented. If LESS_VERBOSE is 1, be less verbose about
203 successive complaints, since the messages are appearing all
204 together during a command that is reporting a contiguous block of
205 complaints (rather than being interleaved with other messages). */
208 clear_complaints (int less_verbose)
212 for (p = symfile_complaint_book.root; p != NULL; p = p->next)
218 symfile_complaint_book.series = ISOLATED_MESSAGE;
220 symfile_complaint_book.series = SHORT_FIRST_MESSAGE;
224 complaints_show_value (struct ui_file *file, int from_tty,
225 struct cmd_list_element *cmd, const char *value)
227 fprintf_filtered (file, _("Max number of complaints about incorrect"
228 " symbols is %s.\n"),
233 _initialize_complaints (void)
235 add_setshow_zinteger_cmd ("complaints", class_support,
237 Set max number of complaints about incorrect symbols."), _("\
238 Show max number of complaints about incorrect symbols."), NULL,
239 NULL, complaints_show_value,
240 &setlist, &showlist);