1 /* Support for complaint handling during symbol reading in GDB.
3 Copyright (C) 1990-1993, 1995, 1998-2000, 2002, 2004-2012 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 3 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, see <http://www.gnu.org/licenses/>. */
22 #include "complaints.h"
23 #include "gdb_assert.h"
27 extern void _initialize_complaints (void);
29 /* Should each complaint message be self explanatory, or should we
30 assume that a series of complaints is being produced? */
32 /* case 1: First message of a series that must
33 start off with explanation. case 2: Subsequent message of a series
34 that needs no explanation (the user already knows we have a problem
35 so we can just state our piece). */
36 enum complaint_series
{
37 /* Isolated self explanatory message. */
39 /* First message of a series, includes an explanation. */
41 /* First message of a series, but does not need to include any sort
44 /* Subsequent message of a series that needs no explanation (the
45 user already knows we have a problem so we can just state our
50 /* Structure to manage complaints about symbol file contents. */
58 struct complain
*next
;
61 /* The explanatory message that should accompany the complaint. The
62 message is in two parts - pre and post - that are printed around
63 the complaint text. */
72 struct complain
*root
;
74 /* Should each complaint be self explanatory, or should we assume
75 that a series of complaints is being produced? case 0: Isolated
76 self explanatory message. case 1: First message of a series that
77 must start off with explanation. case 2: Subsequent message of a
78 series that needs no explanation (the user already knows we have
79 a problem so we can just state our piece). */
82 /* The explanatory messages that should accompany the complaint.
83 NOTE: cagney/2002-08-14: In a desperate attempt at being vaguely
84 i18n friendly, this is an array of two messages. When present,
85 the PRE and POST EXPLANATION[SERIES] are used to wrap the
87 const struct explanation
*explanation
;
90 static struct complain complaint_sentinel
;
92 /* The symbol table complaint table. */
94 static struct explanation symfile_explanations
[] = {
95 { "During symbol reading, ", "." },
96 { "During symbol reading...", "..."},
102 static struct complaints symfile_complaint_book
= {
107 struct complaints
*symfile_complaints
= &symfile_complaint_book
;
109 /* Wrapper function to, on-demand, fill in a complaints object. */
111 static struct complaints
*
112 get_complaints (struct complaints
**c
)
116 (*c
) = XMALLOC (struct complaints
);
117 (*c
)->root
= &complaint_sentinel
;
118 (*c
)->series
= ISOLATED_MESSAGE
;
119 (*c
)->explanation
= NULL
;
123 static struct complain
* ATTRIBUTE_PRINTF (4, 0)
124 find_complaint (struct complaints
*complaints
, const char *file
,
125 int line
, const char *fmt
)
127 struct complain
*complaint
;
129 /* Find the complaint in the table. A more efficient search
130 algorithm (based on hash table or something) could be used. But
131 that can wait until someone shows evidence that this lookup is
132 a real bottle neck. */
133 for (complaint
= complaints
->root
;
135 complaint
= complaint
->next
)
137 if (complaint
->fmt
== fmt
138 && complaint
->file
== file
139 && complaint
->line
== line
)
143 /* Oops not seen before, fill in a new complaint. */
144 complaint
= XMALLOC (struct complain
);
145 complaint
->fmt
= fmt
;
146 complaint
->file
= file
;
147 complaint
->line
= line
;
148 complaint
->counter
= 0;
149 complaint
->next
= NULL
;
151 /* File it, return it. */
152 complaint
->next
= complaints
->root
;
153 complaints
->root
= complaint
;
158 /* How many complaints about a particular thing should be printed
159 before we stop whining about it? Default is no whining at all,
160 since so many systems have ill-constructed symbol files. */
162 static int stop_whining
= 0;
164 /* Print a complaint, and link the complaint block into a chain for
167 static void ATTRIBUTE_PRINTF (4, 0)
168 vcomplaint (struct complaints
**c
, const char *file
,
169 int line
, const char *fmt
,
172 struct complaints
*complaints
= get_complaints (c
);
173 struct complain
*complaint
= find_complaint (complaints
, file
,
175 enum complaint_series series
;
177 gdb_assert (complaints
!= NULL
);
179 complaint
->counter
++;
180 if (complaint
->counter
> stop_whining
)
184 series
= SUBSEQUENT_MESSAGE
;
186 series
= complaints
->series
;
188 if (complaint
->file
!= NULL
)
189 internal_vwarning (complaint
->file
, complaint
->line
,
190 complaint
->fmt
, args
);
191 else if (deprecated_warning_hook
)
192 (*deprecated_warning_hook
) (complaint
->fmt
, args
);
195 if (complaints
->explanation
== NULL
)
196 /* A [v]warning() call always appends a newline. */
197 vwarning (complaint
->fmt
, args
);
201 struct cleanup
*cleanups
;
202 msg
= xstrvprintf (complaint
->fmt
, args
);
203 cleanups
= make_cleanup (xfree
, msg
);
205 if (series
!= SUBSEQUENT_MESSAGE
)
208 fprintf_filtered (gdb_stderr
, "%s%s%s",
209 complaints
->explanation
[series
].prefix
, msg
,
210 complaints
->explanation
[series
].postfix
);
211 /* Force a line-break after any isolated message. For the
212 other cases, clear_complaints() takes care of any missing
213 trailing newline, the wrap_here() is just a hint. */
214 if (series
== ISOLATED_MESSAGE
)
215 /* It would be really nice to use begin_line() here.
216 Unfortunately that function doesn't track GDB_STDERR and
217 consequently will sometimes supress a line when it
219 fputs_filtered ("\n", gdb_stderr
);
222 do_cleanups (cleanups
);
228 case ISOLATED_MESSAGE
:
231 complaints
->series
= SUBSEQUENT_MESSAGE
;
233 case SUBSEQUENT_MESSAGE
:
234 case SHORT_FIRST_MESSAGE
:
235 complaints
->series
= SUBSEQUENT_MESSAGE
;
239 /* If GDB dumps core, we'd like to see the complaints first.
240 Presumably GDB will not be sending so many complaints that this
241 becomes a performance hog. */
243 gdb_flush (gdb_stderr
);
247 complaint (struct complaints
**complaints
, const char *fmt
, ...)
251 va_start (args
, fmt
);
252 vcomplaint (complaints
, NULL
/*file*/, 0/*line*/, fmt
, args
);
257 internal_complaint (struct complaints
**complaints
, const char *file
,
258 int line
, const char *fmt
, ...)
261 va_start (args
, fmt
);
262 vcomplaint (complaints
, file
, line
, fmt
, args
);
266 /* Clear out / initialize all complaint counters that have ever been
267 incremented. If LESS_VERBOSE is 1, be less verbose about
268 successive complaints, since the messages are appearing all
269 together during a command that is reporting a contiguous block of
270 complaints (rather than being interleaved with other messages). If
271 noisy is 1, we are in a noisy command, and our caller will print
272 enough context for the user to figure it out. */
275 clear_complaints (struct complaints
**c
, int less_verbose
, int noisy
)
277 struct complaints
*complaints
= get_complaints (c
);
280 for (p
= complaints
->root
; p
!= NULL
; p
= p
->next
)
285 switch (complaints
->series
)
288 /* Haven't yet printed anything. */
290 case SHORT_FIRST_MESSAGE
:
291 /* Haven't yet printed anything. */
293 case ISOLATED_MESSAGE
:
294 /* The code above, always forces a line-break. No need to do it
297 case SUBSEQUENT_MESSAGE
:
298 /* It would be really nice to use begin_line() here.
299 Unfortunately that function doesn't track GDB_STDERR and
300 consequently will sometimes supress a line when it
302 fputs_unfiltered ("\n", gdb_stderr
);
305 internal_error (__FILE__
, __LINE__
, _("bad switch"));
309 complaints
->series
= ISOLATED_MESSAGE
;
311 complaints
->series
= FIRST_MESSAGE
;
313 complaints
->series
= SHORT_FIRST_MESSAGE
;
317 complaints_show_value (struct ui_file
*file
, int from_tty
,
318 struct cmd_list_element
*cmd
, const char *value
)
320 fprintf_filtered (file
, _("Max number of complaints about incorrect"
321 " symbols is %s.\n"),
326 _initialize_complaints (void)
328 add_setshow_zinteger_cmd ("complaints", class_support
,
330 Set max number of complaints about incorrect symbols."), _("\
331 Show max number of complaints about incorrect symbols."), NULL
,
332 NULL
, complaints_show_value
,
333 &setlist
, &showlist
);