diff options
author | Daniel Berlin <dberlin@dberlin.org> | 2000-03-23 23:21:27 +0000 |
---|---|---|
committer | Daniel Berlin <dberlin@dberlin.org> | 2000-03-23 23:21:27 +0000 |
commit | 6837a0a2a98f17adfd4b3723b6130d3ae4ae258e (patch) | |
tree | a963196cc70581c8324fbe357bc92bc868295e0f | |
parent | 0f4db1a1596363685d1d8b466479d75203a286b9 (diff) | |
download | gdb-6837a0a2a98f17adfd4b3723b6130d3ae4ae258e.zip gdb-6837a0a2a98f17adfd4b3723b6130d3ae4ae258e.tar.gz gdb-6837a0a2a98f17adfd4b3723b6130d3ae4ae258e.tar.bz2 |
Added the apropos command
-rw-r--r-- | gdb/ChangeLog | 7 | ||||
-rw-r--r-- | gdb/command.c | 88 | ||||
-rw-r--r-- | gdb/doc/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/doc/gdb.texinfo | 19 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/help.exp | 6 |
6 files changed, 127 insertions, 1 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 132e12b..8d5b70e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -40,6 +40,13 @@ (delete_file_handler, handle_file_event): Likewise. (gdb_wait_for_event, poll_timers): Likewise. +2000-03-22 Daniel Berlin <dan@cgsoftware.com> + * command.c (apropos_cmd_helper): New function, meat of the + apropos command. + (apropos_command): New apropos command to search command + names/documentation for regular expressions. + (_initialize_command): Add the apropos command. + 2000-03-22 Peter Schauer <pes@regent.e-technik.tu-muenchen.de> * printcmd.c (print_scalar_formatted): Truncate addresses to the diff --git a/gdb/command.c b/gdb/command.c index e0b7ad7..826cc46 100644 --- a/gdb/command.c +++ b/gdb/command.c @@ -27,7 +27,7 @@ #endif #include "gdb_wait.h" - +#include "gnu-regex.h" /* FIXME: this should be auto-configured! */ #ifdef __MSDOS__ # define CANT_FORK @@ -54,6 +54,10 @@ static struct cmd_list_element *find_cmd PARAMS ((char *command, struct cmd_list_element * clist, int ignore_help_classes, int *nfound)); +static void apropos_cmd_helper (struct ui_file *, struct cmd_list_element *, + struct re_pattern_buffer *, char *); + +void apropos_command (char *, int); void _initialize_command PARAMS ((void)); @@ -370,6 +374,87 @@ delete_cmd (name, list) c = c->next; } } +/* Recursively walk the commandlist structures, and print out the + documentation of commands that match our regex in either their + name, or their documentation. +*/ +static void +apropos_cmd_helper (struct ui_file *stream, struct cmd_list_element *commandlist, + struct re_pattern_buffer *regex, char *prefix) +{ + register struct cmd_list_element *c; + int returnvalue=1; /*Needed to avoid double printing*/ + /* Walk through the commands */ + for (c=commandlist;c;c=c->next) + { + if (c->name != NULL) + { + /* Try to match against the name*/ + returnvalue=re_search(regex,c->name,strlen(c->name),0,strlen(c->name),NULL); + if (returnvalue >= 0) + { + /* Stolen from help_cmd_list. We don't directly use + * help_cmd_list because it doesn't let us print out + * single commands + */ + fprintf_filtered (stream, "%s%s -- ", prefix, c->name); + print_doc_line (stream, c->doc); + fputs_filtered ("\n", stream); + returnvalue=0; /*Set this so we don't print it again.*/ + } + } + if (c->doc != NULL && returnvalue != 0) + { + /* Try to match against documentation */ + if (re_search(regex,c->doc,strlen(c->doc),0,strlen(c->doc),NULL) >=0) + { + /* Stolen from help_cmd_list. We don't directly use + * help_cmd_list because it doesn't let us print out + * single commands + */ + fprintf_filtered (stream, "%s%s -- ", prefix, c->name); + print_doc_line (stream, c->doc); + fputs_filtered ("\n", stream); + } + } + /* Check if this command has subcommands */ + if (c->prefixlist != NULL) + { + /* Recursively call ourselves on the subcommand list, + passing the right prefix in. + */ + apropos_cmd_helper(stream,*c->prefixlist,regex,c->prefixname); + } + } +} +/* Search through names of commands and documentations for a certain + regular expression. +*/ +void +apropos_command (char *searchstr, int from_tty) +{ + extern struct cmd_list_element *cmdlist; /*This is the main command list*/ + regex_t pattern; + char *pattern_fastmap; + char errorbuffer[512]; + pattern_fastmap=calloc(256,sizeof(char)); + if (searchstr == NULL) + error("REGEXP string is empty"); + + if (regcomp(&pattern,searchstr,REG_ICASE) == 0) + { + pattern.fastmap=pattern_fastmap; + re_compile_fastmap(&pattern); + apropos_cmd_helper(gdb_stdout,cmdlist,&pattern,""); + } + else + { + regerror(regcomp(&pattern,searchstr,REG_ICASE),NULL,errorbuffer,512); + error("Error in regular expression:%s",errorbuffer); + } + free(pattern_fastmap); +} + /* This command really has to deal with two things: * 1) I want documentation on *this string* (usually called by @@ -1693,4 +1778,5 @@ With no arguments, run an inferior shell."); "Show definitions of user defined commands.\n\ Argument is the name of the user defined command.\n\ With no argument, show definitions of all user defined commands.", &showlist); + add_com ("apropos", class_support, apropos_command, "Search for commands matching a REGEXP"); } diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index b0f2654..48efadf 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,7 @@ +2000-03-22 Daniel Berlin <dan@cgsoftware.com> + + * gdb.texinfo: Add documentation for the apropos command. + 2000-03-20 Michael Snyder <msnyder@cleaver.cygnus.com> * gdb.texinfo: Add white space to prevent overprinting in diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 15a0820..7ccfe03 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -1318,6 +1318,25 @@ Command name abbreviations are allowed if unambiguous. With a command name as @code{help} argument, @value{GDBN} displays a short paragraph on how to use that command. +@kindex apropos +@item apropos @var{args} +The @code{apropos @var{args}} command searches through all of the @value{GDBN} +commands, and their documentation, for the regular expression specified in +@var{args}. It prints out all matches found. For example: + +@smallexample +apropos reload +@end smallexample + +@noindent results in: + +@smallexample +@group +set symbol-reloading -- Set dynamic symbol table reloading multiple times in one run +show symbol-reloading -- Show dynamic symbol table reloading multiple times in one run +@end group +@end smallexample + @kindex complete @item complete @var{args} The @code{complete @var{args}} command lists all the possible completions diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 47bc29f..ded1f39 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2000-03-22 Daniel Berlin <dan@cgsoftware.com> + + * gdb.base/help.exp: Added test for new apropos command. + 2000-03-21 Kevin Buettner <kevinb@redhat.com> * gdb.base/pointers.c (usevar): New function. diff --git a/gdb/testsuite/gdb.base/help.exp b/gdb/testsuite/gdb.base/help.exp index c78bd89..9515132 100644 --- a/gdb/testsuite/gdb.base/help.exp +++ b/gdb/testsuite/gdb.base/help.exp @@ -540,3 +540,9 @@ gdb_test "help x" "Examine memory: x/FMT ADDRESS..*\[\r\n\]+ADDRESS is an expres gdb_test "help info bogus-gdb-command" "Undefined info command: \"bogus-gdb-command\". Try \"help info\"." "help info bogus-gdb-command" # test help gotcha gdb_test "help gotcha" "Undefined command: \"gotcha\". Try \"help\"." "help gotcha" +# test apropos regex +gdb_test "apropos \\\(print\[\^ bsiedf\\\".\]\\\)" "handle -- Specify how to handle a signal" +# test apropos >1 word string +gdb_test "apropos handle a signal" "handle -- Specify how to handle a signal" +# test apropos apropos +gdb_test "apropos apropos" "apropos -- Search for commands matching a REGEXP" |