From patchwork Mon Mar 4 14:52:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Vrany X-Patchwork-Id: 31707 Received: (qmail 91639 invoked by alias); 4 Mar 2019 14:52:16 -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 91631 invoked by uid 89); 4 Mar 2019 14:52:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=TEXT, H*r:may, H*r:forged, Hx-languages-length:4559 X-HELO: relay.fit.cvut.cz Received: from relay.fit.cvut.cz (HELO relay.fit.cvut.cz) (147.32.232.237) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 04 Mar 2019 14:52:14 +0000 Received: from imap.fit.cvut.cz (imap.fit.cvut.cz [147.32.232.238]) by relay.fit.cvut.cz (8.15.2/8.15.2) with ESMTPS id x24EqAd7022035 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 4 Mar 2019 15:52:11 +0100 (CET) (envelope-from jan.vrany@fit.cvut.cz) Received: from localhost (02d97f37.bb.sky.com [2.217.127.55] (may be forged)) (authenticated bits=0 as user vranyj1) by imap.fit.cvut.cz (8.15.2/8.15.2) with ESMTPSA id x24Eq9mm033203 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Mon, 4 Mar 2019 15:52:09 +0100 (CET) (envelope-from jan.vrany@fit.cvut.cz) From: Jan Vrany To: gdb-patches@sourceware.org Cc: Jan Vrany Subject: [PATCH v3 1/2] MI: extract command completion logic from complete_command() Date: Mon, 4 Mar 2019 14:52:02 +0000 Message-Id: <20190304145203.11039-2-jan.vrany@fit.cvut.cz> In-Reply-To: <20190128124101.26243-1-jan.vrany@fit.cvut.cz> References: <20190128124101.26243-1-jan.vrany@fit.cvut.cz> MIME-Version: 1.0 Extract completion logic from CLI complete_command() into a new helper function complete(). gdb/Changelog: * completer.h (complete): New function. * completer.c (complete): Likewise. * cli/cli-cmds.c: (complete_command): Update to use new complete() function defined in completer.h. --- gdb/ChangeLog | 7 +++++++ gdb/cli/cli-cmds.c | 30 +----------------------------- gdb/completer.c | 36 ++++++++++++++++++++++++++++++++++++ gdb/completer.h | 7 +++++++ 4 files changed, 51 insertions(+), 29 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8e03dbf883..be65f4a2d6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2019-01-24 Jan Vrany + + * completer.h (complete): New function. + * completer.c (complete): Likewise. + * cli/cli-cmds.c: (complete_command): Update to use new complete() + function defined in completer.h. + 2019-01-22 Philippe Waroquiers * event-top.c (handle_line_of_input): use unique_xmalloc_ptr for diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 57cfad441c..bb0494719c 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -243,41 +243,13 @@ complete_command (const char *arg, int from_tty) if (arg == NULL) arg = ""; - completion_tracker tracker_handle_brkchars; - completion_tracker tracker_handle_completions; - completion_tracker *tracker; - int quote_char = '\0'; const char *word; - TRY - { - word = completion_find_completion_word (tracker_handle_brkchars, - arg, "e_char); - - /* Completers that provide a custom word point in the - handle_brkchars phase also compute their completions then. - Completers that leave the completion word handling to readline - must be called twice. */ - if (tracker_handle_brkchars.use_custom_word_point ()) - tracker = &tracker_handle_brkchars; - else - { - complete_line (tracker_handle_completions, word, arg, strlen (arg)); - tracker = &tracker_handle_completions; - } - } - CATCH (ex, RETURN_MASK_ALL) - { - return; - } - END_CATCH + completion_result result = complete (arg, &word, "e_char); std::string arg_prefix (arg, word - arg); - completion_result result - = tracker->build_completion_result (word, word - arg, strlen (arg)); - if (result.number_matches != 0) { if (result.number_matches == 1) diff --git a/gdb/completer.c b/gdb/completer.c index fed815a53c..e3d81d6226 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -1615,6 +1615,42 @@ make_completion_match_str (gdb::unique_xmalloc_ptr &&match_name, return gdb::unique_xmalloc_ptr (newobj); } +/* See complete.h. */ + +completion_result +complete (const char *line, char const **word, int *quote_char) +{ + completion_tracker tracker_handle_brkchars; + completion_tracker tracker_handle_completions; + completion_tracker *tracker; + + TRY + { + *word = completion_find_completion_word (tracker_handle_brkchars, + line, quote_char); + + /* Completers that provide a custom word point in the + handle_brkchars phase also compute their completions then. + Completers that leave the completion word handling to readline + must be called twice. */ + if (tracker_handle_brkchars.use_custom_word_point ()) + tracker = &tracker_handle_brkchars; + else + { + complete_line (tracker_handle_completions, *word, line, strlen (line)); + tracker = &tracker_handle_completions; + } + } + CATCH (ex, RETURN_MASK_ALL) + { + return {}; + } + END_CATCH + + return tracker->build_completion_result (*word, *word - line, strlen (line)); +} + + /* Generate completions all at once. Does nothing if max_completions is 0. If max_completions is non-negative, this will collect at most max_completions strings. diff --git a/gdb/completer.h b/gdb/completer.h index e81243a721..a46f8cf22a 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -510,6 +510,13 @@ extern void complete_line (completion_tracker &tracker, const char *line_buffer, int point); +/* Complete LINE and return completion results. For completion purposes, + cursor position is assumed to be at the end of LINE. WORD is set to + the end of word to complete. QUOTE_CHAR is set to the opening quote + character if we found an unclosed quoted substring, '\0' otherwise. */ +extern completion_result + complete (const char *line, char const **word, int *quote_char); + /* Find the bounds of the word in TEXT for completion purposes, and return a pointer to the end of the word. Calls the completion machinery for a handle_brkchars phase (using TRACKER) to figure out