aboutsummaryrefslogtreecommitdiff
path: root/gdb/complaints.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-05-16 23:22:54 -0600
committerTom Tromey <tom@tromey.com>2018-05-23 09:17:03 -0600
commitff1cf532dbabdee0d34974a77809bf2fa23d43a5 (patch)
treececf18799007e3199cef48eecf5ef0eee54f0c54 /gdb/complaints.c
parent7ff8817441fcebe3d32343dbd9d514366bfe8e23 (diff)
downloadgdb-ff1cf532dbabdee0d34974a77809bf2fa23d43a5.zip
gdb-ff1cf532dbabdee0d34974a77809bf2fa23d43a5.tar.gz
gdb-ff1cf532dbabdee0d34974a77809bf2fa23d43a5.tar.bz2
Remove struct complain
At this point, struct complain is just holds a key, a value, and a "next" pointer to form a linked list. It's simpler to replace this with an unordered map. gdb/ChangeLog 2018-05-23 Tom Tromey <tom@tromey.com> * complaints.c (counters): New global. (struct complain): Remove. (struct complaints) <root>: Remove. (complaint_sentinel): Remove. (symfile_complaint_book): Update. (find_complaint) Remove. (complaint_internal, clear_complaints): Update. gdb/testsuite/ChangeLog 2018-05-23 Tom Tromey <tom@tromey.com> * gdb.gdb/complaints.exp (test_initial_complaints): Simplify.
Diffstat (limited to 'gdb/complaints.c')
-rw-r--r--gdb/complaints.c62
1 files changed, 5 insertions, 57 deletions
diff --git a/gdb/complaints.c b/gdb/complaints.c
index 851d8f5..2c69b8c 100644
--- a/gdb/complaints.c
+++ b/gdb/complaints.c
@@ -21,6 +21,7 @@
#include "complaints.h"
#include "command.h"
#include "gdbcmd.h"
+#include <unordered_map>
/* Should each complaint message be self explanatory, or should we
assume that a series of complaints is being produced? */
@@ -34,59 +35,19 @@ enum complaint_series {
SHORT_FIRST_MESSAGE,
};
-/* Structure to manage complaints about symbol file contents. */
+/* Map format strings to counters. */
-struct complain
-{
- const char *fmt;
- int counter;
- struct complain *next;
-};
+static std::unordered_map<const char *, int> counters;
struct complaints
{
- struct complain *root;
-
enum complaint_series series;
};
-static struct complain complaint_sentinel;
-
static struct complaints symfile_complaint_book = {
- &complaint_sentinel,
ISOLATED_MESSAGE
};
-static struct complain * ATTRIBUTE_PRINTF (2, 0)
-find_complaint (struct complaints *complaints, const char *fmt)
-{
- struct complain *complaint;
-
- /* Find the complaint in the table. A more efficient search
- algorithm (based on hash table or something) could be used. But
- that can wait until someone shows evidence that this lookup is
- a real bottle neck. */
- for (complaint = complaints->root;
- complaint != NULL;
- complaint = complaint->next)
- {
- if (complaint->fmt == fmt)
- return complaint;
- }
-
- /* Oops not seen before, fill in a new complaint. */
- complaint = XNEW (struct complain);
- complaint->fmt = fmt;
- complaint->counter = 0;
- complaint->next = NULL;
-
- /* File it, return it. */
- complaint->next = complaints->root;
- complaints->root = complaint;
- return complaint;
-}
-
-
/* How many complaints about a particular thing should be printed
before we stop whining about it? Default is no whining at all,
since so many systems have ill-constructed symbol files. */
@@ -99,24 +60,14 @@ void
complaint_internal (const char *fmt, ...)
{
va_list args;
-
- struct complain *complaint = find_complaint (&symfile_complaint_book, fmt);
enum complaint_series series;
- complaint->counter++;
- if (complaint->counter > stop_whining)
+ if (counters[fmt]++ > stop_whining)
return;
va_start (args, fmt);
series = symfile_complaint_book.series;
- /* Pass 'fmt' instead of 'complaint->fmt' to printf-like callees
- from here on, to avoid "format string is not a string literal"
- warnings. 'fmt' is this function's printf-format parameter, so
- the compiler can assume the passed in argument is a literal
- string somewhere up the call chain. */
- gdb_assert (complaint->fmt == fmt);
-
if (deprecated_warning_hook)
(*deprecated_warning_hook) (fmt, args);
else
@@ -150,10 +101,7 @@ clear_complaints (int less_verbose)
{
struct complain *p;
- for (p = symfile_complaint_book.root; p != NULL; p = p->next)
- {
- p->counter = 0;
- }
+ counters.clear ();
if (!less_verbose)
symfile_complaint_book.series = ISOLATED_MESSAGE;