From patchwork Tue May 22 05:07:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27389 Received: (qmail 27770 invoked by alias); 22 May 2018 05:08:17 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 5955 invoked by uid 89); 22 May 2018 05:07:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=bottle, Prime, neck, complain X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.144.98) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 May 2018 05:07:22 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 97CA5BE627 for ; Tue, 22 May 2018 00:07:09 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id KzVtf4oN5QUwqKzVtfky0x; Tue, 22 May 2018 00:07:09 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:36532 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fKzVt-003pV7-CN; Tue, 22 May 2018 00:07:09 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 8/9] Remove struct complain Date: Mon, 21 May 2018 23:07:03 -0600 Message-Id: <20180522050704.10845-9-tom@tromey.com> In-Reply-To: <20180522050704.10845-1-tom@tromey.com> References: <20180522050704.10845-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fKzVt-003pV7-CN X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:36532 X-Source-Auth: tom+tromey.com X-Email-Count: 9 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes 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 * complaints.c (counters): New global. (struct complain): Remove. (struct complaints) : Remove. (complaint_sentinel): Remove. (symfile_complaint_book): Update. (find_complaint) Remove. (complaint_internal, clear_complaints): Update. gdb/testsuite/ChangeLog 2018-05-21 Tom Tromey * 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 /* 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 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!\")" \