diff options
author | Tom Tromey <tromey@redhat.com> | 2011-01-17 16:50:42 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2011-01-17 16:50:42 +0000 |
commit | dc92e16124ca764e536f2457635749e5431c4765 (patch) | |
tree | 4435d0e6b715c61188acf0aea2a92112a44515f2 /gdb | |
parent | da17376b704177fc4d8fa038169782e28b1f3b24 (diff) | |
download | gdb-dc92e16124ca764e536f2457635749e5431c4765.zip gdb-dc92e16124ca764e536f2457635749e5431c4765.tar.gz gdb-dc92e16124ca764e536f2457635749e5431c4765.tar.bz2 |
* cli/cli-cmds.c (apropos_command): Free the compiled regex. Use
get_regcomp_error.
* utils.c: Include gdb_regex.h.
(do_regfree_cleanup): New function.
(make_regfree_cleanup): Likewise.
(get_regcomp_error): Likewise.
* gdb_regex.h (make_regfree_cleanup, get_regcomp_error): Declare.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 10 | ||||
-rw-r--r-- | gdb/cli/cli-cmds.c | 20 | ||||
-rw-r--r-- | gdb/gdb_regex.h | 4 | ||||
-rw-r--r-- | gdb/utils.c | 32 |
4 files changed, 60 insertions, 6 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5a814c4..136bb1d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,15 @@ 2011-01-17 Tom Tromey <tromey@redhat.com> + * cli/cli-cmds.c (apropos_command): Free the compiled regex. Use + get_regcomp_error. + * utils.c: Include gdb_regex.h. + (do_regfree_cleanup): New function. + (make_regfree_cleanup): Likewise. + (get_regcomp_error): Likewise. + * gdb_regex.h (make_regfree_cleanup, get_regcomp_error): Declare. + +2011-01-17 Tom Tromey <tromey@redhat.com> + * cli/cli-cmds.c (apropos_command): Fix formatting. Don't call re_compile_fastmap. diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index e1d8174..c11b257 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -1254,18 +1254,26 @@ void apropos_command (char *searchstr, int from_tty) { regex_t pattern; - char errorbuffer[512]; + int code; if (searchstr == NULL) error (_("REGEXP string is empty")); - if (regcomp (&pattern, searchstr, REG_ICASE) == 0) - apropos_cmd (gdb_stdout, cmdlist, &pattern, ""); + code = regcomp (&pattern, searchstr, REG_ICASE); + if (code == 0) + { + struct cleanup *cleanups; + + cleanups = make_regfree_cleanup (&pattern); + apropos_cmd (gdb_stdout, cmdlist, &pattern, ""); + do_cleanups (cleanups); + } else { - regerror (regcomp (&pattern, searchstr, REG_ICASE), NULL, - errorbuffer, 512); - error (_("Error in regular expression: %s"), errorbuffer); + char *err = get_regcomp_error (code, &pattern); + + make_cleanup (xfree, err); + error (_("Error in regular expression: %s"), err); } } diff --git a/gdb/gdb_regex.h b/gdb/gdb_regex.h index ccdf9c3..835cb09 100644 --- a/gdb/gdb_regex.h +++ b/gdb/gdb_regex.h @@ -28,4 +28,8 @@ # include <regex.h> #endif +/* From utils.c. */ +struct cleanup *make_regfree_cleanup (regex_t *); +char *get_regcomp_error (int, regex_t *); + #endif /* not GDB_REGEX_H */ diff --git a/gdb/utils.c b/gdb/utils.c index c23c4d4..82e3adb 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -73,6 +73,7 @@ #include "gdb_usleep.h" #include "interps.h" +#include "gdb_regex.h" #if !HAVE_DECL_MALLOC extern PTR malloc (); /* ARI: PTR */ @@ -1643,6 +1644,37 @@ gdb_print_host_address (const void *addr, struct ui_file *stream) } +/* A cleanup function that calls regfree. */ + +static void +do_regfree_cleanup (void *r) +{ + regfree (r); +} + +/* Create a new cleanup that frees the compiled regular expression R. */ + +struct cleanup * +make_regfree_cleanup (regex_t *r) +{ + return make_cleanup (do_regfree_cleanup, r); +} + +/* Return an xmalloc'd error message resulting from a regular + expression compilation failure. */ + +char * +get_regcomp_error (int code, regex_t *rx) +{ + size_t length = regerror (code, rx, NULL, 0); + char *result = xmalloc (length); + + regerror (code, rx, result, length); + return result; +} + + + /* This function supports the query, nquery, and yquery functions. Ask user a y-or-n question and return 0 if answer is no, 1 if answer is yes, or default the answer to the specified default |