* [RFA] New variable, 'max-completion-results'.
@ 2002-11-04 19:45 Klee Dienes
2002-11-05 14:07 ` Michael Snyder
2003-01-03 23:28 ` Elena Zannoni
0 siblings, 2 replies; 3+ messages in thread
From: Klee Dienes @ 2002-11-04 19:45 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 455 bytes --]
The following patch adds a new user-visible variable to GDB,
'max-completion-results'.
It is used by the completion functions in symtab.c to limit the maximum
number of results returned by the completion function, and defaults to
'unlimited'. I find it particuarly useful when using GDB under emacs,
to prevent situations where hitting <tab> at the wrong time can lead to
hundreds of thousands of results having to be sorted by
complete_command.
[-- Attachment #2: limit-completions.txt --]
[-- Type: text/plain, Size: 2975 bytes --]
Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.75
diff -u -r1.75 symtab.c
--- symtab.c 28 Oct 2002 17:05:56 -0000 1.75
+++ symtab.c 4 Nov 2002 07:24:59 -0000
@@ -50,6 +50,8 @@
#include <ctype.h>
#include "cp-abi.h"
+static unsigned int max_completion_results = UINT_MAX;
+
/* Prototypes for local functions */
static void completion_list_add_name (char *, char *, int, char *, char *);
@@ -3090,6 +3092,7 @@
/* Helper routine for make_symbol_completion_list. */
+static unsigned int return_val_max;
static int return_val_size;
static int return_val_index;
static char **return_val;
@@ -3120,10 +3123,11 @@
/* clip symbols that cannot match */
+ if (return_val_index == return_val_max)
+ return;
+
if (strncmp (symname, sym_text, sym_text_len) != 0)
- {
- return;
- }
+ return;
/* We have a match for a completion, so add SYMNAME to the current list
of matches. Note that the name is moved to freshly malloc'd space. */
@@ -3238,6 +3242,7 @@
sym_text_len = strlen (sym_text);
+ return_val_max = max_completion_results;
return_val_size = 100;
return_val_index = 0;
return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
@@ -3419,6 +3424,7 @@
sym_text_len = strlen (sym_text);
+ return_val_max = max_completion_results;
return_val_size = 10;
return_val_index = 0;
return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
@@ -3739,6 +3745,7 @@
/* Helper routine for make_symbol_completion_list. */
+static unsigned int sym_return_val_max;
static int sym_return_val_size;
static int sym_return_val_index;
static struct symbol **sym_return_val;
@@ -3754,6 +3761,9 @@
int i;
char *sym_name;
+ if (sym_return_val_index >= sym_return_val_max)
+ return;
+
/* If there is no type information, we can't do anything, so skip */
if (SYMBOL_TYPE (sym) == NULL)
return;
@@ -3822,6 +3832,7 @@
}
oload_name_len = strlen (oload_name);
+ sym_return_val_max = max_completion_results;
sym_return_val_size = 100;
sym_return_val_index = 0;
sym_return_val = (struct symbol **) xmalloc ((sym_return_val_size + 1) * sizeof (struct symbol *));
@@ -3965,6 +3976,8 @@
void
_initialize_symtab (void)
{
+ struct cmd_list_element *cmd;
+
add_info ("variables", variables_info,
"All global and static variable names, or those matching REGEXP.");
if (dbx_commands)
@@ -3998,6 +4011,13 @@
add_com ("rbreak", class_breakpoint, rbreak_command,
"Set a breakpoint for all functions matching REGEXP.");
+
+ cmd = add_set_cmd ("max-completion-results", class_obscure, var_uinteger,
+ (char *) &max_completion_results,
+ "Set the maximum number of entries to be returned from a completion o\
+peration.",
+ &setlist);
+ add_show_from_set (cmd, &showlist);
if (xdb_commands)
{
[-- Attachment #3: Type: text/plain, Size: 1 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [RFA] New variable, 'max-completion-results'.
2002-11-04 19:45 [RFA] New variable, 'max-completion-results' Klee Dienes
@ 2002-11-05 14:07 ` Michael Snyder
2003-01-03 23:28 ` Elena Zannoni
1 sibling, 0 replies; 3+ messages in thread
From: Michael Snyder @ 2002-11-05 14:07 UTC (permalink / raw)
To: Klee Dienes, gdb-patches
Klee Dienes wrote:
>
> The following patch adds a new user-visible variable to GDB,
> 'max-completion-results'.
>
> It is used by the completion functions in symtab.c to limit the maximum
> number of results returned by the completion function, and defaults to
> 'unlimited'. I find it particuarly useful when using GDB under emacs,
> to prevent situations where hitting <tab> at the wrong time can lead to
> hundreds of thousands of results having to be sorted by
> complete_command.
What a great idea!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFA] New variable, 'max-completion-results'.
2002-11-04 19:45 [RFA] New variable, 'max-completion-results' Klee Dienes
2002-11-05 14:07 ` Michael Snyder
@ 2003-01-03 23:28 ` Elena Zannoni
1 sibling, 0 replies; 3+ messages in thread
From: Elena Zannoni @ 2003-01-03 23:28 UTC (permalink / raw)
To: Klee Dienes; +Cc: gdb-patches
Klee Dienes writes:
> The following patch adds a new user-visible variable to GDB,
> 'max-completion-results'.
>
> It is used by the completion functions in symtab.c to limit the maximum
> number of results returned by the completion function, and defaults to
> 'unlimited'. I find it particuarly useful when using GDB under emacs,
> to prevent situations where hitting <tab> at the wrong time can lead to
> hundreds of thousands of results having to be sorted by
> complete_command.
>
Needs a testcase (added to completion.exp) and documentation. Also, is
there any check that the new value makes sense? I.e. what if one
enters a negative number? Maybe that's a limitation of the set/show
command, though.
I get:
(gdb) set max-completion-results -2
(gdb) show max-completion-results
The maximum number of entries to be returned from a completion operation is
4294967294.
> Index: symtab.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/symtab.c,v
> retrieving revision 1.75
> diff -u -r1.75 symtab.c
> --- symtab.c 28 Oct 2002 17:05:56 -0000 1.75
> +++ symtab.c 4 Nov 2002 07:24:59 -0000
> @@ -50,6 +50,8 @@
> #include <ctype.h>
> #include "cp-abi.h"
>
> +static unsigned int max_completion_results = UINT_MAX;
> +
> /* Prototypes for local functions */
>
> static void completion_list_add_name (char *, char *, int, char *, char *);
> @@ -3090,6 +3092,7 @@
>
> /* Helper routine for make_symbol_completion_list. */
>
> +static unsigned int return_val_max;
> static int return_val_size;
> static int return_val_index;
> static char **return_val;
> @@ -3120,10 +3123,11 @@
>
> /* clip symbols that cannot match */
>
> + if (return_val_index == return_val_max)
should be return_val_max - 1
(gdb) set max-completion-results 2
(gdb) p f <tab>
factorial features.h float
> + return;
> +
> if (strncmp (symname, sym_text, sym_text_len) != 0)
> - {
> - return;
> - }
> + return;
>
> /* We have a match for a completion, so add SYMNAME to the current list
> of matches. Note that the name is moved to freshly malloc'd space. */
> @@ -3238,6 +3242,7 @@
>
> sym_text_len = strlen (sym_text);
>
> + return_val_max = max_completion_results;
> return_val_size = 100;
> return_val_index = 0;
> return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
> @@ -3419,6 +3424,7 @@
>
> sym_text_len = strlen (sym_text);
>
> + return_val_max = max_completion_results;
> return_val_size = 10;
> return_val_index = 0;
> return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
> @@ -3739,6 +3745,7 @@
>
> /* Helper routine for make_symbol_completion_list. */
>
> +static unsigned int sym_return_val_max;
> static int sym_return_val_size;
> static int sym_return_val_index;
> static struct symbol **sym_return_val;
> @@ -3754,6 +3761,9 @@
> int i;
> char *sym_name;
>
> + if (sym_return_val_index >= sym_return_val_max)
> + return;
> +
I haven't tried this one, but should it be sym_return_val_max-1?
because the index starts form 0.
Elena
> /* If there is no type information, we can't do anything, so skip */
> if (SYMBOL_TYPE (sym) == NULL)
> return;
> @@ -3822,6 +3832,7 @@
> }
> oload_name_len = strlen (oload_name);
>
> + sym_return_val_max = max_completion_results;
> sym_return_val_size = 100;
> sym_return_val_index = 0;
> sym_return_val = (struct symbol **) xmalloc ((sym_return_val_size + 1) * sizeof (struct symbol *));
> @@ -3965,6 +3976,8 @@
> void
> _initialize_symtab (void)
> {
> + struct cmd_list_element *cmd;
> +
> add_info ("variables", variables_info,
> "All global and static variable names, or those matching REGEXP.");
> if (dbx_commands)
> @@ -3998,6 +4011,13 @@
>
> add_com ("rbreak", class_breakpoint, rbreak_command,
> "Set a breakpoint for all functions matching REGEXP.");
> +
> + cmd = add_set_cmd ("max-completion-results", class_obscure, var_uinteger,
> + (char *) &max_completion_results,
> + "Set the maximum number of entries to be returned from a completion o\
> +peration.",
> + &setlist);
> + add_show_from_set (cmd, &showlist);
>
> if (xdb_commands)
> {
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-01-03 23:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-04 19:45 [RFA] New variable, 'max-completion-results' Klee Dienes
2002-11-05 14:07 ` Michael Snyder
2003-01-03 23:28 ` Elena Zannoni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox