From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 8/9] Remove struct complain
Date: Tue, 22 May 2018 05:09:00 -0000 [thread overview]
Message-ID: <20180522050704.10845-9-tom@tromey.com> (raw)
In-Reply-To: <20180522050704.10845-1-tom@tromey.com>
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-21 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-21 Tom Tromey <tom@tromey.com>
* gdb.gdb/complaints.exp (test_initial_complaints): Simplify.
---
gdb/ChangeLog | 10 ++++++
gdb/complaints.c | 62 +++---------------------------------
gdb/testsuite/ChangeLog | 4 +++
gdb/testsuite/gdb.gdb/complaints.exp | 16 +++-------
4 files changed, 23 insertions(+), 69 deletions(-)
diff --git a/gdb/complaints.c b/gdb/complaints.c
index 851d8f5d6f..2c69b8ca2c 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;
diff --git a/gdb/testsuite/gdb.gdb/complaints.exp b/gdb/testsuite/gdb.gdb/complaints.exp
index 886b43521d..65b6bdc281 100644
--- a/gdb/testsuite/gdb.gdb/complaints.exp
+++ b/gdb/testsuite/gdb.gdb/complaints.exp
@@ -57,26 +57,18 @@ proc test_initial_complaints { } {
# Unsupress complaints
gdb_test "set stop_whining = 2"
+ gdb_test_no_output "set var \$cstr = \"Register a complaint\""
+
# Prime the system
gdb_test_stdio \
- "call complaint_internal (\"Register a complaint\")" \
+ "call complaint_internal (\$cstr)" \
"During symbol reading, Register a complaint."
- # Check that the complaint was inserted and where
- gdb_test "print symfile_complaint_book.root->fmt" \
- ".\[0-9\]+ =.*\"Register a complaint\""
-
# Re-issue the first message #1
gdb_test_stdio \
- "call complaint_internal (symfile_complaint_book.root->fmt)" \
+ "call complaint_internal (\$cstr)" \
"During symbol reading, Register a complaint."
- # Check that there is only one thing in the list. How the boolean
- # result is output depends on whether GDB is built as a C or C++
- # program.
- gdb_test "print symfile_complaint_book.root->next == &complaint_sentinel" \
- ".\[0-9\]+ = \(1|true\)" "list has one entry"
-
# Add a second complaint, expect it
gdb_test_stdio \
"call complaint_internal (\"Testing! Testing! Testing!\")" \
--
2.13.6
next prev parent reply other threads:[~2018-05-22 5:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-22 5:09 [RFA 0/9] Radically simplify the complaint system Tom Tromey
2018-05-22 5:07 ` [RFA 9/9] Remove struct complaints Tom Tromey
2018-05-22 5:07 ` [RFA 2/9] Remove elements from complaint_series Tom Tromey
2018-05-22 5:08 ` [RFA 5/9] Remove struct explanation Tom Tromey
2018-05-22 5:08 ` [RFA 6/9] Remove vcomplaint Tom Tromey
2018-05-22 5:09 ` [RFA 1/9] Remove internal_complaint Tom Tromey
2018-05-22 5:09 ` [RFA 4/9] Remove symfile_complaints Tom Tromey
2018-05-22 5:09 ` Tom Tromey [this message]
2018-05-22 5:50 ` [RFA 3/9] Remove "noisy" parameter from clear_complaints Tom Tromey
2018-05-22 7:01 ` [RFA 7/9] Remove file and line from struct complain Tom Tromey
2018-05-23 14:49 ` [RFA 0/9] Radically simplify the complaint system Pedro Alves
2018-05-23 15:08 ` Tom Tromey
2018-05-23 17:44 ` Pedro Alves
2018-05-28 10:41 ` Tom Tromey
2018-05-28 10:41 ` Tom Tromey
2018-05-28 19:37 ` Pedro Alves
2018-05-28 22:19 ` Tom Tromey
2018-05-29 16:05 ` Pedro Alves
2018-06-04 20:25 ` Possible regression on gdb.gdb/complaints.exp (was: Re: [RFA 0/9] Radically simplify the complaint system) Sergio Durigan Junior
2018-06-04 21:38 ` Possible regression on gdb.gdb/complaints.exp Tom Tromey
2018-06-04 23:29 ` Sergio Durigan Junior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180522050704.10845-9-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox