Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for complaint handling during symbol reading in GDB. |
b9caf505 | 2 | |
0b302171 JB |
3 | Copyright (C) 1990-1993, 1995, 1998-2000, 2002, 2004-2012 Free |
4 | Software Foundation, Inc. | |
c906108c | 5 | |
c5aa993b | 6 | This file is part of GDB. |
c906108c | 7 | |
c5aa993b JM |
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 | |
a9762ec7 | 10 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 11 | (at your option) any later version. |
c906108c | 12 | |
c5aa993b JM |
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. | |
c906108c | 17 | |
c5aa993b | 18 | You should have received a copy of the GNU General Public License |
a9762ec7 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
20 | |
21 | #include "defs.h" | |
22 | #include "complaints.h" | |
b9caf505 AC |
23 | #include "gdb_assert.h" |
24 | #include "command.h" | |
c906108c SS |
25 | #include "gdbcmd.h" |
26 | ||
a14ed312 | 27 | extern void _initialize_complaints (void); |
392a587b | 28 | |
aff410f1 MS |
29 | /* Should each complaint message be self explanatory, or should we |
30 | assume that a series of complaints is being produced? */ | |
b9caf505 AC |
31 | |
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. */ | |
38 | ISOLATED_MESSAGE, | |
39 | /* First message of a series, includes an explanation. */ | |
40 | FIRST_MESSAGE, | |
41 | /* First message of a series, but does not need to include any sort | |
42 | of explanation. */ | |
43 | SHORT_FIRST_MESSAGE, | |
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 | |
46 | piece). */ | |
47 | SUBSEQUENT_MESSAGE | |
48 | }; | |
49 | ||
c906108c SS |
50 | /* Structure to manage complaints about symbol file contents. */ |
51 | ||
b9caf505 | 52 | struct complain |
c5aa993b | 53 | { |
b9caf505 AC |
54 | const char *file; |
55 | int line; | |
56 | const char *fmt; | |
57 | int counter; | |
58 | struct complain *next; | |
c906108c SS |
59 | }; |
60 | ||
d9170e22 AC |
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. */ | |
64 | struct explanation | |
65 | { | |
66 | const char *prefix; | |
67 | const char *postfix; | |
68 | }; | |
69 | ||
b9caf505 AC |
70 | struct complaints |
71 | { | |
72 | struct complain *root; | |
c906108c | 73 | |
b9caf505 AC |
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). */ | |
80 | int series; | |
c906108c | 81 | |
b9caf505 AC |
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, | |
d9170e22 AC |
85 | the PRE and POST EXPLANATION[SERIES] are used to wrap the |
86 | message. */ | |
87 | const struct explanation *explanation; | |
b9caf505 | 88 | }; |
c906108c | 89 | |
b9caf505 | 90 | static struct complain complaint_sentinel; |
c906108c | 91 | |
b9caf505 | 92 | /* The symbol table complaint table. */ |
c5aa993b | 93 | |
d9170e22 AC |
94 | static struct explanation symfile_explanations[] = { |
95 | { "During symbol reading, ", "." }, | |
96 | { "During symbol reading...", "..."}, | |
97 | { "", "..."}, | |
98 | { "", "..."}, | |
99 | { NULL, NULL } | |
b9caf505 | 100 | }; |
c906108c | 101 | |
b9caf505 AC |
102 | static struct complaints symfile_complaint_book = { |
103 | &complaint_sentinel, | |
104 | 0, | |
105 | symfile_explanations | |
106 | }; | |
107 | struct complaints *symfile_complaints = &symfile_complaint_book; | |
c906108c | 108 | |
b9caf505 AC |
109 | /* Wrapper function to, on-demand, fill in a complaints object. */ |
110 | ||
111 | static struct complaints * | |
112 | get_complaints (struct complaints **c) | |
c906108c | 113 | { |
b9caf505 AC |
114 | if ((*c) != NULL) |
115 | return (*c); | |
116 | (*c) = XMALLOC (struct complaints); | |
117 | (*c)->root = &complaint_sentinel; | |
118 | (*c)->series = ISOLATED_MESSAGE; | |
119 | (*c)->explanation = NULL; | |
120 | return (*c); | |
121 | } | |
c906108c | 122 | |
a0b31db1 | 123 | static struct complain * ATTRIBUTE_PRINTF (4, 0) |
b9caf505 AC |
124 | find_complaint (struct complaints *complaints, const char *file, |
125 | int line, const char *fmt) | |
126 | { | |
127 | struct complain *complaint; | |
128 | ||
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; | |
134 | complaint != NULL; | |
135 | complaint = complaint->next) | |
c906108c | 136 | { |
b9caf505 AC |
137 | if (complaint->fmt == fmt |
138 | && complaint->file == file | |
139 | && complaint->line == line) | |
140 | return complaint; | |
c906108c | 141 | } |
b9caf505 AC |
142 | |
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; | |
150 | ||
151 | /* File it, return it. */ | |
152 | complaint->next = complaints->root; | |
153 | complaints->root = complaint; | |
154 | return complaint; | |
155 | } | |
156 | ||
157 | ||
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. */ | |
161 | ||
a0841d7a | 162 | static int stop_whining = 0; |
b9caf505 AC |
163 | |
164 | /* Print a complaint, and link the complaint block into a chain for | |
165 | later handling. */ | |
166 | ||
a0b31db1 | 167 | static void ATTRIBUTE_PRINTF (4, 0) |
aff410f1 MS |
168 | vcomplaint (struct complaints **c, const char *file, |
169 | int line, const char *fmt, | |
b9caf505 AC |
170 | va_list args) |
171 | { | |
172 | struct complaints *complaints = get_complaints (c); | |
aff410f1 MS |
173 | struct complain *complaint = find_complaint (complaints, file, |
174 | line, fmt); | |
b9caf505 | 175 | enum complaint_series series; |
c5504eaf | 176 | |
b9caf505 AC |
177 | gdb_assert (complaints != NULL); |
178 | ||
179 | complaint->counter++; | |
c5aa993b | 180 | if (complaint->counter > stop_whining) |
b9caf505 AC |
181 | return; |
182 | ||
183 | if (info_verbose) | |
184 | series = SUBSEQUENT_MESSAGE; | |
185 | else | |
186 | series = complaints->series; | |
187 | ||
188 | if (complaint->file != NULL) | |
aff410f1 MS |
189 | internal_vwarning (complaint->file, complaint->line, |
190 | complaint->fmt, args); | |
9a4105ab AC |
191 | else if (deprecated_warning_hook) |
192 | (*deprecated_warning_hook) (complaint->fmt, args); | |
b9caf505 | 193 | else |
c906108c | 194 | { |
b9caf505 | 195 | if (complaints->explanation == NULL) |
cc3b68a5 | 196 | /* A [v]warning() call always appends a newline. */ |
b9caf505 AC |
197 | vwarning (complaint->fmt, args); |
198 | else | |
199 | { | |
200 | char *msg; | |
201 | struct cleanup *cleanups; | |
e623b504 | 202 | msg = xstrvprintf (complaint->fmt, args); |
b9caf505 AC |
203 | cleanups = make_cleanup (xfree, msg); |
204 | wrap_here (""); | |
205 | if (series != SUBSEQUENT_MESSAGE) | |
206 | begin_line (); | |
3d263c1d | 207 | /* XXX: i18n */ |
d9170e22 AC |
208 | fprintf_filtered (gdb_stderr, "%s%s%s", |
209 | complaints->explanation[series].prefix, msg, | |
210 | complaints->explanation[series].postfix); | |
cc3b68a5 AC |
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. | |
ce2826aa | 216 | Unfortunately that function doesn't track GDB_STDERR and |
cc3b68a5 AC |
217 | consequently will sometimes supress a line when it |
218 | shouldn't. */ | |
219 | fputs_filtered ("\n", gdb_stderr); | |
220 | else | |
221 | wrap_here (""); | |
b9caf505 AC |
222 | do_cleanups (cleanups); |
223 | } | |
c906108c | 224 | } |
c906108c | 225 | |
b9caf505 | 226 | switch (series) |
c906108c | 227 | { |
b9caf505 | 228 | case ISOLATED_MESSAGE: |
c5aa993b | 229 | break; |
b9caf505 AC |
230 | case FIRST_MESSAGE: |
231 | complaints->series = SUBSEQUENT_MESSAGE; | |
232 | break; | |
233 | case SUBSEQUENT_MESSAGE: | |
234 | case SHORT_FIRST_MESSAGE: | |
235 | complaints->series = SUBSEQUENT_MESSAGE; | |
c5aa993b | 236 | break; |
c906108c | 237 | } |
b9caf505 AC |
238 | |
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. */ | |
242 | ||
6426a772 | 243 | gdb_flush (gdb_stderr); |
b9caf505 AC |
244 | } |
245 | ||
246 | void | |
247 | complaint (struct complaints **complaints, const char *fmt, ...) | |
248 | { | |
249 | va_list args; | |
c5504eaf | 250 | |
b9caf505 AC |
251 | va_start (args, fmt); |
252 | vcomplaint (complaints, NULL/*file*/, 0/*line*/, fmt, args); | |
253 | va_end (args); | |
254 | } | |
255 | ||
256 | void | |
257 | internal_complaint (struct complaints **complaints, const char *file, | |
258 | int line, const char *fmt, ...) | |
259 | { | |
260 | va_list args; | |
261 | va_start (args, fmt); | |
262 | vcomplaint (complaints, file, line, fmt, args); | |
263 | va_end (args); | |
264 | } | |
265 | ||
b9caf505 AC |
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. */ | |
c906108c SS |
273 | |
274 | void | |
b9caf505 | 275 | clear_complaints (struct complaints **c, int less_verbose, int noisy) |
c906108c | 276 | { |
b9caf505 AC |
277 | struct complaints *complaints = get_complaints (c); |
278 | struct complain *p; | |
c906108c | 279 | |
b9caf505 | 280 | for (p = complaints->root; p != NULL; p = p->next) |
c906108c | 281 | { |
c5aa993b | 282 | p->counter = 0; |
c906108c SS |
283 | } |
284 | ||
cc3b68a5 | 285 | switch (complaints->series) |
c906108c | 286 | { |
cc3b68a5 AC |
287 | case FIRST_MESSAGE: |
288 | /* Haven't yet printed anything. */ | |
289 | break; | |
290 | case SHORT_FIRST_MESSAGE: | |
291 | /* Haven't yet printed anything. */ | |
292 | break; | |
293 | case ISOLATED_MESSAGE: | |
294 | /* The code above, always forces a line-break. No need to do it | |
295 | here. */ | |
296 | break; | |
297 | case SUBSEQUENT_MESSAGE: | |
298 | /* It would be really nice to use begin_line() here. | |
ce2826aa | 299 | Unfortunately that function doesn't track GDB_STDERR and |
aff410f1 MS |
300 | consequently will sometimes supress a line when it |
301 | shouldn't. */ | |
cc3b68a5 AC |
302 | fputs_unfiltered ("\n", gdb_stderr); |
303 | break; | |
304 | default: | |
3d263c1d | 305 | internal_error (__FILE__, __LINE__, _("bad switch")); |
c906108c SS |
306 | } |
307 | ||
b9caf505 AC |
308 | if (!less_verbose) |
309 | complaints->series = ISOLATED_MESSAGE; | |
310 | else if (!noisy) | |
311 | complaints->series = FIRST_MESSAGE; | |
312 | else | |
313 | complaints->series = SHORT_FIRST_MESSAGE; | |
c906108c SS |
314 | } |
315 | ||
335cca0d | 316 | static void |
08546159 AC |
317 | complaints_show_value (struct ui_file *file, int from_tty, |
318 | struct cmd_list_element *cmd, const char *value) | |
335cca0d AC |
319 | { |
320 | fprintf_filtered (file, _("Max number of complaints about incorrect" | |
08546159 | 321 | " symbols is %s.\n"), |
335cca0d AC |
322 | value); |
323 | } | |
324 | ||
c906108c | 325 | void |
fba45db2 | 326 | _initialize_complaints (void) |
c906108c | 327 | { |
aff410f1 MS |
328 | add_setshow_zinteger_cmd ("complaints", class_support, |
329 | &stop_whining, _("\ | |
3d263c1d | 330 | Set max number of complaints about incorrect symbols."), _("\ |
335cca0d | 331 | Show max number of complaints about incorrect symbols."), NULL, |
08546159 | 332 | NULL, complaints_show_value, |
b3f42336 | 333 | &setlist, &showlist); |
c906108c | 334 | } |