From 60a20c190789fd75d1955576160cbbfe94c792fb Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 13 Dec 2017 16:38:49 +0000 Subject: Factor out final completion match string building We have several places doing essentially the same thing; factor them out to a central place. Some of the places overallocate for no good reason, or use strcat unnecessarily. The centralized version is more precise and to the point. (I considered making the gdb::unique_xmalloc_ptr overload version of make_completer_match_str try to realloc (not xrealloc) probably avoiding an allocation in most cases, but that'd be probably overdoing it, and also, now that I'm writing this I thought I'd try to see how could we ever get to filename_completer with "text != word", but I couldn't figure it out. Running the testsuite with 'gdb_assert (text == word);' never tripped on the assertion either. So post gdb 8.1, I'll probably propose a patch to simplify filename_completer a bit, and the gdb::unique_xmalloc_str overload can be removed then.) gdb/ChangeLog: 2017-12-13 Pedro Alves * cli/cli-decode.c (complete_on_cmdlist, complete_on_enum): Use make_completion_match_str. * completer.c: Use gdb::unique_xmalloc_ptr and make_completion_match_str. (make_completion_match_str_1): New. (make_completion_match_str(const char *, const char *, const char *)): New. (make_completion_match_str(gdb::unique_xmalloc_ptr &&, const char *, const char *)): New. * completer.h (make_completion_match_str(const char *, const char *, const char *)): New. (make_completion_match_str(gdb::unique_xmalloc_ptr &&, const char *, const char *)): New. * interps.c (interpreter_completer): Use make_completion_match_str. * symtab.c (completion_list_add_name, add_filename_to_list): Use make_completion_match_str. --- gdb/completer.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'gdb/completer.h') diff --git a/gdb/completer.h b/gdb/completer.h index 9ce70bf..73c0f4c 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -482,6 +482,21 @@ private: bool m_lowest_common_denominator_unique = false; }; +/* Return a string to hand off to readline as a completion match + candidate, potentially composed of parts of MATCH_NAME and of + TEXT/WORD. For a description of TEXT/WORD see completer_ftype. */ + +extern gdb::unique_xmalloc_ptr + make_completion_match_str (const char *match_name, + const char *text, const char *word); + +/* Like above, but takes ownership of MATCH_NAME (i.e., can + reuse/return it). */ + +extern gdb::unique_xmalloc_ptr + make_completion_match_str (gdb::unique_xmalloc_ptr &&match_name, + const char *text, const char *word); + extern void gdb_display_match_list (char **matches, int len, int max, const struct match_list_displayer *); -- cgit v1.1