1 /* Support for complaint handling during symbol reading in GDB.
3 Copyright (C) 1990-2013 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"
22 #include "gdb_assert.h"
26 extern void _initialize_complaints (void);
28 /* Should each complaint message be self explanatory, or should we
29 assume that a series of complaints is being produced? */
31 /* case 1: First message of a series that must
32 start off with explanation. case 2: Subsequent message of a series
33 that needs no explanation (the user already knows we have a problem
34 so we can just state our piece). */
35 enum complaint_series
{
36 /* Isolated self explanatory message. */
38 /* First message of a series, includes an explanation. */
40 /* First message of a series, but does not need to include any sort
43 /* Subsequent message of a series that needs no explanation (the
44 user already knows we have a problem so we can just state our
49 /* Structure to manage complaints about symbol file contents. */
57 struct complain
*next
;
60 /* The explanatory message that should accompany the complaint. The
61 message is in two parts - pre and post - that are printed around
62 the complaint text. */
71 struct complain
*root
;
73 /* Should each complaint be self explanatory, or should we assume
74 that a series of complaints is being produced? case 0: Isolated
75 self explanatory message. case 1: First message of a series that
76 must start off with explanation. case 2: Subsequent message of a
77 series that needs no explanation (the user already knows we have
78 a problem so we can just state our piece). */
81 /* The explanatory messages that should accompany the complaint.
82 NOTE: cagney/2002-08-14: In a desperate attempt at being vaguely
83 i18n friendly, this is an array of two messages. When present,
84 the PRE and POST EXPLANATION[SERIES] are used to wrap the
86 const struct explanation
*explanation
;
89 static struct complain complaint_sentinel
;
91 /* The symbol table complaint table. */
93 static struct explanation symfile_explanations
[] = {
94 { "During symbol reading, ", "." },
95 { "During symbol reading...", "..."},
101 static struct complaints symfile_complaint_book
= {
106 struct complaints
*symfile_complaints
= &symfile_complaint_book
;
108 /* Wrapper function to, on-demand, fill in a complaints object. */
110 static struct complaints
*
111 get_complaints (struct complaints
**c
)
115 (*c
) = XMALLOC (struct complaints
);
116 (*c
)->root
= &complaint_sentinel
;
117 (*c
)->series
= ISOLATED_MESSAGE
;
118 (*c
)->explanation
= NULL
;
122 static struct complain
* ATTRIBUTE_PRINTF (4, 0)
123 find_complaint (struct complaints
*complaints
, const char *file
,
124 int line
, const char *fmt
)
126 struct complain
*complaint
;
128 /* Find the complaint in the table. A more efficient search
129 algorithm (based on hash table or something) could be used. But
130 that can wait until someone shows evidence that this lookup is
131 a real bottle neck. */
132 for (complaint
= complaints
->root
;
134 complaint
= complaint
->next
)
136 if (complaint
->fmt
== fmt
137 && complaint
->file
== file
138 && complaint
->line
== line
)
142 /* Oops not seen before, fill in a new complaint. */
143 complaint
= XMALLOC (struct complain
);
144 complaint
->fmt
= fmt
;
145 complaint
->file
= file
;
146 complaint
->line
= line
;
147 complaint
->counter
= 0;
148 complaint
->next
= NULL
;
150 /* File it, return it. */
151 complaint
->next
= complaints
->root
;
152 complaints
->root
= complaint
;
157 /* How many complaints about a particular thing should be printed
158 before we stop whining about it? Default is no whining at all,
159 since so many systems have ill-constructed symbol files. */
161 static int stop_whining
= 0;
163 /* Print a complaint, and link the complaint block into a chain for
166 static void ATTRIBUTE_PRINTF (4, 0)
167 vcomplaint (struct complaints
**c
, const char *file
,
168 int line
, const char *fmt
,
171 struct complaints
*complaints
= get_complaints (c
);
172 struct complain
*complaint
= find_complaint (complaints
, file
,
174 enum complaint_series series
;
176 gdb_assert (complaints
!= NULL
);
178 complaint
->counter
++;
179 if (complaint
->counter
> stop_whining
)
183 series
= SUBSEQUENT_MESSAGE
;
185 series
= complaints
->series
;
187 if (complaint
->file
!= NULL
)
188 internal_vwarning (complaint
->file
, complaint
->line
,
189 complaint
->fmt
, args
);
190 else if (deprecated_warning_hook
)
191 (*deprecated_warning_hook
) (complaint
->fmt
, args
);
194 if (complaints
->explanation
== NULL
)
195 /* A [v]warning() call always appends a newline. */
196 vwarning (complaint
->fmt
, args
);
200 struct cleanup
*cleanups
;
201 msg
= xstrvprintf (complaint
->fmt
, args
);
202 cleanups
= make_cleanup (xfree
, msg
);
204 if (series
!= SUBSEQUENT_MESSAGE
)
207 fprintf_filtered (gdb_stderr
, "%s%s%s",
208 complaints
->explanation
[series
].prefix
, msg
,
209 complaints
->explanation
[series
].postfix
);
210 /* Force a line-break after any isolated message. For the
211 other cases, clear_complaints() takes care of any missing
212 trailing newline, the wrap_here() is just a hint. */
213 if (series
== ISOLATED_MESSAGE
)
214 /* It would be really nice to use begin_line() here.
215 Unfortunately that function doesn't track GDB_STDERR and
216 consequently will sometimes supress a line when it
218 fputs_filtered ("\n", gdb_stderr
);
221 do_cleanups (cleanups
);
227 case ISOLATED_MESSAGE
:
230 complaints
->series
= SUBSEQUENT_MESSAGE
;
232 case SUBSEQUENT_MESSAGE
:
233 case SHORT_FIRST_MESSAGE
:
234 complaints
->series
= SUBSEQUENT_MESSAGE
;
238 /* If GDB dumps core, we'd like to see the complaints first.
239 Presumably GDB will not be sending so many complaints that this
240 becomes a performance hog. */
242 gdb_flush (gdb_stderr
);
246 complaint (struct complaints
**complaints
, const char *fmt
, ...)
250 va_start (args
, fmt
);
251 vcomplaint (complaints
, NULL
/*file*/, 0/*line*/, fmt
, args
);
256 internal_complaint (struct complaints
**complaints
, const char *file
,
257 int line
, const char *fmt
, ...)
260 va_start (args
, fmt
);
261 vcomplaint (complaints
, file
, line
, fmt
, args
);
265 /* Clear out / initialize all complaint counters that have ever been
266 incremented. If LESS_VERBOSE is 1, be less verbose about
267 successive complaints, since the messages are appearing all
268 together during a command that is reporting a contiguous block of
269 complaints (rather than being interleaved with other messages). If
270 noisy is 1, we are in a noisy command, and our caller will print
271 enough context for the user to figure it out. */
274 clear_complaints (struct complaints
**c
, int less_verbose
, int noisy
)
276 struct complaints
*complaints
= get_complaints (c
);
279 for (p
= complaints
->root
; p
!= NULL
; p
= p
->next
)
284 switch (complaints
->series
)
287 /* Haven't yet printed anything. */
289 case SHORT_FIRST_MESSAGE
:
290 /* Haven't yet printed anything. */
292 case ISOLATED_MESSAGE
:
293 /* The code above, always forces a line-break. No need to do it
296 case SUBSEQUENT_MESSAGE
:
297 /* It would be really nice to use begin_line() here.
298 Unfortunately that function doesn't track GDB_STDERR and
299 consequently will sometimes supress a line when it
301 fputs_unfiltered ("\n", gdb_stderr
);
304 internal_error (__FILE__
, __LINE__
, _("bad switch"));
308 complaints
->series
= ISOLATED_MESSAGE
;
310 complaints
->series
= FIRST_MESSAGE
;
312 complaints
->series
= SHORT_FIRST_MESSAGE
;
316 complaints_show_value (struct ui_file
*file
, int from_tty
,
317 struct cmd_list_element
*cmd
, const char *value
)
319 fprintf_filtered (file
, _("Max number of complaints about incorrect"
320 " symbols is %s.\n"),
325 _initialize_complaints (void)
327 add_setshow_zinteger_cmd ("complaints", class_support
,
329 Set max number of complaints about incorrect symbols."), _("\
330 Show max number of complaints about incorrect symbols."), NULL
,
331 NULL
, complaints_show_value
,
332 &setlist
, &showlist
);