1 /* Support for complaint handling during symbol reading in GDB.
3 Copyright 1990, 1991, 1992, 1993, 1995, 1998, 1999, 2000, 2002 Free
4 Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #include "complaints.h"
25 #include "gdb_assert.h"
29 extern void _initialize_complaints (void);
31 /* Should each complaint message be self explanatory, or should we assume that
32 a series of complaints is being produced? */
34 /* case 1: First message of a series that must
35 start off with explanation. case 2: Subsequent message of a series
36 that needs no explanation (the user already knows we have a problem
37 so we can just state our piece). */
38 enum complaint_series {
39 /* Isolated self explanatory message. */
41 /* First message of a series, includes an explanation. */
43 /* First message of a series, but does not need to include any sort
46 /* Subsequent message of a series that needs no explanation (the
47 user already knows we have a problem so we can just state our
52 /* Structure to manage complaints about symbol file contents. */
60 struct complain *next;
65 struct complain *root;
67 /* Should each complaint be self explanatory, or should we assume
68 that a series of complaints is being produced? case 0: Isolated
69 self explanatory message. case 1: First message of a series that
70 must start off with explanation. case 2: Subsequent message of a
71 series that needs no explanation (the user already knows we have
72 a problem so we can just state our piece). */
75 /* The explanatory messages that should accompany the complaint.
76 NOTE: cagney/2002-08-14: In a desperate attempt at being vaguely
77 i18n friendly, this is an array of two messages. When present,
78 EXPLANATION[SERIES] is used to wrap the message. */
79 const char **explanation;
82 static struct complain complaint_sentinel;
84 /* The symbol table complaint table. */
86 static const char *symfile_explanations[] = {
87 "During symbol reading, %s.",
88 "During symbol reading...%s...",
94 static struct complaints symfile_complaint_book = {
99 struct complaints *symfile_complaints = &symfile_complaint_book;
101 /* Wrapper function to, on-demand, fill in a complaints object. */
103 static struct complaints *
104 get_complaints (struct complaints **c)
108 (*c) = XMALLOC (struct complaints);
109 (*c)->root = &complaint_sentinel;
110 (*c)->series = ISOLATED_MESSAGE;
111 (*c)->explanation = NULL;
115 static struct complain *
116 find_complaint (struct complaints *complaints, const char *file,
117 int line, const char *fmt)
119 struct complain *complaint;
121 /* Find the complaint in the table. A more efficient search
122 algorithm (based on hash table or something) could be used. But
123 that can wait until someone shows evidence that this lookup is
124 a real bottle neck. */
125 for (complaint = complaints->root;
127 complaint = complaint->next)
129 if (complaint->fmt == fmt
130 && complaint->file == file
131 && complaint->line == line)
135 /* Oops not seen before, fill in a new complaint. */
136 complaint = XMALLOC (struct complain);
137 complaint->fmt = fmt;
138 complaint->file = file;
139 complaint->line = line;
140 complaint->counter = 0;
141 complaint->next = NULL;
143 /* File it, return it. */
144 complaint->next = complaints->root;
145 complaints->root = complaint;
150 /* How many complaints about a particular thing should be printed
151 before we stop whining about it? Default is no whining at all,
152 since so many systems have ill-constructed symbol files. */
154 static unsigned int stop_whining = 0;
156 /* Print a complaint, and link the complaint block into a chain for
160 vcomplaint (struct complaints **c, const char *file, int line, const char *fmt,
163 struct complaints *complaints = get_complaints (c);
164 struct complain *complaint = find_complaint (complaints, file, line, fmt);
165 enum complaint_series series;
166 gdb_assert (complaints != NULL);
168 complaint->counter++;
169 if (complaint->counter > stop_whining)
173 series = SUBSEQUENT_MESSAGE;
175 series = complaints->series;
177 if (complaint->file != NULL)
178 internal_vwarning (complaint->file, complaint->line, complaint->fmt, args);
179 else if (warning_hook)
180 (*warning_hook) (complaint->fmt, args);
183 if (complaints->explanation == NULL)
184 /* A [v]warning() call always appends a newline. */
185 vwarning (complaint->fmt, args);
189 struct cleanup *cleanups;
190 xvasprintf (&msg, complaint->fmt, args);
191 cleanups = make_cleanup (xfree, msg);
193 if (series != SUBSEQUENT_MESSAGE)
195 fprintf_filtered (gdb_stderr,
196 complaints->explanation[series],
198 /* Force a line-break after any isolated message. For the
199 other cases, clear_complaints() takes care of any missing
200 trailing newline, the wrap_here() is just a hint. */
201 if (series == ISOLATED_MESSAGE)
202 /* It would be really nice to use begin_line() here.
203 Unfortunatly that function doesn't track GDB_STDERR and
204 consequently will sometimes supress a line when it
206 fputs_filtered ("\n", gdb_stderr);
209 do_cleanups (cleanups);
215 case ISOLATED_MESSAGE:
218 complaints->series = SUBSEQUENT_MESSAGE;
220 case SUBSEQUENT_MESSAGE:
221 case SHORT_FIRST_MESSAGE:
222 complaints->series = SUBSEQUENT_MESSAGE;
226 /* If GDB dumps core, we'd like to see the complaints first.
227 Presumably GDB will not be sending so many complaints that this
228 becomes a performance hog. */
230 gdb_flush (gdb_stderr);
234 complaint (struct complaints **complaints, const char *fmt, ...)
237 va_start (args, fmt);
238 vcomplaint (complaints, NULL/*file*/, 0/*line*/, fmt, args);
243 internal_complaint (struct complaints **complaints, const char *file,
244 int line, const char *fmt, ...)
247 va_start (args, fmt);
248 vcomplaint (complaints, file, line, fmt, args);
253 complain (struct deprecated_complaint *complaint, ...)
256 va_start (args, complaint);
257 vcomplaint (&symfile_complaints, NULL/*file*/, 0/*line*/,
258 complaint->message, args);
262 /* Clear out / initialize all complaint counters that have ever been
263 incremented. If LESS_VERBOSE is 1, be less verbose about
264 successive complaints, since the messages are appearing all
265 together during a command that is reporting a contiguous block of
266 complaints (rather than being interleaved with other messages). If
267 noisy is 1, we are in a noisy command, and our caller will print
268 enough context for the user to figure it out. */
271 clear_complaints (struct complaints **c, int less_verbose, int noisy)
273 struct complaints *complaints = get_complaints (c);
276 for (p = complaints->root; p != NULL; p = p->next)
281 switch (complaints->series)
284 /* Haven't yet printed anything. */
286 case SHORT_FIRST_MESSAGE:
287 /* Haven't yet printed anything. */
289 case ISOLATED_MESSAGE:
290 /* The code above, always forces a line-break. No need to do it
293 case SUBSEQUENT_MESSAGE:
294 /* It would be really nice to use begin_line() here.
295 Unfortunatly that function doesn't track GDB_STDERR and
296 consequently will sometimes supress a line when it shouldn't. */
297 fputs_unfiltered ("\n", gdb_stderr);
300 internal_error (__FILE__, __LINE__, "bad switch");
304 complaints->series = ISOLATED_MESSAGE;
306 complaints->series = FIRST_MESSAGE;
308 complaints->series = SHORT_FIRST_MESSAGE;
312 _initialize_complaints (void)
314 add_setshow_cmd ("complaints", class_support, var_zinteger,
316 "Set max number of complaints about incorrect symbols.",
317 "Show max number of complaints about incorrect symbols.",
319 &setlist, &showlist);