Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for complaint handling during symbol reading in GDB. |
b9caf505 | 2 | |
61baf725 | 3 | Copyright (C) 1990-2017 Free Software Foundation, Inc. |
c906108c | 4 | |
c5aa993b | 5 | This file is part of GDB. |
c906108c | 6 | |
c5aa993b JM |
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 10 | (at your option) any later version. |
c906108c | 11 | |
c5aa993b JM |
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. | |
c906108c | 16 | |
c5aa993b | 17 | You should have received a copy of the GNU General Public License |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
19 | |
20 | #include "defs.h" | |
21 | #include "complaints.h" | |
b9caf505 | 22 | #include "command.h" |
c906108c SS |
23 | #include "gdbcmd.h" |
24 | ||
aff410f1 MS |
25 | /* Should each complaint message be self explanatory, or should we |
26 | assume that a series of complaints is being produced? */ | |
b9caf505 | 27 | |
b9caf505 AC |
28 | enum complaint_series { |
29 | /* Isolated self explanatory message. */ | |
30 | ISOLATED_MESSAGE, | |
05d999b0 | 31 | |
b9caf505 AC |
32 | /* First message of a series, includes an explanation. */ |
33 | FIRST_MESSAGE, | |
05d999b0 | 34 | |
b9caf505 AC |
35 | /* First message of a series, but does not need to include any sort |
36 | of explanation. */ | |
37 | SHORT_FIRST_MESSAGE, | |
05d999b0 | 38 | |
b9caf505 AC |
39 | /* Subsequent message of a series that needs no explanation (the |
40 | user already knows we have a problem so we can just state our | |
41 | piece). */ | |
42 | SUBSEQUENT_MESSAGE | |
43 | }; | |
44 | ||
c906108c SS |
45 | /* Structure to manage complaints about symbol file contents. */ |
46 | ||
b9caf505 | 47 | struct complain |
c5aa993b | 48 | { |
b9caf505 AC |
49 | const char *file; |
50 | int line; | |
51 | const char *fmt; | |
52 | int counter; | |
53 | struct complain *next; | |
c906108c SS |
54 | }; |
55 | ||
d9170e22 AC |
56 | /* The explanatory message that should accompany the complaint. The |
57 | message is in two parts - pre and post - that are printed around | |
58 | the complaint text. */ | |
59 | struct explanation | |
60 | { | |
61 | const char *prefix; | |
62 | const char *postfix; | |
63 | }; | |
64 | ||
b9caf505 AC |
65 | struct complaints |
66 | { | |
67 | struct complain *root; | |
c906108c | 68 | |
05d999b0 | 69 | enum complaint_series series; |
c906108c | 70 | |
b9caf505 AC |
71 | /* The explanatory messages that should accompany the complaint. |
72 | NOTE: cagney/2002-08-14: In a desperate attempt at being vaguely | |
73 | i18n friendly, this is an array of two messages. When present, | |
d9170e22 AC |
74 | the PRE and POST EXPLANATION[SERIES] are used to wrap the |
75 | message. */ | |
76 | const struct explanation *explanation; | |
b9caf505 | 77 | }; |
c906108c | 78 | |
b9caf505 | 79 | static struct complain complaint_sentinel; |
c906108c | 80 | |
b9caf505 | 81 | /* The symbol table complaint table. */ |
c5aa993b | 82 | |
d9170e22 AC |
83 | static struct explanation symfile_explanations[] = { |
84 | { "During symbol reading, ", "." }, | |
85 | { "During symbol reading...", "..."}, | |
86 | { "", "..."}, | |
87 | { "", "..."}, | |
88 | { NULL, NULL } | |
b9caf505 | 89 | }; |
c906108c | 90 | |
b9caf505 AC |
91 | static struct complaints symfile_complaint_book = { |
92 | &complaint_sentinel, | |
05d999b0 | 93 | ISOLATED_MESSAGE, |
b9caf505 AC |
94 | symfile_explanations |
95 | }; | |
96 | struct complaints *symfile_complaints = &symfile_complaint_book; | |
c906108c | 97 | |
b9caf505 AC |
98 | /* Wrapper function to, on-demand, fill in a complaints object. */ |
99 | ||
100 | static struct complaints * | |
101 | get_complaints (struct complaints **c) | |
c906108c | 102 | { |
b9caf505 AC |
103 | if ((*c) != NULL) |
104 | return (*c); | |
70ba0933 | 105 | (*c) = XNEW (struct complaints); |
b9caf505 AC |
106 | (*c)->root = &complaint_sentinel; |
107 | (*c)->series = ISOLATED_MESSAGE; | |
108 | (*c)->explanation = NULL; | |
109 | return (*c); | |
110 | } | |
c906108c | 111 | |
a0b31db1 | 112 | static struct complain * ATTRIBUTE_PRINTF (4, 0) |
b9caf505 AC |
113 | find_complaint (struct complaints *complaints, const char *file, |
114 | int line, const char *fmt) | |
115 | { | |
116 | struct complain *complaint; | |
117 | ||
118 | /* Find the complaint in the table. A more efficient search | |
119 | algorithm (based on hash table or something) could be used. But | |
120 | that can wait until someone shows evidence that this lookup is | |
121 | a real bottle neck. */ | |
122 | for (complaint = complaints->root; | |
123 | complaint != NULL; | |
124 | complaint = complaint->next) | |
c906108c | 125 | { |
b9caf505 AC |
126 | if (complaint->fmt == fmt |
127 | && complaint->file == file | |
128 | && complaint->line == line) | |
129 | return complaint; | |
c906108c | 130 | } |
b9caf505 AC |
131 | |
132 | /* Oops not seen before, fill in a new complaint. */ | |
70ba0933 | 133 | complaint = XNEW (struct complain); |
b9caf505 AC |
134 | complaint->fmt = fmt; |
135 | complaint->file = file; | |
136 | complaint->line = line; | |
137 | complaint->counter = 0; | |
138 | complaint->next = NULL; | |
139 | ||
140 | /* File it, return it. */ | |
141 | complaint->next = complaints->root; | |
142 | complaints->root = complaint; | |
143 | return complaint; | |
144 | } | |
145 | ||
146 | ||
147 | /* How many complaints about a particular thing should be printed | |
148 | before we stop whining about it? Default is no whining at all, | |
149 | since so many systems have ill-constructed symbol files. */ | |
150 | ||
a0841d7a | 151 | static int stop_whining = 0; |
b9caf505 AC |
152 | |
153 | /* Print a complaint, and link the complaint block into a chain for | |
154 | later handling. */ | |
155 | ||
a0b31db1 | 156 | static void ATTRIBUTE_PRINTF (4, 0) |
aff410f1 MS |
157 | vcomplaint (struct complaints **c, const char *file, |
158 | int line, const char *fmt, | |
b9caf505 AC |
159 | va_list args) |
160 | { | |
161 | struct complaints *complaints = get_complaints (c); | |
aff410f1 MS |
162 | struct complain *complaint = find_complaint (complaints, file, |
163 | line, fmt); | |
b9caf505 | 164 | enum complaint_series series; |
c5504eaf | 165 | |
b9caf505 AC |
166 | gdb_assert (complaints != NULL); |
167 | ||
168 | complaint->counter++; | |
c5aa993b | 169 | if (complaint->counter > stop_whining) |
b9caf505 AC |
170 | return; |
171 | ||
172 | if (info_verbose) | |
173 | series = SUBSEQUENT_MESSAGE; | |
174 | else | |
175 | series = complaints->series; | |
176 | ||
77b64a49 PA |
177 | /* Pass 'fmt' instead of 'complaint->fmt' to printf-like callees |
178 | from here on, to avoid "format string is not a string literal" | |
179 | warnings. 'fmt' is this function's printf-format parameter, so | |
180 | the compiler can assume the passed in argument is a literal | |
181 | string somewhere up the call chain. */ | |
182 | gdb_assert (complaint->fmt == fmt); | |
183 | ||
b9caf505 | 184 | if (complaint->file != NULL) |
77b64a49 | 185 | internal_vwarning (complaint->file, complaint->line, fmt, args); |
9a4105ab | 186 | else if (deprecated_warning_hook) |
77b64a49 | 187 | (*deprecated_warning_hook) (fmt, args); |
b9caf505 | 188 | else |
c906108c | 189 | { |
b9caf505 | 190 | if (complaints->explanation == NULL) |
cc3b68a5 | 191 | /* A [v]warning() call always appends a newline. */ |
77b64a49 | 192 | vwarning (fmt, args); |
b9caf505 AC |
193 | else |
194 | { | |
195 | char *msg; | |
196 | struct cleanup *cleanups; | |
77b64a49 | 197 | msg = xstrvprintf (fmt, args); |
b9caf505 AC |
198 | cleanups = make_cleanup (xfree, msg); |
199 | wrap_here (""); | |
200 | if (series != SUBSEQUENT_MESSAGE) | |
201 | begin_line (); | |
3d263c1d | 202 | /* XXX: i18n */ |
d9170e22 AC |
203 | fprintf_filtered (gdb_stderr, "%s%s%s", |
204 | complaints->explanation[series].prefix, msg, | |
205 | complaints->explanation[series].postfix); | |
cc3b68a5 AC |
206 | /* Force a line-break after any isolated message. For the |
207 | other cases, clear_complaints() takes care of any missing | |
208 | trailing newline, the wrap_here() is just a hint. */ | |
209 | if (series == ISOLATED_MESSAGE) | |
210 | /* It would be really nice to use begin_line() here. | |
ce2826aa | 211 | Unfortunately that function doesn't track GDB_STDERR and |
cc3b68a5 AC |
212 | consequently will sometimes supress a line when it |
213 | shouldn't. */ | |
214 | fputs_filtered ("\n", gdb_stderr); | |
215 | else | |
216 | wrap_here (""); | |
b9caf505 AC |
217 | do_cleanups (cleanups); |
218 | } | |
c906108c | 219 | } |
c906108c | 220 | |
b9caf505 | 221 | switch (series) |
c906108c | 222 | { |
b9caf505 | 223 | case ISOLATED_MESSAGE: |
c5aa993b | 224 | break; |
b9caf505 AC |
225 | case FIRST_MESSAGE: |
226 | complaints->series = SUBSEQUENT_MESSAGE; | |
227 | break; | |
228 | case SUBSEQUENT_MESSAGE: | |
229 | case SHORT_FIRST_MESSAGE: | |
230 | complaints->series = SUBSEQUENT_MESSAGE; | |
c5aa993b | 231 | break; |
c906108c | 232 | } |
b9caf505 AC |
233 | |
234 | /* If GDB dumps core, we'd like to see the complaints first. | |
235 | Presumably GDB will not be sending so many complaints that this | |
236 | becomes a performance hog. */ | |
237 | ||
6426a772 | 238 | gdb_flush (gdb_stderr); |
b9caf505 AC |
239 | } |
240 | ||
241 | void | |
242 | complaint (struct complaints **complaints, const char *fmt, ...) | |
243 | { | |
244 | va_list args; | |
c5504eaf | 245 | |
b9caf505 AC |
246 | va_start (args, fmt); |
247 | vcomplaint (complaints, NULL/*file*/, 0/*line*/, fmt, args); | |
248 | va_end (args); | |
249 | } | |
250 | ||
251 | void | |
252 | internal_complaint (struct complaints **complaints, const char *file, | |
253 | int line, const char *fmt, ...) | |
254 | { | |
255 | va_list args; | |
256 | va_start (args, fmt); | |
257 | vcomplaint (complaints, file, line, fmt, args); | |
258 | va_end (args); | |
259 | } | |
260 | ||
b9caf505 AC |
261 | /* Clear out / initialize all complaint counters that have ever been |
262 | incremented. If LESS_VERBOSE is 1, be less verbose about | |
263 | successive complaints, since the messages are appearing all | |
264 | together during a command that is reporting a contiguous block of | |
265 | complaints (rather than being interleaved with other messages). If | |
266 | noisy is 1, we are in a noisy command, and our caller will print | |
267 | enough context for the user to figure it out. */ | |
c906108c SS |
268 | |
269 | void | |
b9caf505 | 270 | clear_complaints (struct complaints **c, int less_verbose, int noisy) |
c906108c | 271 | { |
b9caf505 AC |
272 | struct complaints *complaints = get_complaints (c); |
273 | struct complain *p; | |
c906108c | 274 | |
b9caf505 | 275 | for (p = complaints->root; p != NULL; p = p->next) |
c906108c | 276 | { |
c5aa993b | 277 | p->counter = 0; |
c906108c SS |
278 | } |
279 | ||
cc3b68a5 | 280 | switch (complaints->series) |
c906108c | 281 | { |
cc3b68a5 AC |
282 | case FIRST_MESSAGE: |
283 | /* Haven't yet printed anything. */ | |
284 | break; | |
285 | case SHORT_FIRST_MESSAGE: | |
286 | /* Haven't yet printed anything. */ | |
287 | break; | |
288 | case ISOLATED_MESSAGE: | |
289 | /* The code above, always forces a line-break. No need to do it | |
290 | here. */ | |
291 | break; | |
292 | case SUBSEQUENT_MESSAGE: | |
293 | /* It would be really nice to use begin_line() here. | |
ce2826aa | 294 | Unfortunately that function doesn't track GDB_STDERR and |
aff410f1 MS |
295 | consequently will sometimes supress a line when it |
296 | shouldn't. */ | |
cc3b68a5 AC |
297 | fputs_unfiltered ("\n", gdb_stderr); |
298 | break; | |
299 | default: | |
3d263c1d | 300 | internal_error (__FILE__, __LINE__, _("bad switch")); |
c906108c SS |
301 | } |
302 | ||
b9caf505 AC |
303 | if (!less_verbose) |
304 | complaints->series = ISOLATED_MESSAGE; | |
305 | else if (!noisy) | |
306 | complaints->series = FIRST_MESSAGE; | |
307 | else | |
308 | complaints->series = SHORT_FIRST_MESSAGE; | |
c906108c SS |
309 | } |
310 | ||
335cca0d | 311 | static void |
08546159 AC |
312 | complaints_show_value (struct ui_file *file, int from_tty, |
313 | struct cmd_list_element *cmd, const char *value) | |
335cca0d AC |
314 | { |
315 | fprintf_filtered (file, _("Max number of complaints about incorrect" | |
08546159 | 316 | " symbols is %s.\n"), |
335cca0d AC |
317 | value); |
318 | } | |
319 | ||
c906108c | 320 | void |
fba45db2 | 321 | _initialize_complaints (void) |
c906108c | 322 | { |
aff410f1 MS |
323 | add_setshow_zinteger_cmd ("complaints", class_support, |
324 | &stop_whining, _("\ | |
3d263c1d | 325 | Set max number of complaints about incorrect symbols."), _("\ |
335cca0d | 326 | Show max number of complaints about incorrect symbols."), NULL, |
08546159 | 327 | NULL, complaints_show_value, |
b3f42336 | 328 | &setlist, &showlist); |
c906108c | 329 | } |