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