Introduce compiled_regex, eliminate make_regfree_cleanup

This patch replaces compile_rx_or_error and make_regfree_cleanup with
a class that wraps a regex_t.

gdb/ChangeLog:
2017-06-07  Pedro Alves  <palves@redhat.com>

	* Makefile.in (SFILES): Add gdb_regex.c.
	(COMMON_OBS): Add gdb_regex.o.
	* ada-lang.c (ada_add_standard_exceptions)
	(ada_add_exceptions_from_frame, name_matches_regex)
	(ada_add_global_exceptions, ada_exceptions_list_1): Change regex
	parameter type to compiled_regex.  Adjust.
	(ada_exceptions_list): Use compiled_regex.
	* break-catch-throw.c (exception_catchpoint::pattern): Now a
	std::unique_ptr<compiled_regex>.
	(exception_catchpoint::~exception_catchpoint): Remove regfree
	call.
	(check_status_exception_catchpoint): Adjust to use compiled_regex.
	(handle_gnu_v3_exceptions): Adjust to use compiled_regex.
	* breakpoint.c (solib_catchpoint::compiled): Now a
	std::unique_ptr<compiled_regex>.
	(solib_catchpoint::~solib_catchpoint): Remove regfree call.
	(check_status_catch_solib): Adjust to use compiled_regex.
	(add_solib_catchpoint): Adjust to use compiled_regex.
	* cli/cli-cmds.c (apropos_command): Use compiled_regex.
	* cli/cli-decode.c (apropos_cmd): Change regex parameter to
	compiled_regex reference.  Adjust to use it.
	* cli/cli-decode.h: Remove struct re_pattern_buffer forward
	declaration.  Include "gdb_regex.h".
	(apropos_cmd): Change regex parameter to compiled_regex reference.
	* gdb_regex.c: New file.
	* gdb_regex.h (make_regfree_cleanup, get_regcomp_error): Delete
	declarations.
	(class compiled_regex): New.
	* linux-tdep.c: Include "common/gdb_optional.h".
	(struct mapping_regexes): New, factored out from
	mapping_is_anonymous_p, and adjusted to use compiled_regex.
	(mapping_is_anonymous_p): Use mapping_regexes wrapped in a
	gdb::optional and remove cleanups.  Adjust to compiled_regex.
	* probe.c: Include "common/gdb_optional.h".
	(collect_probes): Use compiled_regex and gdb::optional and remove
	cleanups.
	* skip.c: Include "common/gdb_optional.h".
	(skiplist_entry::compiled_function_regexp): Now a
	gdb::optional<compiled_regex>.
	(skiplist_entry::compiled_function_regexp_is_valid): Delete field.
	(free_skiplist_entry): Remove regfree call.
	(compile_skip_regexp, skip_rfunction_p): Adjust to use
	compiled_regex and gdb::optional.
	* symtab.c: Include "common/gdb_optional.h".
	(search_symbols): Use compiled_regex and gdb::optional.
	* utils.c (do_regfree_cleanup, make_regfree_cleanup)
	(get_regcomp_error, compile_rx_or_error): Delete.  Some bits moved
	to gdb_regex.c.
This commit is contained in:
Pedro Alves
2017-06-07 14:21:40 +01:00
parent 62e20ed45e
commit 2d7cc5c797
15 changed files with 255 additions and 226 deletions

View File

@@ -13219,14 +13219,15 @@ sort_remove_dups_ada_exceptions_list (VEC(ada_exc_info) **exceptions,
gets pushed. */
static void
ada_add_standard_exceptions (regex_t *preg, VEC(ada_exc_info) **exceptions)
ada_add_standard_exceptions (compiled_regex *preg,
VEC(ada_exc_info) **exceptions)
{
int i;
for (i = 0; i < ARRAY_SIZE (standard_exc); i++)
{
if (preg == NULL
|| regexec (preg, standard_exc[i], 0, NULL, 0) == 0)
|| preg->exec (standard_exc[i], 0, NULL, 0) == 0)
{
struct bound_minimal_symbol msymbol
= ada_lookup_simple_minsym (standard_exc[i]);
@@ -13253,7 +13254,8 @@ ada_add_standard_exceptions (regex_t *preg, VEC(ada_exc_info) **exceptions)
gets pushed. */
static void
ada_add_exceptions_from_frame (regex_t *preg, struct frame_info *frame,
ada_add_exceptions_from_frame (compiled_regex *preg,
struct frame_info *frame,
VEC(ada_exc_info) **exceptions)
{
const struct block *block = get_frame_block (frame, 0);
@@ -13290,10 +13292,10 @@ ada_add_exceptions_from_frame (regex_t *preg, struct frame_info *frame,
/* Return true if NAME matches PREG or if PREG is NULL. */
static bool
name_matches_regex (const char *name, regex_t *preg)
name_matches_regex (const char *name, compiled_regex *preg)
{
return (preg == NULL
|| regexec (preg, ada_decode (name), 0, NULL, 0) == 0);
|| preg->exec (ada_decode (name), 0, NULL, 0) == 0);
}
/* Add all exceptions defined globally whose name name match
@@ -13316,7 +13318,8 @@ name_matches_regex (const char *name, regex_t *preg)
gets pushed. */
static void
ada_add_global_exceptions (regex_t *preg, VEC(ada_exc_info) **exceptions)
ada_add_global_exceptions (compiled_regex *preg,
VEC(ada_exc_info) **exceptions)
{
struct objfile *objfile;
struct compunit_symtab *s;
@@ -13364,7 +13367,7 @@ ada_add_global_exceptions (regex_t *preg, VEC(ada_exc_info) **exceptions)
do not match. Otherwise, all exceptions are listed. */
static VEC(ada_exc_info) *
ada_exceptions_list_1 (regex_t *preg)
ada_exceptions_list_1 (compiled_regex *preg)
{
VEC(ada_exc_info) *result = NULL;
struct cleanup *old_chain
@@ -13417,19 +13420,11 @@ ada_exceptions_list_1 (regex_t *preg)
VEC(ada_exc_info) *
ada_exceptions_list (const char *regexp)
{
VEC(ada_exc_info) *result = NULL;
struct cleanup *old_chain = NULL;
regex_t reg;
if (regexp == NULL)
return ada_exceptions_list_1 (NULL);
if (regexp != NULL)
old_chain = compile_rx_or_error (&reg, regexp,
_("invalid regular expression"));
result = ada_exceptions_list_1 (regexp != NULL ? &reg : NULL);
if (old_chain != NULL)
do_cleanups (old_chain);
return result;
compiled_regex reg (regexp, REG_NOSUB, _("invalid regular expression"));
return ada_exceptions_list_1 (&reg);
}
/* Implement the "info exceptions" command. */