Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support for complaint handling during symbol reading in GDB. |
b9caf505 | 2 | |
e2882c85 | 3 | Copyright (C) 1990-2018 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, but does not need to include any sort |
33 | of explanation. */ | |
34 | SHORT_FIRST_MESSAGE, | |
b9caf505 AC |
35 | }; |
36 | ||
c906108c SS |
37 | /* Structure to manage complaints about symbol file contents. */ |
38 | ||
b9caf505 | 39 | struct complain |
c5aa993b | 40 | { |
b9caf505 AC |
41 | const char *file; |
42 | int line; | |
43 | const char *fmt; | |
44 | int counter; | |
45 | struct complain *next; | |
c906108c SS |
46 | }; |
47 | ||
d9170e22 AC |
48 | /* The explanatory message that should accompany the complaint. The |
49 | message is in two parts - pre and post - that are printed around | |
50 | the complaint text. */ | |
51 | struct explanation | |
52 | { | |
53 | const char *prefix; | |
54 | const char *postfix; | |
55 | }; | |
56 | ||
b9caf505 AC |
57 | struct complaints |
58 | { | |
59 | struct complain *root; | |
c906108c | 60 | |
05d999b0 | 61 | enum complaint_series series; |
c906108c | 62 | |
b9caf505 AC |
63 | /* The explanatory messages that should accompany the complaint. |
64 | NOTE: cagney/2002-08-14: In a desperate attempt at being vaguely | |
65 | i18n friendly, this is an array of two messages. When present, | |
d9170e22 AC |
66 | the PRE and POST EXPLANATION[SERIES] are used to wrap the |
67 | message. */ | |
68 | const struct explanation *explanation; | |
b9caf505 | 69 | }; |
c906108c | 70 | |
b9caf505 | 71 | static struct complain complaint_sentinel; |
c906108c | 72 | |
b9caf505 | 73 | /* The symbol table complaint table. */ |
c5aa993b | 74 | |
d9170e22 AC |
75 | static struct explanation symfile_explanations[] = { |
76 | { "During symbol reading, ", "." }, | |
d9170e22 AC |
77 | { "", "..."}, |
78 | { NULL, NULL } | |
b9caf505 | 79 | }; |
c906108c | 80 | |
b9caf505 AC |
81 | static struct complaints symfile_complaint_book = { |
82 | &complaint_sentinel, | |
05d999b0 | 83 | ISOLATED_MESSAGE, |
b9caf505 AC |
84 | symfile_explanations |
85 | }; | |
86 | struct complaints *symfile_complaints = &symfile_complaint_book; | |
c906108c | 87 | |
b9caf505 AC |
88 | /* Wrapper function to, on-demand, fill in a complaints object. */ |
89 | ||
90 | static struct complaints * | |
91 | get_complaints (struct complaints **c) | |
c906108c | 92 | { |
b9caf505 AC |
93 | if ((*c) != NULL) |
94 | return (*c); | |
70ba0933 | 95 | (*c) = XNEW (struct complaints); |
b9caf505 AC |
96 | (*c)->root = &complaint_sentinel; |
97 | (*c)->series = ISOLATED_MESSAGE; | |
98 | (*c)->explanation = NULL; | |
99 | return (*c); | |
100 | } | |
c906108c | 101 | |
a0b31db1 | 102 | static struct complain * ATTRIBUTE_PRINTF (4, 0) |
b9caf505 AC |
103 | find_complaint (struct complaints *complaints, const char *file, |
104 | int line, const char *fmt) | |
105 | { | |
106 | struct complain *complaint; | |
107 | ||
108 | /* Find the complaint in the table. A more efficient search | |
109 | algorithm (based on hash table or something) could be used. But | |
110 | that can wait until someone shows evidence that this lookup is | |
111 | a real bottle neck. */ | |
112 | for (complaint = complaints->root; | |
113 | complaint != NULL; | |
114 | complaint = complaint->next) | |
c906108c | 115 | { |
b9caf505 AC |
116 | if (complaint->fmt == fmt |
117 | && complaint->file == file | |
118 | && complaint->line == line) | |
119 | return complaint; | |
c906108c | 120 | } |
b9caf505 AC |
121 | |
122 | /* Oops not seen before, fill in a new complaint. */ | |
70ba0933 | 123 | complaint = XNEW (struct complain); |
b9caf505 AC |
124 | complaint->fmt = fmt; |
125 | complaint->file = file; | |
126 | complaint->line = line; | |
127 | complaint->counter = 0; | |
128 | complaint->next = NULL; | |
129 | ||
130 | /* File it, return it. */ | |
131 | complaint->next = complaints->root; | |
132 | complaints->root = complaint; | |
133 | return complaint; | |
134 | } | |
135 | ||
136 | ||
137 | /* How many complaints about a particular thing should be printed | |
138 | before we stop whining about it? Default is no whining at all, | |
139 | since so many systems have ill-constructed symbol files. */ | |
140 | ||
62d7ae92 | 141 | int stop_whining = 0; |
b9caf505 AC |
142 | |
143 | /* Print a complaint, and link the complaint block into a chain for | |
144 | later handling. */ | |
145 | ||
a0b31db1 | 146 | static void ATTRIBUTE_PRINTF (4, 0) |
aff410f1 MS |
147 | vcomplaint (struct complaints **c, const char *file, |
148 | int line, const char *fmt, | |
b9caf505 AC |
149 | va_list args) |
150 | { | |
151 | struct complaints *complaints = get_complaints (c); | |
aff410f1 MS |
152 | struct complain *complaint = find_complaint (complaints, file, |
153 | line, fmt); | |
b9caf505 | 154 | enum complaint_series series; |
c5504eaf | 155 | |
b9caf505 AC |
156 | gdb_assert (complaints != NULL); |
157 | ||
158 | complaint->counter++; | |
c5aa993b | 159 | if (complaint->counter > stop_whining) |
b9caf505 AC |
160 | return; |
161 | ||
43ba33c7 | 162 | series = complaints->series; |
b9caf505 | 163 | |
77b64a49 PA |
164 | /* Pass 'fmt' instead of 'complaint->fmt' to printf-like callees |
165 | from here on, to avoid "format string is not a string literal" | |
166 | warnings. 'fmt' is this function's printf-format parameter, so | |
167 | the compiler can assume the passed in argument is a literal | |
168 | string somewhere up the call chain. */ | |
169 | gdb_assert (complaint->fmt == fmt); | |
170 | ||
b9caf505 | 171 | if (complaint->file != NULL) |
77b64a49 | 172 | internal_vwarning (complaint->file, complaint->line, fmt, args); |
9a4105ab | 173 | else if (deprecated_warning_hook) |
77b64a49 | 174 | (*deprecated_warning_hook) (fmt, args); |
b9caf505 | 175 | else |
c906108c | 176 | { |
b9caf505 | 177 | if (complaints->explanation == NULL) |
cc3b68a5 | 178 | /* A [v]warning() call always appends a newline. */ |
77b64a49 | 179 | vwarning (fmt, args); |
b9caf505 AC |
180 | else |
181 | { | |
55b06432 | 182 | std::string msg = string_vprintf (fmt, args); |
b9caf505 | 183 | wrap_here (""); |
43ba33c7 | 184 | begin_line (); |
3d263c1d | 185 | /* XXX: i18n */ |
d9170e22 | 186 | fprintf_filtered (gdb_stderr, "%s%s%s", |
55b06432 TT |
187 | complaints->explanation[series].prefix, |
188 | msg.c_str (), | |
d9170e22 | 189 | complaints->explanation[series].postfix); |
43ba33c7 | 190 | /* Force a line-break after any isolated message. */ |
cc3b68a5 AC |
191 | if (series == ISOLATED_MESSAGE) |
192 | /* It would be really nice to use begin_line() here. | |
ce2826aa | 193 | Unfortunately that function doesn't track GDB_STDERR and |
cc3b68a5 AC |
194 | consequently will sometimes supress a line when it |
195 | shouldn't. */ | |
196 | fputs_filtered ("\n", gdb_stderr); | |
197 | else | |
198 | wrap_here (""); | |
b9caf505 | 199 | } |
c906108c | 200 | } |
c906108c | 201 | |
b9caf505 AC |
202 | /* If GDB dumps core, we'd like to see the complaints first. |
203 | Presumably GDB will not be sending so many complaints that this | |
204 | becomes a performance hog. */ | |
205 | ||
6426a772 | 206 | gdb_flush (gdb_stderr); |
b9caf505 AC |
207 | } |
208 | ||
209 | void | |
62d7ae92 | 210 | complaint_internal (struct complaints **complaints, const char *fmt, ...) |
b9caf505 AC |
211 | { |
212 | va_list args; | |
c5504eaf | 213 | |
b9caf505 AC |
214 | va_start (args, fmt); |
215 | vcomplaint (complaints, NULL/*file*/, 0/*line*/, fmt, args); | |
216 | va_end (args); | |
217 | } | |
218 | ||
b9caf505 AC |
219 | /* Clear out / initialize all complaint counters that have ever been |
220 | incremented. If LESS_VERBOSE is 1, be less verbose about | |
221 | successive complaints, since the messages are appearing all | |
222 | together during a command that is reporting a contiguous block of | |
4e9668d0 | 223 | complaints (rather than being interleaved with other messages). */ |
c906108c SS |
224 | |
225 | void | |
4e9668d0 | 226 | clear_complaints (struct complaints **c, int less_verbose) |
c906108c | 227 | { |
b9caf505 AC |
228 | struct complaints *complaints = get_complaints (c); |
229 | struct complain *p; | |
c906108c | 230 | |
b9caf505 | 231 | for (p = complaints->root; p != NULL; p = p->next) |
c906108c | 232 | { |
c5aa993b | 233 | p->counter = 0; |
c906108c SS |
234 | } |
235 | ||
b9caf505 AC |
236 | if (!less_verbose) |
237 | complaints->series = ISOLATED_MESSAGE; | |
b9caf505 AC |
238 | else |
239 | complaints->series = SHORT_FIRST_MESSAGE; | |
c906108c SS |
240 | } |
241 | ||
335cca0d | 242 | static void |
08546159 AC |
243 | complaints_show_value (struct ui_file *file, int from_tty, |
244 | struct cmd_list_element *cmd, const char *value) | |
335cca0d AC |
245 | { |
246 | fprintf_filtered (file, _("Max number of complaints about incorrect" | |
08546159 | 247 | " symbols is %s.\n"), |
335cca0d AC |
248 | value); |
249 | } | |
250 | ||
c906108c | 251 | void |
fba45db2 | 252 | _initialize_complaints (void) |
c906108c | 253 | { |
aff410f1 MS |
254 | add_setshow_zinteger_cmd ("complaints", class_support, |
255 | &stop_whining, _("\ | |
3d263c1d | 256 | Set max number of complaints about incorrect symbols."), _("\ |
335cca0d | 257 | Show max number of complaints about incorrect symbols."), NULL, |
08546159 | 258 | NULL, complaints_show_value, |
b3f42336 | 259 | &setlist, &showlist); |
c906108c | 260 | } |