From patchwork Tue Apr 7 08:08:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 6035 Received: (qmail 76091 invoked by alias); 7 Apr 2015 08:09:19 -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 76045 invoked by uid 89); 7 Apr 2015 08:09:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=AWL, BAYES_50, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-wg0-f46.google.com Received: from mail-wg0-f46.google.com (HELO mail-wg0-f46.google.com) (74.125.82.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 07 Apr 2015 08:09:17 +0000 Received: by wgin8 with SMTP id n8so47592888wgi.0 for ; Tue, 07 Apr 2015 01:09:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=ysFJjfr1OT4tazxqFuIp6xN6FO33WZrRQxR+6NThMOY=; b=JeJGx0PW8LJpCJyWwN1gu15DEyFyv0bQPgTUpBNuDBStxvJANH7fy1skjTtTSKrh9j SADDulfW1M/rJkgqRnsEy/Q0ewVWdlqPRFiGBEiRfakyyfVycAhjB3hd4DWvk0enDHPY +qW4St5qwvdFX7cHKxTAHhQNI1PllvPFgjGdT8Szt5aeb8tnQQlxRpvylUrj+183qwx0 RhUUaPTzXpedVH01P7NYnAThPeIcafzgtZf/u8IA0KVU2bU0TA/MDKdwrUWeIrMXJHM1 EzIjDB0yhTLV+NwBuiEioqD40Fbwg6R5SJtk2s2u6nyjgD1lBD6bta7J3jv/hpV5u82Q nP6A== X-Gm-Message-State: ALoCoQnwrqgO+X4ZgOknCaOgofSIoe6XtVGdtthdb0VsjGKr30HDD3SMxujEW6dOWL+La25AL3as X-Received: by 10.180.20.144 with SMTP id n16mr2274461wie.44.1428394153942; Tue, 07 Apr 2015 01:09:13 -0700 (PDT) Received: from localhost ([85.133.27.37]) by mx.google.com with ESMTPSA id ew5sm9855184wic.14.2015.04.07.01.09.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Apr 2015 01:09:13 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/2] gdb: Add completer for layout command. Date: Tue, 7 Apr 2015 09:08:55 +0100 Message-Id: <18d55b2f3d6b65fd7e1fef8374fbadf429e95095.1428011044.git.andrew.burgess@embecosm.com> In-Reply-To: References: In-Reply-To: References: X-IsSubscribed: yes Add layout name completion for the layout command. Some extra effort is required as some layout names use '$' which is by default a word breaking character. gdb/ChangeLog: * completer.c (set_gdb_completion_word_break_characters_string): New function. (set_gdb_completion_word_break_characters): Use new function. * completer.h (set_gdb_completion_word_break_characters_string): Declare. * tui/tui-layout.c: Add 'completer.h' include. (layout_completer): New function. (layout_brkchars): New function. (_initialize_tui_layout): Set completer and brkchars on layout command. gdb/testsuite/ChangeLog: * gdb.base/completion.exp: Add test for completion of layout names. --- gdb/ChangeLog | 13 +++++++++ gdb/completer.c | 18 +++++++++--- gdb/completer.h | 4 +++ gdb/testsuite/ChangeLog | 5 ++++ gdb/testsuite/gdb.base/completion.exp | 18 ++++++++++++ gdb/tui/tui-layout.c | 53 +++++++++++++++++++++++++++++++++-- 6 files changed, 105 insertions(+), 6 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index febc377..3507097 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,16 @@ +2015-03-26 Andrew Burgess + + * completer.c (set_gdb_completion_word_break_characters_string): + New function. + (set_gdb_completion_word_break_characters): Use new function. + * completer.h (set_gdb_completion_word_break_characters_string): + Declare. + * tui/tui-layout.c: Add 'completer.h' include. + (layout_completer): New function. + (layout_brkchars): New function. + (_initialize_tui_layout): Set completer and brkchars on layout + command. + 2015-03-25 Pedro Alves * target.h : Replace 'callback' and 'context' parameters diff --git a/gdb/completer.c b/gdb/completer.c index c8c0e4c..8b1fa41 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -457,16 +457,26 @@ expression_completer (struct cmd_list_element *ignore, /* See definition in completer.h. */ void +set_gdb_completion_word_break_characters_string (char *c) +{ + rl_completer_word_break_characters = c; +} + +/* See definition in completer.h. */ + +void set_gdb_completion_word_break_characters (completer_ftype *fn) { /* So far we are only interested in differentiating filename completers from everything else. */ + char *c; + if (fn == filename_completer) - rl_completer_word_break_characters - = gdb_completer_file_name_break_characters; + c = gdb_completer_file_name_break_characters; else - rl_completer_word_break_characters - = gdb_completer_command_word_break_characters; + c = gdb_completer_command_word_break_characters; + + set_gdb_completion_word_break_characters_string (c); } /* Here are some useful test cases for completion. FIXME: These diff --git a/gdb/completer.h b/gdb/completer.h index 56e1a2b..5e62828 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -107,6 +107,10 @@ extern char *gdb_completion_word_break_characters (void); extern void set_gdb_completion_word_break_characters (completer_ftype *fn); +/* Set the word break characters array to the set STR. */ + +extern void set_gdb_completion_word_break_characters_string (char *STR); + /* Exported to linespec.c */ extern const char *skip_quoted_chars (const char *, const char *, diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 6abb62f..ee9fc77 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2015-03-27 Andrew Burgess + * gdb.base/completion.exp: Add test for completion of layout + names. + +2015-03-27 Andrew Burgess + * lib/gdb.exp (skip_tui_tests): New proc. * gdb.base/tui-layout.exp: Check skip_tui_tests. diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp index f77bfe2..43a4e1e 100644 --- a/gdb/testsuite/gdb.base/completion.exp +++ b/gdb/testsuite/gdb.base/completion.exp @@ -859,3 +859,21 @@ gdb_test_multiple "" "$test" { pass "$test" } } + +gdb_test_no_output "set max-completions unlimited" + +if {![skip_tui_tests]} { + set test "test completion of layout names" + send_gdb "layout\t\t\t" + gdb_test_multiple "" "$test" { + -re "\\\$fregs \\\$gregs \\\$regs \\\$sregs asm next prev regs split src *\r\n$gdb_prompt layout $" { + pass "$test" + } + } + send_gdb "\003" + gdb_test_multiple "" "$test" { + -re "$gdb_prompt $" { + pass "quit command input after testing layout completion" + } + } +} diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index 6547404..e05418f 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -25,6 +25,7 @@ #include "symtab.h" #include "frame.h" #include "source.h" +#include "completer.h" #include #include "tui/tui.h" @@ -373,6 +374,50 @@ tui_default_win_viewport_height (enum tui_win_type type, return h; } +/* Complete possible layout names. TEXT is the complete text entered so + far, WORD is the word currently being completed. */ + +static VEC (char_ptr) * +layout_completer (struct cmd_list_element *ignore, + const char *text, const char *word) +{ + VEC (char_ptr) *return_val = NULL; + const char **tmp, *p; + size_t len; + + static const char *layout_names [] = + { "src", "asm", "split", "regs", "next", "prev", + TUI_FLOAT_REGS_NAME_LOWER, + TUI_GENERAL_REGS_NAME_LOWER, + TUI_SPECIAL_REGS_NAME_LOWER, + TUI_GENERAL_SPECIAL_REGS_NAME_LOWER, + NULL }; + + gdb_assert (text != NULL); + p = strchr (text, ' '); + len = (p == NULL) ? strlen (text) : p - text; + + for (tmp = layout_names; *tmp != NULL; ++tmp) + { + if (strncmp (text, *tmp, len) == 0) + { + char *str = xstrdup (*tmp); + VEC_safe_push (char_ptr, return_val, str); + } + } + + return return_val; +} + +static void +layout_brkchars (struct cmd_list_element *command, + const char *text, const char *word) +{ + /* This set of characters should be the same set returned by + DEFAULT_WORD_BREAK_CHARACTERS but with '$' removed. */ + set_gdb_completion_word_break_characters_string + (" \t\n!@#%^&*()+=|~`}{[]\"';:?/>.<,"); +} /* Function to initialize gdb commands, for tui window layout manipulation. */ @@ -383,8 +428,10 @@ extern initialize_file_ftype _initialize_tui_layout; void _initialize_tui_layout (void) { - add_com ("layout", class_tui, tui_layout_command, _("\ -Change the layout of windows.\n\ + struct cmd_list_element *cmd; + + cmd = add_com ("layout", class_tui, tui_layout_command, _("\ +Change the layout of windows.\n \ Usage: layout prev | next | \n\ Layout names are:\n\ src : Displays source and command windows.\n\ @@ -396,6 +443,8 @@ Layout names are:\n\ source/assembly/command (split) is displayed, \n\ the register window is displayed with \n\ the window that has current logical focus.\n")); + set_cmd_completer (cmd, layout_completer); + set_cmd_completer_handle_brkchars (cmd, layout_brkchars); if (xdb_commands) { add_com ("td", class_tui, tui_toggle_layout_command, _("\