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. */
45 struct complain *next;
50 struct complain *root;
52 enum complaint_series series;
55 static struct complain complaint_sentinel;
57 static struct complaints symfile_complaint_book = {
62 static struct complain * ATTRIBUTE_PRINTF (4, 0)
63 find_complaint (struct complaints *complaints, const char *file,
64 int line, const char *fmt)
66 struct complain *complaint;
68 /* Find the complaint in the table. A more efficient search
69 algorithm (based on hash table or something) could be used. But
70 that can wait until someone shows evidence that this lookup is
71 a real bottle neck. */
72 for (complaint = complaints->root;
74 complaint = complaint->next)
76 if (complaint->fmt == fmt
77 && complaint->file == file
78 && complaint->line == line)
82 /* Oops not seen before, fill in a new complaint. */
83 complaint = XNEW (struct complain);
85 complaint->file = file;
86 complaint->line = line;
87 complaint->counter = 0;
88 complaint->next = NULL;
90 /* File it, return it. */
91 complaint->next = complaints->root;
92 complaints->root = complaint;
97 /* How many complaints about a particular thing should be printed
98 before we stop whining about it? Default is no whining at all,
99 since so many systems have ill-constructed symbol files. */
101 int stop_whining = 0;
103 /* Print a complaint, and link the complaint block into a chain for
106 static void ATTRIBUTE_PRINTF (3, 0)
107 vcomplaint (const char *file,
108 int line, const char *fmt,
111 struct complain *complaint = find_complaint (&symfile_complaint_book, file,
113 enum complaint_series series;
115 complaint->counter++;
116 if (complaint->counter > stop_whining)
119 series = symfile_complaint_book.series;
121 /* Pass 'fmt' instead of 'complaint->fmt' to printf-like callees
122 from here on, to avoid "format string is not a string literal"
123 warnings. 'fmt' is this function's printf-format parameter, so
124 the compiler can assume the passed in argument is a literal
125 string somewhere up the call chain. */
126 gdb_assert (complaint->fmt == fmt);
128 if (complaint->file != NULL)
129 internal_vwarning (complaint->file, complaint->line, fmt, args);
130 else if (deprecated_warning_hook)
131 (*deprecated_warning_hook) (fmt, args);
134 std::string msg = string_vprintf (fmt, args);
137 if (series == ISOLATED_MESSAGE)
138 fprintf_filtered (gdb_stderr, "During symbol reading, %s.\n",
141 fprintf_filtered (gdb_stderr, "%s...", msg.c_str ());
144 /* If GDB dumps core, we'd like to see the complaints first.
145 Presumably GDB will not be sending so many complaints that this
146 becomes a performance hog. */
148 gdb_flush (gdb_stderr);
152 complaint_internal (const char *fmt, ...)
156 va_start (args, fmt);
157 vcomplaint (NULL/*file*/, 0/*line*/, fmt, args);
161 /* Clear out / initialize all complaint counters that have ever been
162 incremented. If LESS_VERBOSE is 1, be less verbose about
163 successive complaints, since the messages are appearing all
164 together during a command that is reporting a contiguous block of
165 complaints (rather than being interleaved with other messages). */
168 clear_complaints (int less_verbose)
172 for (p = symfile_complaint_book.root; p != NULL; p = p->next)
178 symfile_complaint_book.series = ISOLATED_MESSAGE;
180 symfile_complaint_book.series = SHORT_FIRST_MESSAGE;
184 complaints_show_value (struct ui_file *file, int from_tty,
185 struct cmd_list_element *cmd, const char *value)
187 fprintf_filtered (file, _("Max number of complaints about incorrect"
188 " symbols is %s.\n"),
193 _initialize_complaints (void)
195 add_setshow_zinteger_cmd ("complaints", class_support,
197 Set max number of complaints about incorrect symbols."), _("\
198 Show max number of complaints about incorrect symbols."), NULL,
199 NULL, complaints_show_value,
200 &setlist, &showlist);