From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108369 invoked by alias); 27 Nov 2017 17:11:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 107768 invoked by uid 89); 27 Nov 2017 17:11:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_STOCKGEN,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=pairing 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; Mon, 27 Nov 2017 17:11:47 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B827882FF for ; Mon, 27 Nov 2017 17:11:46 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27D4F60C95; Mon, 27 Nov 2017 17:11:44 +0000 (UTC) Subject: Re: [PATCH 31/40] Handle custom completion match prefix / LCD To: Keith Seitz , gdb-patches@sourceware.org References: <1496406158-12663-1-git-send-email-palves@redhat.com> <1496406158-12663-32-git-send-email-palves@redhat.com> From: Pedro Alves Message-ID: <72128d5b-b3f6-a7c0-9692-08e9a3955369@redhat.com> Date: Mon, 27 Nov 2017 17:11:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-11/txt/msg00688.txt.bz2 On 08/08/2017 10:27 PM, Keith Seitz wrote: > On 06/02/2017 05:22 AM, Pedro Alves wrote: > >> diff --git a/gdb/completer.h b/gdb/completer.h >> index df90822..db781ab 100644 >> --- a/gdb/completer.h >> +++ b/gdb/completer.h >> @@ -116,12 +116,44 @@ private: >> std::string m_storage; >> }; >> >> +/* The result of a successful completion match, but for least common >> + denominator (LCD) computation. Some completers provide matches >> + that don't start with the completion "word". E.g., completing on >> + "b push_ba" on a C++ program usually completes to >> + std::vector<...>::push_back, std::string::push_back etc. In such >> + case, the symbol comparison routine will set the LCD match to point >> + into the "push_back" substring within the symbol's name string. */ > > [missing newline?] Fixed. > >> +class completion_match_for_lcd >> +{ >> +public: >> + /* Set the match for LCD. See m_match's description. */ >> + void set_match (const char *match) >> + { m_match = match; } >> + >> + /* Get the resulting LCD, after a successful match. */ >> + const char *finish () >> + { return m_match; } >> + >> + /* Prepare for another completion matching sequence. */ >> + void clear () >> + { m_match = NULL; } >> + >> +private: >> + /* The completion match result for LCD. This is usually either a >> + pointer into to a substring within a symbol's name, or to the >> + storage of the pairing completion_match object. */ >> + const char *m_match; >> +}; >> + >> /* Convenience aggregate holding info returned by the symbol name >> matching routines (see symbol_name_matcher_ftype). */ >> struct completion_match_result >> { >> /* The completion match candidate. */ >> completion_match match; >> + >> + /* The completion match, for LCD computation purposes. */ >> + completion_match_for_lcd match_for_lcd; >> }; >> >> /* The final result of a completion that is handed over to either >> diff --git a/gdb/cp-support.c b/gdb/cp-support.c >> index 064a45b..397c738 100644 >> --- a/gdb/cp-support.c >> +++ b/gdb/cp-support.c >> @@ -1660,8 +1660,11 @@ cp_fq_symbol_name_matches (const char *symbol_search_name, >> name.c_str (), name.size (), >> mode) == 0) >> { >> - if (match != NULL) >> - match->set_match (symbol_search_name); >> + if (comp_match_res != NULL) >> + { >> + comp_match_res->match.set_match (symbol_search_name); >> + comp_match_res->match_for_lcd.set_match (symbol_search_name); >> + } >> return true; >> } >> >> diff --git a/gdb/language.c b/gdb/language.c >> index 6705a3b..511a86f 100644 >> --- a/gdb/language.c >> +++ b/gdb/language.c >> @@ -725,8 +725,11 @@ default_symbol_name_matcher (const char *symbol_search_name, >> if (strncmp_iw_with_mode (symbol_search_name, name.c_str (), name.size (), >> mode) == 0) >> { >> - if (match != NULL) >> - match->set_match (symbol_search_name); >> + if (comp_match_res != NULL) >> + { >> + comp_match_res->match.set_match (symbol_search_name); >> + comp_match_res->match_for_lcd.set_match (symbol_search_name); >> + } >> return true; >> } >> else > > In the above two hunks, the code calls result->match.set_match (A) > and result->match_for_lcd.set_match (A), i.e., both these calls take the > same argument and are called at the same time. > > Furthermore, on the final series of the patch, > > $ grep -n set_match\ \( *.c > ada-lang.c:6416: comp_match_res->match.set_match (match_str.c_str ()); > ada-lang.c:6417: comp_match_res->match_for_lcd.set_match (match_str.c_str ()); > ada-lang.c:6426: comp_match_res->match.set_match (match_str.c_str ()); > ada-lang.c:6427: comp_match_res->match_for_lcd.set_match (match_str.c_str ()); > cp-support.c:1734: comp_match_res->match.set_match (symbol_search_name); > cp-support.c:1735: comp_match_res->match_for_lcd.set_match (sname); > cp-support.c:1773: comp_match_res->match.set_match (symbol_search_name); > cp-support.c:1774: comp_match_res->match_for_lcd.set_match (symbol_search_name); > language.c:725: comp_match_res->match.set_match (symbol_search_name); > language.c:726: comp_match_res->match_for_lcd.set_match (symbol_search_name); > > It appears that these two are /always/ called together, suggesting that > completion_match_result might "benefit" from a convenience method to set both > of these parameters at the same time. [Unless there is a specific reason > not to do this, of course.] WDYT? OK, I'm folding the below into the series. (I'm posting a v2 in a bit.) >From cc3d60557be486a0eb317e6920ccb323a76617c8 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 27 Nov 2017 12:26:31 +0000 Subject: [PATCH] set_match --- gdb/ada-lang.c | 10 +++------- gdb/completer.h | 11 +++++++++++ gdb/cp-support.c | 29 +++++++++++++++++++++++------ gdb/language.c | 5 +---- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index cad9d7c..38d1ce6 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -6420,11 +6420,7 @@ ada_lookup_name_info::matches std::string &match_str = comp_match_res->match.storage (); if (!m_encoded_p) - { - match_str = ada_decode (sym_name); - comp_match_res->match.set_match (match_str.c_str ()); - comp_match_res->match_for_lcd.set_match (match_str.c_str ()); - } + match_str = ada_decode (sym_name); else { if (m_verbatim_p) @@ -6432,9 +6428,9 @@ ada_lookup_name_info::matches else match_str = sym_name; - comp_match_res->match.set_match (match_str.c_str ()); - comp_match_res->match_for_lcd.set_match (match_str.c_str ()); } + + comp_match_res->set_match (match_str.c_str ()); } return true; diff --git a/gdb/completer.h b/gdb/completer.h index 97611e4..f756412 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -155,6 +155,17 @@ struct completion_match_result /* The completion match, for LCD computation purposes. */ completion_match_for_lcd match_for_lcd; + + /* Convenience that sets both MATCH and MATCH_FOR_LCD. M_FOR_LCD is + optional. If not specified, defaults to M. */ + void set_match (const char *m, const char *m_for_lcd = NULL) + { + match.set_match (m); + if (m_for_lcd == NULL) + match_for_lcd.set_match (m); + else + match_for_lcd.set_match (m_for_lcd); + } }; /* The final result of a completion that is handed over to either diff --git a/gdb/cp-support.c b/gdb/cp-support.c index 4c78af8..172d821 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -1682,8 +1682,28 @@ cp_symbol_name_matches_1 (const char *symbol_search_name, { if (comp_match_res != NULL) { - comp_match_res->match.set_match (symbol_search_name); - comp_match_res->match_for_lcd.set_match (sname); + /* Note here we set different MATCH and MATCH_FOR_LCD + strings. This is because with + + (gdb) b push_bac[TAB] + + we want the completion matches to list + + std::vector::push_back(...) + std::vector::push_back(...) + + etc., which are SYMBOL_SEARCH_NAMEs, while we want + the input line to auto-complete to + + (gdb) push_back(...) + + which is SNAME, not to + + (gdb) std::vector< + + which would be the regular common prefix between all + the matches otherwise. */ + comp_match_res->set_match (symbol_search_name, sname); } return true; } @@ -1718,10 +1738,7 @@ cp_fq_symbol_name_matches (const char *symbol_search_name, mode, language_cplus) == 0) { if (comp_match_res != NULL) - { - comp_match_res->match.set_match (symbol_search_name); - comp_match_res->match_for_lcd.set_match (symbol_search_name); - } + comp_match_res->set_match (symbol_search_name); return true; } diff --git a/gdb/language.c b/gdb/language.c index 64ef7e0..c05b703 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -716,10 +716,7 @@ default_symbol_name_matcher (const char *symbol_search_name, mode, language_minimal) == 0) { if (comp_match_res != NULL) - { - comp_match_res->match.set_match (symbol_search_name); - comp_match_res->match_for_lcd.set_match (symbol_search_name); - } + comp_match_res->set_match (symbol_search_name); return true; } else -- 2.5.5 > >> diff --git a/gdb/symtab.h b/gdb/symtab.h >> index d68eed8..736fea0 100644 >> --- a/gdb/symtab.h >> +++ b/gdb/symtab.h >> @@ -292,15 +292,21 @@ private: >> >> SYMBOL_SEARCH_NAME should be a symbol's "search" name. >> >> - On success and if non-NULL, MATCH is set to point to the symbol >> - name as should be presented to the user as a completion match list >> - element. In most languages, this is the same as the symbol's >> - search name, but in some, like Ada, the display name is dynamically >> - computed within the comparison routine. */ >> + On success and if non-NULL, COMP_MATCH_RES->match is set to point >> + to the symbol name as should be presented to the user as a >> + completion match list element. In most languages, this is the same >> + as the symbol's search name, but in some, like Ada, the display >> + name is dynamically computed within the comparison routine. >> + >> + Also, on success and if non-NULL, COMP_MATCH_RES->match_for_lcd >> + points the part of SYMBOL_SEARCH_NAME that was considered to match > ^ > missing "to" Fixed, thanks. -- Pedro Alves