From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 770 invoked by alias); 28 Mar 2013 09:26:37 -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 678 invoked by uid 89); 28 Mar 2013 09:26:30 -0000 X-Spam-SWARE-Status: No, score=-3.8 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL autolearn=ham version=3.3.1 Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Thu, 28 Mar 2013 09:26:27 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1UL96H-0001Iz-UZ from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Thu, 28 Mar 2013 02:26:25 -0700 Received: from SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 28 Mar 2013 02:26:26 -0700 Received: from qiyao.dyndns.org.dyndns.org (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.1.289.1; Thu, 28 Mar 2013 02:26:24 -0700 From: Yao Qi To: Subject: [PATCH] Add completer to commands 'target {core/tfile/exec}' Date: Thu, 28 Mar 2013 15:14:00 -0000 Message-ID: <1364462710-16702-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2013-03/txt/msg01055.txt.bz2 Hi, Recently I type command 'target tifle' and 'target ctf' frequently, and feel uneasy to type file name without a completer. This patch adds filename completer to commands target {core,tfile,exec}. Note that command "core-file" has already has a filename completer, but "target core" doesn't. Is it OK? gdb: 2013-03-28 Yao Qi * corelow.c: Include "completer.h". (_initialize_corelow): Call add_target_with_completer with parameter 'filename_completer'. * tracepoint.c: Likewise. * exec.c (_initialize_exec): Likewise. * target.c (add_target): Rename to ... (add_target_with_completer): ... it. New. Call set_cmd_completer if parameter completer is not NULL. (add_target): New. * target.h: Include "command.h". (add_target_with_completer): Declare it. gdb/testsuite: 2013-03-28 Yao Qi * gdb.base/completion.exp: Test completion of commands "target core", "target tfile" and "target exec". * gdb.trace/tfile.exp: Test completion of command "target tfile". --- gdb/corelow.c | 3 ++- gdb/exec.c | 2 +- gdb/target.c | 22 +++++++++++++++++++--- gdb/target.h | 4 ++++ gdb/testsuite/gdb.base/completion.exp | 7 +++++++ gdb/testsuite/gdb.trace/tfile.exp | 5 +++++ gdb/tracepoint.c | 3 ++- 7 files changed, 40 insertions(+), 6 deletions(-) diff --git a/gdb/corelow.c b/gdb/corelow.c index 77bab82..fa48941 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -46,6 +46,7 @@ #include "progspace.h" #include "objfiles.h" #include "gdb_bfd.h" +#include "completer.h" #ifndef O_LARGEFILE #define O_LARGEFILE 0 @@ -977,5 +978,5 @@ _initialize_corelow (void) { init_core_ops (); - add_target (&core_ops); + add_target_with_completer (&core_ops, filename_completer); } diff --git a/gdb/exec.c b/gdb/exec.c index f550194..3386b60 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -943,7 +943,7 @@ Show writing into executable and core files."), NULL, show_write_files, &setlist, &showlist); - add_target (&exec_ops); + add_target_with_completer (&exec_ops, filename_completer); } static char * diff --git a/gdb/target.c b/gdb/target.c index 9193c97..f0eefd4 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -384,11 +384,16 @@ target_has_execution_current (void) return target_has_execution_1 (inferior_ptid); } -/* Add a possible target architecture to the list. */ +/* Add a possible target architecture T to the list and add a new + command 'target T->to_shortname'. Set COMPLETER for the command + completer if it is not NULL. */ void -add_target (struct target_ops *t) +add_target_with_completer (struct target_ops *t, + completer_ftype *completer) { + struct cmd_list_element *c; + /* Provide default values for all "must have" methods. */ if (t->to_xfer_partial == NULL) t->to_xfer_partial = default_xfer_partial; @@ -431,7 +436,18 @@ Remaining arguments are interpreted by the target protocol. For more\n\ information on the arguments for a particular protocol, type\n\ `help target ' followed by the protocol name."), &targetlist, "target ", 0, &cmdlist); - add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, &targetlist); + c = add_cmd (t->to_shortname, no_class, t->to_open, t->to_doc, + &targetlist); + if (completer != NULL) + set_cmd_completer (c, completer); +} + +/* Add a possible target architecture to the list. */ + +void +add_target (struct target_ops *t) +{ + add_target_with_completer (t, NULL); } /* See target.h. */ diff --git a/gdb/target.h b/gdb/target.h index ee3fbff..4f8520c 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -63,6 +63,7 @@ struct expression; #include "vec.h" #include "gdb_signals.h" #include "btrace.h" +#include "command.h" enum strata { @@ -1841,6 +1842,9 @@ int target_verify_memory (const gdb_byte *data, extern void add_target (struct target_ops *); +extern void add_target_with_completer (struct target_ops *t, + completer_ftype *completer); + /* Adds a command ALIAS for target T and marks it deprecated. This is useful for maintaining backwards compatibility when renaming targets. */ diff --git a/gdb/testsuite/gdb.base/completion.exp b/gdb/testsuite/gdb.base/completion.exp index cddc548..df93733 100644 --- a/gdb/testsuite/gdb.base/completion.exp +++ b/gdb/testsuite/gdb.base/completion.exp @@ -713,6 +713,13 @@ gdb_test "complete set gnutarget aut" "set gnutarget auto" gdb_test "complete set cp-abi aut" "set cp-abi auto" +# Test commands 'target FOO' completion works well. + +foreach target_name { "core" "tfile" "exec" } { + gdb_test "complete target ${target_name} ./gdb.base/completion" \ + "target ${target_name} ./gdb.base/completion\\.exp.*" +} + # Restore globals modified in this test... set timeout $oldtimeout1 diff --git a/gdb/testsuite/gdb.trace/tfile.exp b/gdb/testsuite/gdb.trace/tfile.exp index e8a778d..3b720cc 100644 --- a/gdb/testsuite/gdb.trace/tfile.exp +++ b/gdb/testsuite/gdb.trace/tfile.exp @@ -128,3 +128,8 @@ gdb_test \ gdb_test "interpreter-exec mi \"-trace-status\"" \ "\\^done,supported=\"file\",trace-file=\".*basic.tf\",running=\"0\",stop-reason=\"request\",frames=\"${decimal}\",frames-created=\"${decimal}\",buffer-size=\"${decimal}\",buffer-free=\"${decimal}\",disconnected=\".*\",circular=\".*\",user-name=\"\",notes=\"\",start-time=\".*\",stop-time=\".*\"" \ "-trace-status" + +# Test completion works well. + +gdb_test "target tfile basic\t" "Assuming tracepoint.*" \ + "complete-command 'target tfile'" diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index d42138b..1044606 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -53,6 +53,7 @@ #include "cli/cli-utils.h" #include "probe.h" #include "ctf.h" +#include "completer.h" /* readline include files */ #include "readline/readline.h" @@ -5846,5 +5847,5 @@ Show the notes string to use for future tstop commands"), NULL, init_tfile_ops (); - add_target (&tfile_ops); + add_target_with_completer (&tfile_ops, filename_completer); } -- 1.7.7.6