From patchwork Thu Jan 23 00:56:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37484 Received: (qmail 80143 invoked by alias); 23 Jan 2020 00:57:31 -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 80034 invoked by uid 89); 23 Jan 2020 00:57:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 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.1 spammy= X-HELO: gateway34.websitewelcome.com Received: from gateway34.websitewelcome.com (HELO gateway34.websitewelcome.com) (192.185.148.119) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 00:57:23 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway34.websitewelcome.com (Postfix) with ESMTP id E1C0510C290C for ; Wed, 22 Jan 2020 18:57:21 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id uQoDigBAINBC3uQoDiy06z; Wed, 22 Jan 2020 18:57:21 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=TP21yYy26b7D+SdhjTnsGeC6J+9CWZf2OJpRclOqkAg=; b=W6tDfB6vlBxOjnslp4ASCfO3v/ YAI4XYJFMjWrM6O7q1o0bGzPoJ3mmIOeMZVqlS9MTbs6q+IWaHkUg/SCF53fWFuE7i+hg2loNh6xY cKxbD6PXfY8HLi1af43Ng44Gn; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:40826 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1iuQoD-004Kis-N6; Wed, 22 Jan 2020 17:57:21 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 13/38] Remove DWARF queue-related globals Date: Wed, 22 Jan 2020 17:56:45 -0700 Message-Id: <20200123005710.7978-14-tom@tromey.com> In-Reply-To: <20200123005710.7978-1-tom@tromey.com> References: <20200123005710.7978-1-tom@tromey.com> This removes some queue-related globals from the DWARF reader, in favor of a new member on dwarf2_per_objfile. Globals must be avoided in this code, because they prevent multi-threading the reader. gdb/ChangeLog 2020-01-22 Tom Tromey * dwarf2/read.h (struct dwarf2_queue_item): Move from dwarf2/read.c. Remove "next" member. Add constructor ntad destructor. (struct dwarf2_per_objfile) : New member. * dwarf2/read.c (struct dwarf2_queue_item): Move to dwarf2/read.h. (dwarf2_queue, dwarf2_queue_tail): Remove. (class dwarf2_queue_guard): Add parameter to constructor. Use DISABLE_COPY_AND_ASSIGN. : New member. <~dwarf2_queue_guard>: Rewrite. (dw2_do_instantiate_symtab, queue_comp_unit, process_queue): Update. (~dwarf2_queue_item): New. Change-Id: Ied1f6ff3691352a66c4709b0b2cba0588f49f79a --- gdb/ChangeLog | 17 +++++++++ gdb/dwarf2/read.c | 96 ++++++++++++++++++----------------------------- gdb/dwarf2/read.h | 23 ++++++++++++ 3 files changed, 76 insertions(+), 60 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index a35a55673dc..1e64870678e 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1335,18 +1335,6 @@ struct field_info std::vector nested_types_list; }; -/* One item on the queue of compilation units to read in full symbols - for. */ -struct dwarf2_queue_item -{ - struct dwarf2_per_cu_data *per_cu; - enum language pretend_language; - struct dwarf2_queue_item *next; -}; - -/* The current queue. */ -static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; - /* Loaded secondary compilation units are kept in memory until they have not been referenced for the processing of this many compilation units. Set this to zero to disable caching. Cache @@ -1818,35 +1806,38 @@ static struct type *dwarf2_per_cu_int_type class dwarf2_queue_guard { public: - dwarf2_queue_guard () = default; + explicit dwarf2_queue_guard (dwarf2_per_objfile *per_objfile) + : m_per_objfile (per_objfile) + { + } /* Free any entries remaining on the queue. There should only be entries left if we hit an error while processing the dwarf. */ ~dwarf2_queue_guard () { - struct dwarf2_queue_item *item, *last; - - item = dwarf2_queue; - while (item) - { - /* Anything still marked queued is likely to be in an - inconsistent state, so discard it. */ - if (item->per_cu->queued) - { - if (item->per_cu->cu != NULL) - free_one_cached_comp_unit (item->per_cu); - item->per_cu->queued = 0; - } + /* Ensure that no memory is allocated by the queue. */ + std::queue empty; + std::swap (m_per_objfile->queue, empty); + } - last = item; - item = item->next; - xfree (last); - } + DISABLE_COPY_AND_ASSIGN (dwarf2_queue_guard); - dwarf2_queue = dwarf2_queue_tail = NULL; - } +private: + dwarf2_per_objfile *m_per_objfile; }; +dwarf2_queue_item::~dwarf2_queue_item () +{ + /* Anything still marked queued is likely to be in an + inconsistent state, so discard it. */ + if (per_cu->queued) + { + if (per_cu->cu != NULL) + free_one_cached_comp_unit (per_cu); + per_cu->queued = 0; + } +} + /* The return type of find_file_and_directory. Note, the enclosed string pointers are only valid while this object is valid. */ @@ -2582,7 +2573,7 @@ dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial) /* The destructor of dwarf2_queue_guard frees any entries left on the queue. After this point we're guaranteed to leave this function with the dwarf queue empty. */ - dwarf2_queue_guard q_guard; + dwarf2_queue_guard q_guard (dwarf2_per_objfile); if (dwarf2_per_objfile->using_index ? per_cu->v.quick->compunit_symtab == NULL @@ -9188,20 +9179,8 @@ static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, enum language pretend_language) { - struct dwarf2_queue_item *item; - per_cu->queued = 1; - item = XNEW (struct dwarf2_queue_item); - item->per_cu = per_cu; - item->pretend_language = pretend_language; - item->next = NULL; - - if (dwarf2_queue == NULL) - dwarf2_queue = item; - else - dwarf2_queue_tail->next = item; - - dwarf2_queue_tail = item; + per_cu->dwarf2_per_objfile->queue.emplace (per_cu, pretend_language); } /* If PER_CU is not yet queued, add it to the queue. @@ -9256,8 +9235,6 @@ maybe_queue_comp_unit (struct dwarf2_cu *dependent_cu, static void process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile) { - struct dwarf2_queue_item *item, *next_item; - if (dwarf_read_debug) { fprintf_unfiltered (gdb_stdlog, @@ -9267,15 +9244,17 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile) /* The queue starts out with one item, but following a DIE reference may load a new CU, adding it to the end of the queue. */ - for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) + while (!dwarf2_per_objfile->queue.empty ()) { + dwarf2_queue_item &item = dwarf2_per_objfile->queue.front (); + if ((dwarf2_per_objfile->using_index - ? !item->per_cu->v.quick->compunit_symtab - : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) + ? !item.per_cu->v.quick->compunit_symtab + : (item.per_cu->v.psymtab && !item.per_cu->v.psymtab->readin)) /* Skip dummy CUs. */ - && item->per_cu->cu != NULL) + && item.per_cu->cu != NULL) { - struct dwarf2_per_cu_data *per_cu = item->per_cu; + struct dwarf2_per_cu_data *per_cu = item.per_cu; unsigned int debug_print_threshold; char buf[100]; @@ -9302,21 +9281,18 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile) fprintf_unfiltered (gdb_stdlog, "Expanding symtab of %s\n", buf); if (per_cu->is_debug_types) - process_full_type_unit (per_cu, item->pretend_language); + process_full_type_unit (per_cu, item.pretend_language); else - process_full_comp_unit (per_cu, item->pretend_language); + process_full_comp_unit (per_cu, item.pretend_language); if (dwarf_read_debug >= debug_print_threshold) fprintf_unfiltered (gdb_stdlog, "Done expanding %s\n", buf); } - item->per_cu->queued = 0; - next_item = item->next; - xfree (item); + item.per_cu->queued = 0; + dwarf2_per_objfile->queue.pop (); } - dwarf2_queue_tail = NULL; - if (dwarf_read_debug) { fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n", diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 9752abc5e4c..9c671806479 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -20,6 +20,7 @@ #ifndef DWARF2READ_H #define DWARF2READ_H +#include #include #include "dwarf2/index-cache.h" #include "dwarf2/section.h" @@ -43,10 +44,29 @@ struct tu_stats }; struct dwarf2_debug_sections; +struct dwarf2_per_cu_data; struct mapped_index; struct mapped_debug_names; struct signatured_type; +/* One item on the queue of compilation units to read in full symbols + for. */ +struct dwarf2_queue_item +{ + dwarf2_queue_item (dwarf2_per_cu_data *cu, enum language lang) + : per_cu (cu), + pretend_language (lang) + { + } + + ~dwarf2_queue_item (); + + DISABLE_COPY_AND_ASSIGN (dwarf2_queue_item); + + struct dwarf2_per_cu_data *per_cu; + enum language pretend_language; +}; + /* Collection of data recorded per objfile. This hangs off of dwarf2_objfile_data_key. */ @@ -214,6 +234,9 @@ public: std::unordered_map, gdb::hash_enum> abstract_to_concrete; + + /* CUs that are queued to be read. */ + std::queue queue; }; /* Get the dwarf2_per_objfile associated to OBJFILE. */