From patchwork Sat Dec 9 00:00:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 24840 Received: (qmail 46401 invoked by alias); 9 Dec 2017 00:00:39 -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 45885 invoked by uid 89); 9 Dec 2017 00:00:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 09 Dec 2017 00:00:13 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4E56821C3 for ; Sat, 9 Dec 2017 00:00:12 +0000 (UTC) Received: from cascais.lan (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A8F617A89 for ; Sat, 9 Dec 2017 00:00:11 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed] dwarf2read.c: Rewrite/simplify mock_mapped_index Date: Sat, 9 Dec 2017 00:00:10 +0000 Message-Id: <1512777610-10140-1-git-send-email-palves@redhat.com> Now that dw2_expand_symtabs_matching_symbol works with the abstract mapped_index_base, we can make mock_mapped_index inherit mapped_index_base too instead of having it pretend to be a real .gdb_index table. gdb/ChangeLog: 2017-12-08 Pedro Alves * dwarf2read.c (mock_mapped_index): Reimplement as an extension of mapped_index_base. (check_match): Adjust to use mock_index directly. (check_find_bounds_finds) (test_mapped_index_find_name_component_bounds): Adjust to work with a mapped_index_base. --- gdb/ChangeLog | 9 +++++++ gdb/dwarf2read.c | 73 ++++++++++++++++++++++---------------------------------- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c4c7e79..1d38113 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2017-12-08 Pedro Alves + * dwarf2read.c (mock_mapped_index): Reimplement as an extension of + mapped_index_base. + (check_match): Adjust to use mock_index directly. + (check_find_bounds_finds) + (test_mapped_index_find_name_component_bounds): Adjust to work + with a mapped_index_base. + +2017-12-08 Pedro Alves + * dwarf2read.c (struct mapped_index_base): New, partially factored out from ... (struct mapped_index): ... this. Inherit mapped_index_base. diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 8de7efd..2aeb506 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -4838,50 +4838,33 @@ dw2_expand_symtabs_matching_symbol namespace selftests { namespace dw2_expand_symtabs_matching { -/* A wrapper around mapped_index that builds a mock mapped_index, from - the symbol list passed as parameter to the constructor. */ -class mock_mapped_index +/* A mock .gdb_index/.debug_names-like name index table, enough to + exercise dw2_expand_symtabs_matching_symbol, which works with the + mapped_index_base interface. Builds an index from the symbol list + passed as parameter to the constructor. */ +class mock_mapped_index : public mapped_index_base { public: - template - mock_mapped_index (const char *(&symbols)[N]) - : mock_mapped_index (symbols, N) + mock_mapped_index (gdb::array_view symbols) + : m_symbol_table (symbols) {} - /* Access the built index. */ - mapped_index &index () - { return m_index; } + DISABLE_COPY_AND_ASSIGN (mock_mapped_index); - /* Disable copy. */ - mock_mapped_index(const mock_mapped_index &) = delete; - void operator= (const mock_mapped_index &) = delete; - -private: - mock_mapped_index (const char **symbols, size_t symbols_size) + /* Return the number of names in the symbol table. */ + virtual size_t symbol_name_count () const { - /* No string can live at offset zero. Add a dummy entry. */ - obstack_grow_str0 (&m_constant_pool, ""); - - for (size_t i = 0; i < symbols_size; i++) - { - const char *sym = symbols[i]; - size_t offset = obstack_object_size (&m_constant_pool); - obstack_grow_str0 (&m_constant_pool, sym); - m_symbol_table.push_back ({offset, 0}); - }; - - m_index.constant_pool = (const char *) obstack_base (&m_constant_pool); - m_index.symbol_table = m_symbol_table; + return m_symbol_table.size (); } -public: - /* The built mapped_index. */ - mapped_index m_index{}; + /* Get the name of the symbol at IDX in the symbol table. */ + virtual const char *symbol_name_at (offset_type idx) const + { + return m_symbol_table[idx]; + } - /* The storage that the built mapped_index uses for symbol and - constant pool tables. */ - std::vector m_symbol_table; - auto_obstack m_constant_pool; +private: + gdb::array_view m_symbol_table; }; /* Convenience function that converts a NULL pointer to a "" @@ -4926,11 +4909,11 @@ check_match (const char *file, int line, auto expected_it = expected_list.begin (); auto expected_end = expected_list.end (); - dw2_expand_symtabs_matching_symbol (mock_index.index (), lookup_name, + dw2_expand_symtabs_matching_symbol (mock_index, lookup_name, NULL, ALL_DOMAIN, [&] (offset_type idx) { - const char *matched_name = mock_index.index ().symbol_name_at (idx); + const char *matched_name = mock_index.symbol_name_at (idx); const char *expected_str = expected_it == expected_end ? NULL : *expected_it++; @@ -4990,12 +4973,12 @@ static const char *test_symbols[] = { Z_SYM_NAME }; -/* Returns true if the mapped_index::find_name_component_bounds method - finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME, in - completion mode. */ +/* Returns true if the mapped_index_base::find_name_component_bounds + method finds EXPECTED_SYMS in INDEX when looking for SEARCH_NAME, + in completion mode. */ static bool -check_find_bounds_finds (mapped_index &index, +check_find_bounds_finds (mapped_index_base &index, const char *search_name, gdb::array_view expected_syms) { @@ -5027,7 +5010,7 @@ test_mapped_index_find_name_component_bounds () { mock_mapped_index mock_index (test_symbols); - mock_index.index ().build_name_components (); + mock_index.build_name_components (); /* Test the lower-level mapped_index::find_name_component_bounds method in completion mode. */ @@ -5037,7 +5020,7 @@ test_mapped_index_find_name_component_bounds () "t1_func1", }; - SELF_CHECK (check_find_bounds_finds (mock_index.index (), + SELF_CHECK (check_find_bounds_finds (mock_index, "t1_func", expected_syms)); } @@ -5048,13 +5031,13 @@ test_mapped_index_find_name_component_bounds () "\377", "\377\377123", }; - SELF_CHECK (check_find_bounds_finds (mock_index.index (), + SELF_CHECK (check_find_bounds_finds (mock_index, "\377", expected_syms1)); static const char *expected_syms2[] = { "\377\377123", }; - SELF_CHECK (check_find_bounds_finds (mock_index.index (), + SELF_CHECK (check_find_bounds_finds (mock_index, "\377\377", expected_syms2)); } }