-Wwrite-strings: Some constification in gdb/breakpoint.c

The main motivation here is avoiding having to write a couple casts
like these:

     if (!arg)
  -    arg = "";
  +    arg = (char *) "";

in catch_exception_command_1 and catch_exec_command_1.

That requires making ep_parse_optional_if_clause and
check_for_argument take pointers to const strings.  I then tried
propagating the resulting constification all the way, but that was
spiraling out of control, so instead I settled for keeping const and
non-const overloads.

gdb/ChangeLog:
2017-04-05  Pedro Alves  <palves@redhat.com>

	* break-catch-throw.c (handle_gnu_v3_exceptions): Constify
	'cond_string' parameter.
	(extract_exception_regexp): Constify 'string' parameter.
	(catch_exception_command_1): Constify.
	* breakpoint.c (init_catchpoint)
	(create_fork_vfork_event_catchpoint): Constify 'cond_string'
	parameter.
	(ep_parse_optional_if_clause, catch_fork_command_1)
	(catch_exec_command_1): Constify.
	* breakpoint.h (init_catchpoint): Constify 'cond_string'
	parameter.
	(ep_parse_optional_if_clause): Constify.
	* cli/cli-utils.c (remove_trailing_whitespace)
	(check_for_argument): Constify.
	* cli/cli-utils.h (remove_trailing_whitespace): Constify and add
	non-const overload.
	(check_for_argument): Likewise.
This commit is contained in:
Pedro Alves
2017-04-05 19:21:36 +01:00
parent 9b2eba3dcc
commit 63160a4350
6 changed files with 72 additions and 29 deletions

View File

@@ -383,7 +383,8 @@ print_recreate_exception_catchpoint (struct breakpoint *b,
}
static void
handle_gnu_v3_exceptions (int tempflag, char *except_rx, char *cond_string,
handle_gnu_v3_exceptions (int tempflag, char *except_rx,
const char *cond_string,
enum exception_event_kind ex_event, int from_tty)
{
regex_t *pattern = NULL;
@@ -425,18 +426,18 @@ handle_gnu_v3_exceptions (int tempflag, char *except_rx, char *cond_string,
the end of the string. */
static char *
extract_exception_regexp (char **string)
extract_exception_regexp (const char **string)
{
char *start;
char *last, *last_space;
const char *start;
const char *last, *last_space;
start = skip_spaces (*string);
start = skip_spaces_const (*string);
last = start;
last_space = start;
while (*last != '\0')
{
char *if_token = last;
const char *if_token = last;
/* Check for the "if". */
if (check_for_argument (&if_token, "if", 2))
@@ -444,7 +445,7 @@ extract_exception_regexp (char **string)
/* No "if" token here. Skip to the next word start. */
last_space = skip_to_space (last);
last = skip_spaces (last_space);
last = skip_spaces_const (last_space);
}
*string = last;
@@ -457,16 +458,18 @@ extract_exception_regexp (char **string)
commands. */
static void
catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
catch_exception_command_1 (enum exception_event_kind ex_event,
char *arg_entry,
int tempflag, int from_tty)
{
char *except_rx;
char *cond_string = NULL;
const char *cond_string = NULL;
struct cleanup *cleanup;
const char *arg = arg_entry;
if (!arg)
arg = "";
arg = skip_spaces (arg);
arg = skip_spaces_const (arg);
except_rx = extract_exception_regexp (&arg);
cleanup = make_cleanup (xfree, except_rx);