From patchwork Mon Apr 13 19:23:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 6193 Received: (qmail 119473 invoked by alias); 13 Apr 2015 19:23: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 119435 invoked by uid 89); 13 Apr 2015 19:23:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.2 required=5.0 tests=AWL, BAYES_50, KAM_STOCKGEN, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 13 Apr 2015 19:23:05 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t3DJN3KF015035 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 13 Apr 2015 15:23:03 -0400 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t3DJN3Kd017340 for ; Mon, 13 Apr 2015 15:23:03 -0400 Subject: [PATCH 01/18] Add struct completer_data to the completion API. From: Keith Seitz To: gdb-patches@sourceware.org Date: Mon, 13 Apr 2015 12:23:03 -0700 Message-ID: <20150413192303.29172.23031.stgit@valrhona.uglyboxes.com> In-Reply-To: <20150413192235.29172.13097.stgit@valrhona.uglyboxes.com> References: <20150413192235.29172.13097.stgit@valrhona.uglyboxes.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes This patch is largely mechanical. It modifies the completion API so that all completion functions take a new (pointer to a) structure, which will (eventually) be used internally by the completer to perform completion limiting. gdb/ChangeLog * completer.c (struct completer_data): Define. * language.h (struct language_defn) : Add struct completer_data to argument list. All users updated. * symtab.c (COMPLETION_LIST_ADD_SYMBOL): Add CDATA argument. Update all callers. (MCOMPLETION_LIST_ADD_SYMBOL): Likewise. (struct add_name_data) : New field. (default_make_symbol_completion_list_break_on_1): Initialize the above new field. (struct add_partial_filename_data) : New field. (make_source_files_completion_list): Initialize the above new field. --- gdb/ada-lang.c | 3 + gdb/break-catch-syscall.c | 5 +- gdb/breakpoint.c | 5 +- gdb/cli/cli-decode.c | 11 ++-- gdb/command.h | 11 +++- gdb/completer.c | 85 ++++++++++++++++++----------- gdb/completer.h | 22 +++++--- gdb/corefile.c | 5 +- gdb/cp-abi.c | 5 +- gdb/f-lang.c | 6 +- gdb/guile/scm-cmd.c | 3 + gdb/infrun.c | 7 +- gdb/interps.c | 3 + gdb/language.h | 8 ++- gdb/python/py-cmd.c | 12 ++-- gdb/remote-sim.c | 3 + gdb/symtab.c | 130 ++++++++++++++++++++++++++++----------------- gdb/symtab.h | 44 +++++++++------ 18 files changed, 229 insertions(+), 139 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 124e370..5ca4b5b 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -6190,7 +6190,8 @@ ada_complete_symbol_matcher (const char *name, void *user_data) the entire command on which completion is made. */ static VEC (char_ptr) * -ada_make_symbol_completion_list (const char *text0, const char *word, +ada_make_symbol_completion_list (struct completer_data *cdata, + const char *text0, const char *word, enum type_code code) { char *text; diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c index 1718f49..4677132 100644 --- a/gdb/break-catch-syscall.c +++ b/gdb/break-catch-syscall.c @@ -592,12 +592,13 @@ catching_syscall_number (int syscall_number) /* Complete syscall names. Used by "catch syscall". */ static VEC (char_ptr) * -catch_syscall_completer (struct cmd_list_element *cmd, +catch_syscall_completer (struct completer_data *cdata, + struct cmd_list_element *cmd, const char *text, const char *word) { const char **list = get_syscall_names (get_current_arch ()); VEC (char_ptr) *retlist - = (list == NULL) ? NULL : complete_on_enum (list, word, word); + = (list == NULL) ? NULL : complete_on_enum (cdata, list, word, word); xfree (list); return retlist; diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 31869f1..095fdf2 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -1033,7 +1033,8 @@ set_breakpoint_condition (struct breakpoint *b, const char *exp, /* Completion for the "condition" command. */ static VEC (char_ptr) * -condition_completer (struct cmd_list_element *cmd, +condition_completer (struct completer_data *cdata, + struct cmd_list_element *cmd, const char *text, const char *word) { const char *space; @@ -1072,7 +1073,7 @@ condition_completer (struct cmd_list_element *cmd, /* We're completing the expression part. */ text = skip_spaces_const (space); - return expression_completer (cmd, text, word); + return expression_completer (cdata, cmd, text, word); } /* condition N EXP -- set break condition of breakpoint N to EXP. */ diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 4d0d5a9..286fc61 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -648,7 +648,8 @@ add_setshow_optional_filename_cmd (const char *name, enum command_class theclass support a special "unlimited" value. */ static VEC (char_ptr) * -integer_unlimited_completer (struct cmd_list_element *ignore, +integer_unlimited_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { static const char * const keywords[] = @@ -657,7 +658,7 @@ integer_unlimited_completer (struct cmd_list_element *ignore, NULL, }; - return complete_on_enum (keywords, text, word); + return complete_on_enum (cdata, keywords, text, word); } /* Add element named NAME to both the set and show command LISTs (the @@ -1765,7 +1766,8 @@ lookup_cmd_composition (const char *text, "oobar"; if WORD is "baz/foo", return "baz/foobar". */ VEC (char_ptr) * -complete_on_cmdlist (struct cmd_list_element *list, +complete_on_cmdlist (struct completer_data *cdata, + struct cmd_list_element *list, const char *text, const char *word, int ignore_help_classes) { @@ -1835,7 +1837,8 @@ complete_on_cmdlist (struct cmd_list_element *list, "oobar"; if WORD is "baz/foo", return "baz/foobar". */ VEC (char_ptr) * -complete_on_enum (const char *const *enumlist, +complete_on_enum (struct completer_data *cdata, + const char *const *enumlist, const char *text, const char *word) { VEC (char_ptr) *matchlist = NULL; diff --git a/gdb/command.h b/gdb/command.h index bdf625b..b2aeb30 100644 --- a/gdb/command.h +++ b/gdb/command.h @@ -23,6 +23,8 @@ /* This file defines the public interface for any code wanting to create commands. */ +struct completer_data; + /* Command classes are top-level categories into which commands are broken down for "help" purposes. @@ -156,7 +158,8 @@ typedef void cmd_sfunc_ftype (char *args, int from_tty, extern void set_cmd_sfunc (struct cmd_list_element *cmd, cmd_sfunc_ftype *sfunc); -typedef VEC (char_ptr) *completer_ftype (struct cmd_list_element *, +typedef VEC (char_ptr) *completer_ftype (struct completer_data *, + struct cmd_list_element *, const char *, const char *); typedef void completer_ftype_void (struct cmd_list_element *, @@ -225,10 +228,12 @@ extern struct cmd_list_element *add_info (const char *, extern struct cmd_list_element *add_info_alias (const char *, const char *, int); -extern VEC (char_ptr) *complete_on_cmdlist (struct cmd_list_element *, +extern VEC (char_ptr) *complete_on_cmdlist (struct completer_data *, + struct cmd_list_element *, const char *, const char *, int); -extern VEC (char_ptr) *complete_on_enum (const char *const *enumlist, +extern VEC (char_ptr) *complete_on_enum (struct completer_data *, + const char *const *enumlist, const char *, const char *); /* Functions that implement commands about CLI commands. */ diff --git a/gdb/completer.c b/gdb/completer.c index c8c0e4c..f2b31e9 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -86,6 +86,15 @@ static char *gdb_completer_file_name_break_characters = " \t\n*|\"';:?><"; we can't include '"' because the gdb C parser treats such quoted sequences as strings. */ static char *gdb_completer_quote_characters = "'"; + +/* A structure holding completion-specific calldata. */ + +struct completer_data +{ + /* The completion tracker being used by the completer. */ + completion_tracker_t tracker; +}; + /* Accessor for some completer data that may interest other files. */ @@ -107,7 +116,8 @@ readline_line_completion_function (const char *text, int matches) /* This can be used for functions which don't want to complete on symbols but don't want to complete on anything else either. */ VEC (char_ptr) * -noop_completer (struct cmd_list_element *ignore, +noop_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *prefix) { return NULL; @@ -115,7 +125,8 @@ noop_completer (struct cmd_list_element *ignore, /* Complete on filenames. */ VEC (char_ptr) * -filename_completer (struct cmd_list_element *ignore, +filename_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { int subsequent_name; @@ -184,7 +195,8 @@ filename_completer (struct cmd_list_element *ignore, etc. */ VEC (char_ptr) * -location_completer (struct cmd_list_element *ignore, +location_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { int n_syms, n_files, ix; @@ -260,18 +272,18 @@ location_completer (struct cmd_list_element *ignore, symbols as well as on files. */ if (colon) { - list = make_file_symbol_completion_list (symbol_start, word, + list = make_file_symbol_completion_list (cdata, symbol_start, word, file_to_match); xfree (file_to_match); } else { - list = make_symbol_completion_list (symbol_start, word); + list = make_symbol_completion_list (cdata, symbol_start, word); /* If text includes characters which cannot appear in a file name, they cannot be asking for completion on files. */ if (strcspn (text, gdb_completer_file_name_break_characters) == text_len) - fn_list = make_source_files_completion_list (text, text); + fn_list = make_source_files_completion_list (cdata, text, text); } n_syms = VEC_length (char_ptr, list); @@ -326,7 +338,7 @@ location_completer (struct cmd_list_element *ignore, { /* No completions at all. As the final resort, try completing on the entire text as a symbol. */ - list = make_symbol_completion_list (orig_text, word); + list = make_symbol_completion_list (cdata, orig_text, word); } return list; @@ -336,7 +348,8 @@ location_completer (struct cmd_list_element *ignore, method names from TYPE, a struct or union type, to the array OUTPUT. */ static void -add_struct_fields (struct type *type, VEC (char_ptr) **output, +add_struct_fields (struct completer_data *cdata, + struct type *type, VEC (char_ptr) **output, char *fieldname, int namelen) { int i; @@ -347,7 +360,7 @@ add_struct_fields (struct type *type, VEC (char_ptr) **output, for (i = 0; i < TYPE_NFIELDS (type); ++i) { if (i < TYPE_N_BASECLASSES (type)) - add_struct_fields (TYPE_BASECLASS (type, i), + add_struct_fields (cdata, TYPE_BASECLASS (type, i), output, fieldname, namelen); else if (TYPE_FIELD_NAME (type, i)) { @@ -361,7 +374,7 @@ add_struct_fields (struct type *type, VEC (char_ptr) **output, else if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_UNION) { /* Recurse into anonymous unions. */ - add_struct_fields (TYPE_FIELD_TYPE (type, i), + add_struct_fields (cdata, TYPE_FIELD_TYPE (type, i), output, fieldname, namelen); } } @@ -389,7 +402,8 @@ add_struct_fields (struct type *type, VEC (char_ptr) **output, names, but some language parsers also have support for completing field names. */ VEC (char_ptr) * -expression_completer (struct cmd_list_element *ignore, +expression_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { struct type *type = NULL; @@ -427,7 +441,7 @@ expression_completer (struct cmd_list_element *ignore, int flen = strlen (fieldname); VEC (char_ptr) *result = NULL; - add_struct_fields (type, &result, fieldname, flen); + add_struct_fields (cdata, type, &result, fieldname, flen); xfree (fieldname); return result; } @@ -437,7 +451,8 @@ expression_completer (struct cmd_list_element *ignore, VEC (char_ptr) *result; struct cleanup *cleanup = make_cleanup (xfree, fieldname); - result = make_symbol_completion_type (fieldname, fieldname, code); + result + = make_symbol_completion_type (cdata, fieldname, fieldname, code); do_cleanups (cleanup); return result; } @@ -451,7 +466,7 @@ expression_completer (struct cmd_list_element *ignore, ; /* Not ideal but it is what we used to do before... */ - return location_completer (ignore, p, word); + return location_completer (cdata, ignore, p, word); } /* See definition in completer.h. */ @@ -529,8 +544,8 @@ complete_line_internal_reason; */ static VEC (char_ptr) * -complete_line_internal (const char *text, - const char *line_buffer, int point, +complete_line_internal (struct completer_data *cdata, + const char *text, const char *line_buffer, int point, complete_line_internal_reason reason) { VEC (char_ptr) *list = NULL; @@ -615,13 +630,13 @@ complete_line_internal (const char *text, if (result_list) { if (reason != handle_brkchars) - list = complete_on_cmdlist (*result_list->prefixlist, p, - word, ignore_help_classes); + list = complete_on_cmdlist (cdata, *result_list->prefixlist, + p, word, ignore_help_classes); } else { if (reason != handle_brkchars) - list = complete_on_cmdlist (cmdlist, p, word, + list = complete_on_cmdlist (cdata, cmdlist, p, word, ignore_help_classes); } /* Ensure that readline does the right thing with respect to @@ -648,8 +663,8 @@ complete_line_internal (const char *text, /* It is a prefix command; what comes after it is a subcommand (e.g. "info "). */ if (reason != handle_brkchars) - list = complete_on_cmdlist (*c->prefixlist, p, word, - ignore_help_classes); + list = complete_on_cmdlist (cdata, *c->prefixlist, p, + word, ignore_help_classes); /* Ensure that readline does the right thing with respect to inserting quotes. */ @@ -661,7 +676,7 @@ complete_line_internal (const char *text, else if (c->enums) { if (reason != handle_brkchars) - list = complete_on_enum (c->enums, p, word); + list = complete_on_enum (cdata, c->enums, p, word); rl_completer_word_break_characters = gdb_completer_command_word_break_characters; } @@ -701,7 +716,7 @@ complete_line_internal (const char *text, && c->completer_handle_brkchars != NULL) (*c->completer_handle_brkchars) (c, p, word); if (reason != handle_brkchars && c->completer != NULL) - list = (*c->completer) (c, p, word); + list = (*c->completer) (cdata, c, p, word); } } else @@ -723,7 +738,7 @@ complete_line_internal (const char *text, } if (reason != handle_brkchars) - list = complete_on_cmdlist (result_list, q, word, + list = complete_on_cmdlist (cdata, result_list, q, word, ignore_help_classes); /* Ensure that readline does the right thing @@ -747,7 +762,7 @@ complete_line_internal (const char *text, else if (c->enums) { if (reason != handle_brkchars) - list = complete_on_enum (c->enums, p, word); + list = complete_on_enum (cdata, c->enums, p, word); } else { @@ -777,7 +792,7 @@ complete_line_internal (const char *text, && c->completer_handle_brkchars != NULL) (*c->completer_handle_brkchars) (c, p, word); if (reason != handle_brkchars && c->completer != NULL) - list = (*c->completer) (c, p, word); + list = (*c->completer) (cdata, c, p, word); } } } @@ -804,7 +819,6 @@ new_completion_tracker (void) /* Cleanup routine to free a completion tracker and reset the pointer to NULL. */ - static void free_completion_tracker (void *p) { @@ -885,7 +899,7 @@ complete_line (const char *text, const char *line_buffer, int point) if (max_completions == 0) return NULL; - list = complete_line_internal (text, line_buffer, point, + list = complete_line_internal (NULL, text, line_buffer, point, handle_completions); if (max_completions < 0) return list; @@ -932,17 +946,19 @@ complete_line (const char *text, const char *line_buffer, int point) /* Complete on command names. Used by "help". */ VEC (char_ptr) * -command_completer (struct cmd_list_element *ignore, +command_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { - return complete_line_internal (word, text, + return complete_line_internal (cdata, word, text, strlen (text), handle_help); } /* Complete on signals. */ VEC (char_ptr) * -signal_completer (struct cmd_list_element *ignore, +signal_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { VEC (char_ptr) *return_val = NULL; @@ -972,7 +988,8 @@ signal_completer (struct cmd_list_element *ignore, /* Complete on a register or reggroup. */ VEC (char_ptr) * -reg_or_group_completer (struct cmd_list_element *ignore, +reg_or_group_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { VEC (char_ptr) *result = NULL; @@ -1016,8 +1033,8 @@ gdb_completion_word_break_characters (void) { VEC (char_ptr) *list; - list = complete_line_internal (rl_line_buffer, rl_line_buffer, rl_point, - handle_brkchars); + list = complete_line_internal (NULL, rl_line_buffer, rl_line_buffer, + rl_point, handle_brkchars); gdb_assert (list == NULL); return rl_completer_word_break_characters; } diff --git a/gdb/completer.h b/gdb/completer.h index 56e1a2b..f32c696 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -23,6 +23,7 @@ /* Types of functions in struct match_list_displayer. */ struct match_list_displayer; +struct completer_data; typedef void mld_crlf_ftype (const struct match_list_displayer *); typedef void mld_putch_ftype (const struct match_list_displayer *, int); @@ -75,25 +76,32 @@ extern VEC (char_ptr) *complete_line (const char *text, extern char *readline_line_completion_function (const char *text, int matches); -extern VEC (char_ptr) *noop_completer (struct cmd_list_element *, +extern VEC (char_ptr) *noop_completer (struct completer_data *, + struct cmd_list_element *, const char *, const char *); -extern VEC (char_ptr) *filename_completer (struct cmd_list_element *, +extern VEC (char_ptr) *filename_completer (struct completer_data *, + struct cmd_list_element *, const char *, const char *); -extern VEC (char_ptr) *expression_completer (struct cmd_list_element *, +extern VEC (char_ptr) *expression_completer (struct completer_data *, + struct cmd_list_element *, const char *, const char *); -extern VEC (char_ptr) *location_completer (struct cmd_list_element *, +extern VEC (char_ptr) *location_completer (struct completer_data *, + struct cmd_list_element *, const char *, const char *); -extern VEC (char_ptr) *command_completer (struct cmd_list_element *, +extern VEC (char_ptr) *command_completer (struct completer_data *, + struct cmd_list_element *, const char *, const char *); -extern VEC (char_ptr) *signal_completer (struct cmd_list_element *, +extern VEC (char_ptr) *signal_completer (struct completer_data *, + struct cmd_list_element *, const char *, const char *); -extern VEC (char_ptr) *reg_or_group_completer (struct cmd_list_element *, +extern VEC (char_ptr) *reg_or_group_completer (struct completer_data *, + struct cmd_list_element *, const char *, const char *); extern char *get_gdb_completer_quote_characters (void); diff --git a/gdb/corefile.c b/gdb/corefile.c index a042e6d..b5ec0e0 100644 --- a/gdb/corefile.c +++ b/gdb/corefile.c @@ -468,7 +468,8 @@ set_gnutarget_command (char *ignore, int from_tty, /* A completion function for "set gnutarget". */ static VEC (char_ptr) * -complete_set_gnutarget (struct cmd_list_element *cmd, +complete_set_gnutarget (struct completer_data *cdata, + struct cmd_list_element *cmd, const char *text, const char *word) { static const char **bfd_targets; @@ -486,7 +487,7 @@ complete_set_gnutarget (struct cmd_list_element *cmd, bfd_targets[last + 1] = NULL; } - return complete_on_enum (bfd_targets, text, word); + return complete_on_enum (cdata, bfd_targets, text, word); } /* Set the gnutarget. */ diff --git a/gdb/cp-abi.c b/gdb/cp-abi.c index b8af8f0..504bb20 100644 --- a/gdb/cp-abi.c +++ b/gdb/cp-abi.c @@ -359,7 +359,8 @@ set_cp_abi_cmd (char *args, int from_tty) /* A completion function for "set cp-abi". */ static VEC (char_ptr) * -cp_abi_completer (struct cmd_list_element *ignore, +cp_abi_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { static const char **cp_abi_names; @@ -374,7 +375,7 @@ cp_abi_completer (struct cmd_list_element *ignore, cp_abi_names[i] = NULL; } - return complete_on_enum (cp_abi_names, text, word); + return complete_on_enum (cdata, cp_abi_names, text, word); } /* Show the currently selected C++ ABI. */ diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 8b61028..6852b08 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -229,10 +229,12 @@ f_word_break_characters (void) class. */ static VEC (char_ptr) * -f_make_symbol_completion_list (const char *text, const char *word, +f_make_symbol_completion_list (struct completer_data *cdata, + const char *text, const char *word, enum type_code code) { - return default_make_symbol_completion_list_break_on (text, word, ":", code); + return default_make_symbol_completion_list_break_on (cdata, text, word, + ":", code); } const struct language_defn f_language_defn = diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c index a693df2..2c57d17 100644 --- a/gdb/guile/scm-cmd.c +++ b/gdb/guile/scm-cmd.c @@ -378,7 +378,8 @@ cmdscm_add_completion (SCM completion, VEC (char_ptr) **result) /* Called by gdb for command completion. */ static VEC (char_ptr) * -cmdscm_completer (struct cmd_list_element *command, +cmdscm_completer (struct completer_data *cdata, + struct cmd_list_element *command, const char *text, const char *word) { command_smob *c_smob/*obj*/ = (command_smob *) get_cmd_context (command); diff --git a/gdb/infrun.c b/gdb/infrun.c index 4164a00..23f193f 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -7072,7 +7072,8 @@ Are you sure you want to change it? "), /* Complete the "handle" command. */ static VEC (char_ptr) * -handle_completer (struct cmd_list_element *ignore, +handle_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { VEC (char_ptr) *vec_signals, *vec_keywords, *return_val; @@ -7090,8 +7091,8 @@ handle_completer (struct cmd_list_element *ignore, NULL, }; - vec_signals = signal_completer (ignore, text, word); - vec_keywords = complete_on_enum (keywords, word, word); + vec_signals = signal_completer (cdata, ignore, text, word); + vec_keywords = complete_on_enum (cdata, keywords, word, word); return_val = VEC_merge (char_ptr, vec_signals, vec_keywords); VEC_free (char_ptr, vec_signals); diff --git a/gdb/interps.c b/gdb/interps.c index 90b5b2d..ac1b512 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -437,7 +437,8 @@ interpreter_exec_cmd (char *args, int from_tty) /* List the possible interpreters which could complete the given text. */ static VEC (char_ptr) * -interpreter_completer (struct cmd_list_element *ignore, +interpreter_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { int textlen; diff --git a/gdb/language.h b/gdb/language.h index 436fd6e..17b670e 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -301,9 +301,11 @@ struct language_defn completion is being made. If CODE is TYPE_CODE_UNDEF, then all symbols should be examined; otherwise, only STRUCT_DOMAIN symbols whose type has a code of CODE should be matched. */ - VEC (char_ptr) *(*la_make_symbol_completion_list) (const char *text, - const char *word, - enum type_code code); + VEC (char_ptr) * + (*la_make_symbol_completion_list) (struct completer_data *, + const char *text, + const char *word, + enum type_code code); /* The per-architecture (OS/ABI) language information. */ void (*la_language_arch_info) (struct gdbarch *, diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c index b11fc32..21d842e 100644 --- a/gdb/python/py-cmd.c +++ b/gdb/python/py-cmd.c @@ -237,7 +237,8 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty) call. */ static PyObject * -cmdpy_completer_helper (struct cmd_list_element *command, +cmdpy_completer_helper (struct completer_data *cdata, + struct cmd_list_element *command, const char *text, const char *word) { cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command); @@ -293,7 +294,7 @@ cmdpy_completer_handle_brkchars (struct cmd_list_element *command, /* Calling our helper to obtain the PyObject of the Python function. */ - resultobj = cmdpy_completer_helper (command, text, word); + resultobj = cmdpy_completer_helper (NULL, command, text, word); /* Check if there was an error. */ if (resultobj == NULL) @@ -330,7 +331,8 @@ cmdpy_completer_handle_brkchars (struct cmd_list_element *command, /* Called by gdb for command completion. */ static VEC (char_ptr) * -cmdpy_completer (struct cmd_list_element *command, +cmdpy_completer (struct completer_data *cdata, + struct cmd_list_element *command, const char *text, const char *word) { PyObject *resultobj = NULL; @@ -341,7 +343,7 @@ cmdpy_completer (struct cmd_list_element *command, /* Calling our helper to obtain the PyObject of the Python function. */ - resultobj = cmdpy_completer_helper (command, text, word); + resultobj = cmdpy_completer_helper (cdata, command, text, word); /* If the result object of calling the Python function is NULL, it means that there was an error. In this case, just give up and @@ -362,7 +364,7 @@ cmdpy_completer (struct cmd_list_element *command, PyErr_Clear (); } else if (value >= 0 && value < (long) N_COMPLETERS) - result = completers[value].completer (command, text, word); + result = completers[value].completer (cdata, command, text, word); } else { diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index fd2fd58..2bcb19e 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -1217,7 +1217,8 @@ simulator_command (char *args, int from_tty) } static VEC (char_ptr) * -sim_command_completer (struct cmd_list_element *ignore, const char *text, +sim_command_completer (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { struct sim_inferior_data *sim_data; diff --git a/gdb/symtab.c b/gdb/symtab.c index 72df872..c0562e1 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -5007,13 +5007,15 @@ do_free_completion_list (void *list) static VEC (char_ptr) *return_val; -#define COMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \ - completion_list_add_name \ - (SYMBOL_NATURAL_NAME (symbol), (sym_text), (len), (text), (word)) +#define COMPLETION_LIST_ADD_SYMBOL(cdata, symbol, sym_text, len, \ + text, word) \ + completion_list_add_name \ + ((cdata), SYMBOL_NATURAL_NAME (symbol), (sym_text), (len), (text), (word)) -#define MCOMPLETION_LIST_ADD_SYMBOL(symbol, sym_text, len, text, word) \ - completion_list_add_name \ - (MSYMBOL_NATURAL_NAME (symbol), (sym_text), (len), (text), (word)) +#define MCOMPLETION_LIST_ADD_SYMBOL(cdata, symbol, sym_text, len, \ + text, word) \ + completion_list_add_name \ + (cdata, MSYMBOL_NATURAL_NAME (symbol), (sym_text), (len), (text), (word)) /* Tracker for how many unique completions have been generated. Used to terminate completion list generation early if the list has grown @@ -5029,7 +5031,8 @@ static completion_tracker_t completion_tracker; characters. If so, add it to the current completion list. */ static void -completion_list_add_name (const char *symname, +completion_list_add_name (struct completer_data *cdata, + const char *symname, const char *sym_text, int sym_text_len, const char *text, const char *word) { @@ -5088,7 +5091,8 @@ completion_list_add_name (const char *symname, again and feed all the selectors into the mill. */ static void -completion_list_objc_symbol (struct minimal_symbol *msymbol, +completion_list_objc_symbol (struct completer_data *cdata, + struct minimal_symbol *msymbol, const char *sym_text, int sym_text_len, const char *text, const char *word) { @@ -5106,7 +5110,8 @@ completion_list_objc_symbol (struct minimal_symbol *msymbol, if (sym_text[0] == '[') /* Complete on shortened method method. */ - completion_list_add_name (method + 1, sym_text, sym_text_len, text, word); + completion_list_add_name (cdata, method + 1, sym_text, sym_text_len, + text, word); while ((strlen (method) + 1) >= tmplen) { @@ -5127,9 +5132,11 @@ completion_list_objc_symbol (struct minimal_symbol *msymbol, memcpy (tmp, method, (category - method)); tmp[category - method] = ' '; memcpy (tmp + (category - method) + 1, selector, strlen (selector) + 1); - completion_list_add_name (tmp, sym_text, sym_text_len, text, word); + completion_list_add_name (cdata, tmp, sym_text, sym_text_len, + text, word); if (sym_text[0] == '[') - completion_list_add_name (tmp + 1, sym_text, sym_text_len, text, word); + completion_list_add_name (cdata, tmp + 1, sym_text, sym_text_len, + text, word); } if (selector != NULL) @@ -5140,7 +5147,8 @@ completion_list_objc_symbol (struct minimal_symbol *msymbol, if (tmp2 != NULL) *tmp2 = '\0'; - completion_list_add_name (tmp, sym_text, sym_text_len, text, word); + completion_list_add_name (cdata, tmp, sym_text, sym_text_len, + text, word); } } @@ -5191,7 +5199,8 @@ language_search_unquoted_string (const char *text, const char *p) } static void -completion_list_add_fields (struct symbol *sym, const char *sym_text, +completion_list_add_fields (struct completer_data *cdata, + struct symbol *sym, const char *sym_text, int sym_text_len, const char *text, const char *word) { @@ -5204,7 +5213,7 @@ completion_list_add_fields (struct symbol *sym, const char *sym_text, if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT) for (j = TYPE_N_BASECLASSES (t); j < TYPE_NFIELDS (t); j++) if (TYPE_FIELD_NAME (t, j)) - completion_list_add_name (TYPE_FIELD_NAME (t, j), + completion_list_add_name (cdata, TYPE_FIELD_NAME (t, j), sym_text, sym_text_len, text, word); } } @@ -5220,6 +5229,9 @@ struct add_name_data const char *text; const char *word; + /* Completion data used by the completer function. */ + struct completer_data *completer_data; + /* Extra argument required for add_symtab_completions. */ enum type_code code; }; @@ -5234,7 +5246,7 @@ add_macro_name (const char *name, const struct macro_definition *ignore, { struct add_name_data *datum = (struct add_name_data *) user_data; - completion_list_add_name (name, + completion_list_add_name (datum->completer_data, name, datum->sym_text, datum->sym_text_len, datum->text, datum->word); } @@ -5252,7 +5264,8 @@ symbol_completion_matcher (const char *name, void *user_data) /* Add matching symbols from SYMTAB to the current completion list. */ static void -add_symtab_completions (struct compunit_symtab *cust, +add_symtab_completions (struct completer_data *cdata, + struct compunit_symtab *cust, const char *sym_text, int sym_text_len, const char *text, const char *word, enum type_code code) @@ -5271,7 +5284,7 @@ add_symtab_completions (struct compunit_symtab *cust, if (code == TYPE_CODE_UNDEF || (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN && TYPE_CODE (SYMBOL_TYPE (sym)) == code)) - COMPLETION_LIST_ADD_SYMBOL (sym, + COMPLETION_LIST_ADD_SYMBOL (cdata, sym, sym_text, sym_text_len, text, word); } @@ -5287,14 +5300,15 @@ symtab_expansion_callback (struct compunit_symtab *symtab, { struct add_name_data *datum = (struct add_name_data *) user_data; - add_symtab_completions (symtab, + add_symtab_completions (datum->completer_data, symtab, datum->sym_text, datum->sym_text_len, datum->text, datum->word, datum->code); } static void -default_make_symbol_completion_list_break_on_1 (const char *text, +default_make_symbol_completion_list_break_on_1 (struct completer_data *cdata, + const char *text, const char *word, const char *break_on, enum type_code code) @@ -5394,6 +5408,7 @@ default_make_symbol_completion_list_break_on_1 (const char *text, datum.text = text; datum.word = word; datum.code = code; + datum.completer_data = cdata; /* At this point scan through the misc symbol vectors and add each symbol you find to the list. Eventually we want to ignore @@ -5405,17 +5420,17 @@ default_make_symbol_completion_list_break_on_1 (const char *text, ALL_MSYMBOLS (objfile, msymbol) { QUIT; - MCOMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, - word); + MCOMPLETION_LIST_ADD_SYMBOL (cdata, msymbol, sym_text, sym_text_len, + text, word); - completion_list_objc_symbol (msymbol, sym_text, sym_text_len, text, - word); + completion_list_objc_symbol (cdata, msymbol, sym_text, sym_text_len, + text, word); } } /* Add completions for all currently loaded symbol tables. */ ALL_COMPUNITS (objfile, cust) - add_symtab_completions (cust, sym_text, sym_text_len, text, word, + add_symtab_completions (cdata, cust, sym_text, sym_text_len, text, word, code); /* Look through the partial symtabs for all symbols which begin @@ -5443,15 +5458,15 @@ default_make_symbol_completion_list_break_on_1 (const char *text, { if (code == TYPE_CODE_UNDEF) { - COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, - word); - completion_list_add_fields (sym, sym_text, sym_text_len, text, - word); + COMPLETION_LIST_ADD_SYMBOL (cdata, sym, sym_text, + sym_text_len, text, word); + completion_list_add_fields (cdata, sym, sym_text, + sym_text_len, text, word); } else if (SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN && TYPE_CODE (SYMBOL_TYPE (sym)) == code) - COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, - word); + COMPLETION_LIST_ADD_SYMBOL (cdata, sym, sym_text, sym_text_len, + text, word); } /* Stop when we encounter an enclosing function. Do not stop for @@ -5468,11 +5483,16 @@ default_make_symbol_completion_list_break_on_1 (const char *text, { if (surrounding_static_block != NULL) ALL_BLOCK_SYMBOLS (surrounding_static_block, iter, sym) - completion_list_add_fields (sym, sym_text, sym_text_len, text, word); - + { + completion_list_add_fields (cdata, sym, sym_text, sym_text_len, + text, word); + } if (surrounding_global_block != NULL) ALL_BLOCK_SYMBOLS (surrounding_global_block, iter, sym) - completion_list_add_fields (sym, sym_text, sym_text_len, text, word); + { + completion_list_add_fields (cdata, sym, sym_text, sym_text_len, + text, word); + } } /* Skip macros if we are completing a struct tag -- arguable but @@ -5505,7 +5525,8 @@ default_make_symbol_completion_list_break_on_1 (const char *text, } VEC (char_ptr) * -default_make_symbol_completion_list_break_on (const char *text, +default_make_symbol_completion_list_break_on (struct completer_data *cdata, + const char *text, const char *word, const char *break_on, enum type_code code) @@ -5517,7 +5538,7 @@ default_make_symbol_completion_list_break_on (const char *text, TRY { - default_make_symbol_completion_list_break_on_1 (text, word, + default_make_symbol_completion_list_break_on_1 (cdata, text, word, break_on, code); } CATCH (except, RETURN_MASK_ERROR) @@ -5532,10 +5553,12 @@ default_make_symbol_completion_list_break_on (const char *text, } VEC (char_ptr) * -default_make_symbol_completion_list (const char *text, const char *word, +default_make_symbol_completion_list (struct completer_data *cdata, + const char *text, const char *word, enum type_code code) { - return default_make_symbol_completion_list_break_on (text, word, "", code); + return default_make_symbol_completion_list_break_on (cdata, text, word, "", + code); } /* Return a vector of all symbols (regardless of class) which begin by @@ -5543,9 +5566,10 @@ default_make_symbol_completion_list (const char *text, const char *word, is NULL. */ VEC (char_ptr) * -make_symbol_completion_list (const char *text, const char *word) +make_symbol_completion_list (struct completer_data *cdata, + const char *text, const char *word) { - return current_language->la_make_symbol_completion_list (text, word, + return current_language->la_make_symbol_completion_list (cdata, text, word, TYPE_CODE_UNDEF); } @@ -5553,30 +5577,33 @@ make_symbol_completion_list (const char *text, const char *word) symbols whose type code is CODE. */ VEC (char_ptr) * -make_symbol_completion_type (const char *text, const char *word, - enum type_code code) +make_symbol_completion_type (struct completer_data *cdata, const char *text, + const char *word, enum type_code code) { gdb_assert (code == TYPE_CODE_UNION || code == TYPE_CODE_STRUCT || code == TYPE_CODE_ENUM); - return current_language->la_make_symbol_completion_list (text, word, code); + return current_language->la_make_symbol_completion_list (cdata, text, word, + code); } /* Like make_symbol_completion_list, but suitable for use as a completion function. */ VEC (char_ptr) * -make_symbol_completion_list_fn (struct cmd_list_element *ignore, +make_symbol_completion_list_fn (struct completer_data *cdata, + struct cmd_list_element *ignore, const char *text, const char *word) { - return make_symbol_completion_list (text, word); + return make_symbol_completion_list (cdata, text, word); } /* Like make_symbol_completion_list, but returns a list of symbols defined in a source file FILE. */ VEC (char_ptr) * -make_file_symbol_completion_list (const char *text, const char *word, +make_file_symbol_completion_list (struct completer_data *cdata, + const char *text, const char *word, const char *srcfile) { struct symbol *sym; @@ -5658,13 +5685,15 @@ make_file_symbol_completion_list (const char *text, const char *word, b = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (s), GLOBAL_BLOCK); ALL_BLOCK_SYMBOLS (b, iter, sym) { - COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); + COMPLETION_LIST_ADD_SYMBOL (cdata, sym, sym_text, sym_text_len, + text, word); } b = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (s), STATIC_BLOCK); ALL_BLOCK_SYMBOLS (b, iter, sym) { - COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word); + COMPLETION_LIST_ADD_SYMBOL (cdata, sym, sym_text, sym_text_len, + text, word); } return (return_val); @@ -5730,6 +5759,9 @@ struct add_partial_filename_data const char *word; int text_len; VEC (char_ptr) **list; + + /* Completion data used by the completer function. */ + struct completer_data *completer_data; }; /* A callback for map_partial_symbol_filenames. */ @@ -5766,7 +5798,8 @@ maybe_add_partial_symtab_filename (const char *filename, const char *fullname, NULL. */ VEC (char_ptr) * -make_source_files_completion_list (const char *text, const char *word) +make_source_files_completion_list (struct completer_data *cdata, + const char *text, const char *word) { struct compunit_symtab *cu; struct symtab *s; @@ -5817,6 +5850,7 @@ make_source_files_completion_list (const char *text, const char *word) datum.word = word; datum.text_len = text_len; datum.list = &list; + datum.completer_data = cdata; map_symbol_filenames (maybe_add_partial_symtab_filename, &datum, 0 /*need_fullname*/); diff --git a/gdb/symtab.h b/gdb/symtab.h index 6a0b8da..508a7e5 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -38,6 +38,7 @@ struct program_space; struct language_defn; struct probe; struct common_block; +struct completer_data; /* Some of the structures in this file are space critical. The space-critical structures are: @@ -1445,24 +1446,31 @@ extern void forget_cached_source_info (void); extern void select_source_symtab (struct symtab *); extern VEC (char_ptr) *default_make_symbol_completion_list_break_on - (const char *text, const char *word, const char *break_on, - enum type_code code); -extern VEC (char_ptr) *default_make_symbol_completion_list (const char *, - const char *, - enum type_code); -extern VEC (char_ptr) *make_symbol_completion_list (const char *, const char *); -extern VEC (char_ptr) *make_symbol_completion_type (const char *, const char *, - enum type_code); -extern VEC (char_ptr) *make_symbol_completion_list_fn (struct cmd_list_element *, - const char *, - const char *); - -extern VEC (char_ptr) *make_file_symbol_completion_list (const char *, - const char *, - const char *); - -extern VEC (char_ptr) *make_source_files_completion_list (const char *, - const char *); + (struct completer_data *cdata, const char *text, const char *word, + const char *break_on, enum type_code code); +extern VEC (char_ptr) * + default_make_symbol_completion_list (struct completer_data *, + const char *, const char *, + enum type_code); +extern VEC (char_ptr) * + make_symbol_completion_list (struct completer_data *, const char *, + const char *); +extern VEC (char_ptr) * + make_symbol_completion_type (struct completer_data *, + const char *, const char *, + enum type_code); +extern VEC (char_ptr) * + make_symbol_completion_list_fn (struct completer_data *, + struct cmd_list_element *, + const char *, const char *); + +extern VEC (char_ptr) * + make_file_symbol_completion_list (struct completer_data *, + const char *, const char *, const char *); + +extern VEC (char_ptr) * + make_source_files_completion_list (struct completer_data *, const char *, + const char *); /* symtab.c */