Bug 9007 - excessive completions: ignores readline's completion-query-items
Summary: excessive completions: ignores readline's completion-query-items
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: cli (show other bugs)
Version: 6.3
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-30 18:58 UTC by eddy
Modified: 2015-03-28 22:07 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description eddy 2005-03-30 18:58:00 UTC
[Converted from Gnats 1902]

If I hit TAB to complete at an inopportune moment, gdb in gud-mode will recite (in the gdb window, not an other-window of prompts) *all* 72 thousand or so symbols it knows about, as possible completions, without warning or confirmation.

I typed function name, TAB gave me several param types, I typed some letters of the next, TAB completed it - though gud-mode wanted to offer me lots of other choices in other-window - but this still left the function ambiguous (I never did like C++ overloading) so I used TAB TAB, hoping to see what candidates I needed to chose amongst for the next parameter type.  Presumably the fact that I did so after a space is material to why it thought I wanted a list of all known symbols ...  Each line also has, as prefix, everything I've typed thus far, so looked like:

 break 'ClassName::Method(char*, unsigned int, Descriptor*

followed by a symbol, which did wonders for the total byte count.

It is of course totally useless to list this many symbols, even when they're relevant (there are quicker ways for me to obtain the right answer and no way am I going to read all that lot) and it takes ages simply to display them all, which C-g doesn't seem to be enough to interrupt.  Plus, of course, the gud-mode buffer grows by 9 Mb each time this happens, which is a wicked way to squander resources.  (Gah - and I just had to do it *again* to check my How-To-Repeat does actually work ...)

Even listing this many symbols in other-window (as single TAB does, I see) is worse than useless: again, it takes for ever and chews up resources, and I can only see the first few dozen anyway.

The readline section of gdb's info manual says that, since I have completion-query-items unset (I have no ~/.inputrc), I should be queried if completion would list over 100 items.  (Now that I've read it I'm going to go and set that to something a lot smaller - even 100 is more than I ever want to see - about a dozen should do !)

Hopefully, this will just be a matter of some missing glue between readline and gdb/gud-mode ...

Severity: annoyance
Scope: probably only affects those of us who aren't very sophisticated readline users; probably only rarely (I've hit this before, didn't bug-report it, learned the "don't do that, then" lesson, haven't done it for a year or two, forgot the lesson ...)
Impact: may cause users unfamiliar with readline to be scared of trying to use TAB completion, hence limiting uptake of some useful functionality.

Release:
6.3-debian

Environment:
Linux whorl 2.4.27-2-686-smp #1 SMP Thu Jan 20 11:02:39 JST 2005 i686 GNU/Linux
Running gdb within emacs 21.4.1 using M-x gdb.

How-To-Repeat:
If necessary, remove any setting of completion-query-items from your ~/.inputrc and type C-x C-r; this may be unnecessary, unless your setting is very very high; but, for all I know, an overt setting may be honoured, where the implicit default setting of 100 isn't.

Fire up emacs, M-x gdb, tell it some program you've compiled with -g, let gdb get started in its new buffer.  Type
  break 'write(int, void*
and hit TAB.  Be patient.
How patient depends on the size of the program, I suppose.
Eventually *Completions* will offer you unhelpfully many options to chose amongst.
If you're feeling masochistic, hit TAB again to see gdb print out all those options.

You may need to be in the middle of a long and difficult debugging run of the program for this to work, for all I know, but it seems unlikely.
Comment 1 Tom Tromey 2008-07-27 03:41:41 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: I think the problem here is that gud uses the gdb complete command,
    not readline completion.
    gdb does not respect rl_completion_query_items when completing this way.
    
    Offhand, I am not sure of the best way to fix this.
Comment 2 Sourceware Commits 2015-01-31 23:15:07 UTC
The master branch has been updated by Doug Evans <devans@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ef0b411a110cd2602cb89c3fb237baf8beb28545

commit ef0b411a110cd2602cb89c3fb237baf8beb28545
Author: Gary Benson <gbenson@redhat.com>
Date:   Sat Jan 31 15:07:22 2015 -0800

    Add max-completions parameter, and implement tab-completion limiting.
    
    This commit adds a new exception, MAX_COMPLETIONS_REACHED_ERROR, to be
    thrown whenever the completer has generated too many candidates to
    be useful.  A new user-settable variable, "max_completions", is added
    to control this behaviour.  A top-level completion limit is added to
    complete_line_internal, as the final check to ensure the user never
    sees too many completions.  An additional limit is added to
    default_make_symbol_completion_list_break_on, to halt time-consuming
    symbol table expansions.
    
    gdb/ChangeLog:
    
    	PR cli/9007
    	PR cli/11920
    	PR cli/15548
    	* cli/cli-cmds.c (complete_command): Notify user if max-completions
    	reached.
    	* common/common-exceptions.h (enum errors)
    	<MAX_COMPLETIONS_REACHED_ERROR>: New value.
    	* completer.h (get_max_completions_reached_message): New declaration.
    	(max_completions): Likewise.
    	(completion_tracker_t): New typedef.
    	(new_completion_tracker): New declaration.
    	(make_cleanup_free_completion_tracker): Likewise.
    	(maybe_add_completion_enum): New enum.
    	(maybe_add_completion): New declaration.
    	(throw_max_completions_reached_error): Likewise.
    	* completer.c (max_completions): New global variable.
    	(new_completion_tracker): New function.
    	(free_completion_tracker): Likewise.
    	(make_cleanup_free_completion_tracker): Likewise.
    	(maybe_add_completions): Likewise.
    	(throw_max_completions_reached_error): Likewise.
    	(complete_line): Remove duplicates and limit result to max_completions
    	entries.
    	(get_max_completions_reached_message): New function.
    	(gdb_display_match_list): Handle max_completions.
    	(_initialize_completer): New declaration and function.
    	* symtab.c: Include completer.h.
    	(completion_tracker): New static variable.
    	(completion_list_add_name): Call maybe_add_completion.
    	(default_make_symbol_completion_list_break_on_1): Renamed from
    	default_make_symbol_completion_list_break_on.  Maintain
    	completion_tracker across calls to completion_list_add_name.
    	(default_make_symbol_completion_list_break_on): New function.
    	* top.c (init_main): Set rl_completion_display_matches_hook.
    	* tui/tui-io.c: Include completer.h.
    	(tui_old_rl_display_matches_hook): New static global.
    	(tui_rl_display_match_list): Notify user if max-completions reached.
    	(tui_setup_io): Save/restore rl_completion_display_matches_hook.
    	* NEWS (New Options): Mention set/show max-completions.
    
    gdb/doc/ChangeLog:
    
    	* gdb.texinfo (Command Completion): Document new
    	"set/show max-completions" option.
    
    gdb/testsuite/ChangeLog:
    
    	* gdb.base/completion.exp: Disable completion limiting for
    	existing tests.  Add new tests to check completion limiting.
    	* gdb.linespec/ls-errs.exp: Disable completion limiting.
Comment 3 Sourceware Commits 2015-01-31 23:27:02 UTC
The master branch has been updated by Doug Evans <devans@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cfb069a8bebfacaf00dee6446e86a856978670be

commit cfb069a8bebfacaf00dee6446e86a856978670be
Author: Gary Benson <gbenson@redhat.com>
Date:   Sat Jan 31 15:24:26 2015 -0800

    ChangeLog entries for max-completions patch.
    
    gdb/ChangeLog:
    
    	PR cli/9007
    	PR cli/11920
    	PR cli/15548
    	* cli/cli-cmds.c (complete_command): Notify user if max-completions
    	reached.
    	* common/common-exceptions.h (enum errors)
    	<MAX_COMPLETIONS_REACHED_ERROR>: New value.
    	* completer.h (get_max_completions_reached_message): New declaration.
    	(max_completions): Likewise.
    	(completion_tracker_t): New typedef.
    	(new_completion_tracker): New declaration.
    	(make_cleanup_free_completion_tracker): Likewise.
    	(maybe_add_completion_enum): New enum.
    	(maybe_add_completion): New declaration.
    	(throw_max_completions_reached_error): Likewise.
    	* completer.c (max_completions): New global variable.
    	(new_completion_tracker): New function.
    	(free_completion_tracker): Likewise.
    	(make_cleanup_free_completion_tracker): Likewise.
    	(maybe_add_completions): Likewise.
    	(throw_max_completions_reached_error): Likewise.
    	(complete_line): Remove duplicates and limit result to max_completions
    	entries.
    	(get_max_completions_reached_message): New function.
    	(gdb_display_match_list): Handle max_completions.
    	(_initialize_completer): New declaration and function.
    	* symtab.c: Include completer.h.
    	(completion_tracker): New static variable.
    	(completion_list_add_name): Call maybe_add_completion.
    	(default_make_symbol_completion_list_break_on_1): Renamed from
    	default_make_symbol_completion_list_break_on.  Maintain
    	completion_tracker across calls to completion_list_add_name.
    	(default_make_symbol_completion_list_break_on): New function.
    	* top.c (init_main): Set rl_completion_display_matches_hook.
    	* tui/tui-io.c: Include completer.h.
    	(tui_old_rl_display_matches_hook): New static global.
    	(tui_rl_display_match_list): Notify user if max-completions reached.
    	(tui_setup_io): Save/restore rl_completion_display_matches_hook.
    	* NEWS (New Options): Mention set/show max-completions.
    
    gdb/doc/ChangeLog:
    
    	* gdb.texinfo (Command Completion): Document new
    	"set/show max-completions" option.
    
    gdb/testsuite/ChangeLog:
    
    	* gdb.base/completion.exp: Disable completion limiting for
    	existing tests.  Add new tests to check completion limiting.
    	* gdb.linespec/ls-errs.exp: Disable completion limiting.
Comment 4 Doug Evans 2015-03-28 22:07:51 UTC
Patch committed.