1 /* Support for complaint handling during symbol reading in GDB.
3 Copyright (C) 1990-2018 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"
25 /* Should each complaint message be self explanatory, or should we
26 assume that a series of complaints is being produced? */
28 enum complaint_series
{
29 /* Isolated self explanatory message. */
32 /* First message of a series, but does not need to include any sort
37 /* Structure to manage complaints about symbol file contents. */
43 struct complain
*next
;
48 struct complain
*root
;
50 enum complaint_series series
;
53 static struct complain complaint_sentinel
;
55 static struct complaints symfile_complaint_book
= {
60 static struct complain
* ATTRIBUTE_PRINTF (2, 0)
61 find_complaint (struct complaints
*complaints
, const char *fmt
)
63 struct complain
*complaint
;
65 /* Find the complaint in the table. A more efficient search
66 algorithm (based on hash table or something) could be used. But
67 that can wait until someone shows evidence that this lookup is
68 a real bottle neck. */
69 for (complaint
= complaints
->root
;
71 complaint
= complaint
->next
)
73 if (complaint
->fmt
== fmt
)
77 /* Oops not seen before, fill in a new complaint. */
78 complaint
= XNEW (struct complain
);
80 complaint
->counter
= 0;
81 complaint
->next
= NULL
;
83 /* File it, return it. */
84 complaint
->next
= complaints
->root
;
85 complaints
->root
= complaint
;
90 /* How many complaints about a particular thing should be printed
91 before we stop whining about it? Default is no whining at all,
92 since so many systems have ill-constructed symbol files. */
96 /* See complaints.h. */
99 complaint_internal (const char *fmt
, ...)
103 struct complain
*complaint
= find_complaint (&symfile_complaint_book
, fmt
);
104 enum complaint_series series
;
106 complaint
->counter
++;
107 if (complaint
->counter
> stop_whining
)
110 va_start (args
, fmt
);
111 series
= symfile_complaint_book
.series
;
113 /* Pass 'fmt' instead of 'complaint->fmt' to printf-like callees
114 from here on, to avoid "format string is not a string literal"
115 warnings. 'fmt' is this function's printf-format parameter, so
116 the compiler can assume the passed in argument is a literal
117 string somewhere up the call chain. */
118 gdb_assert (complaint
->fmt
== fmt
);
120 if (deprecated_warning_hook
)
121 (*deprecated_warning_hook
) (fmt
, args
);
124 std::string msg
= string_vprintf (fmt
, args
);
127 if (series
== ISOLATED_MESSAGE
)
128 fprintf_filtered (gdb_stderr
, "During symbol reading, %s.\n",
131 fprintf_filtered (gdb_stderr
, "%s...", msg
.c_str ());
134 /* If GDB dumps core, we'd like to see the complaints first.
135 Presumably GDB will not be sending so many complaints that this
136 becomes a performance hog. */
138 gdb_flush (gdb_stderr
);
142 /* Clear out / initialize all complaint counters that have ever been
143 incremented. If LESS_VERBOSE is 1, be less verbose about
144 successive complaints, since the messages are appearing all
145 together during a command that is reporting a contiguous block of
146 complaints (rather than being interleaved with other messages). */
149 clear_complaints (int less_verbose
)
153 for (p
= symfile_complaint_book
.root
; p
!= NULL
; p
= p
->next
)
159 symfile_complaint_book
.series
= ISOLATED_MESSAGE
;
161 symfile_complaint_book
.series
= SHORT_FIRST_MESSAGE
;
165 complaints_show_value (struct ui_file
*file
, int from_tty
,
166 struct cmd_list_element
*cmd
, const char *value
)
168 fprintf_filtered (file
, _("Max number of complaints about incorrect"
169 " symbols is %s.\n"),
174 _initialize_complaints (void)
176 add_setshow_zinteger_cmd ("complaints", class_support
,
178 Set max number of complaints about incorrect symbols."), _("\
179 Show max number of complaints about incorrect symbols."), NULL
,
180 NULL
, complaints_show_value
,
181 &setlist
, &showlist
);