public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 16/18] -Wwrite-strings: Some constification in gdb/breakpoint.c
Date: Tue, 04 Apr 2017 17:26:00 -0000	[thread overview]
Message-ID: <1491326751-16180-17-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1491326751-16180-1-git-send-email-palves@redhat.com>

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
spriraling out of control, so instead I settled for keeping const and
non-const overloads.

gdb/ChangeLog:
yyyy-mm-dd  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.
---
 gdb/break-catch-throw.c | 23 +++++++++++++----------
 gdb/breakpoint.c        | 26 ++++++++++++++------------
 gdb/breakpoint.h        |  4 ++--
 gdb/cli/cli-utils.c     |  6 +++---
 gdb/cli/cli-utils.h     | 21 +++++++++++++++++++--
 5 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index f7c7cc8..2e18d2a 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -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);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index f0db3e4..4cd7a00 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8582,7 +8582,7 @@ catch_unload_command_1 (char *arg, int from_tty,
 void
 init_catchpoint (struct breakpoint *b,
 		 struct gdbarch *gdbarch, int tempflag,
-		 char *cond_string,
+		 const char *cond_string,
 		 const struct breakpoint_ops *ops)
 {
   struct symtab_and_line sal;
@@ -8613,7 +8613,7 @@ install_breakpoint (int internal, struct breakpoint *b, int update_gll)
 
 static void
 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch,
-				    int tempflag, char *cond_string,
+				    int tempflag, const char *cond_string,
                                     const struct breakpoint_ops *ops)
 {
   struct fork_catchpoint *c = new fork_catchpoint ();
@@ -11779,10 +11779,10 @@ until_break_command (char *arg, int from_tty, int anywhere)
    it updates arg to point to the first character following the parsed
    if clause in the arg string.  */
 
-char *
-ep_parse_optional_if_clause (char **arg)
+const char *
+ep_parse_optional_if_clause (const char **arg)
 {
-  char *cond_string;
+  const char *cond_string;
 
   if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
     return NULL;
@@ -11792,7 +11792,7 @@ ep_parse_optional_if_clause (char **arg)
 
   /* Skip any extra leading whitespace, and record the start of the
      condition string.  */
-  *arg = skip_spaces (*arg);
+  *arg = skip_spaces_const (*arg);
   cond_string = *arg;
 
   /* Assume that the condition occupies the remainder of the arg
@@ -11813,11 +11813,12 @@ typedef enum
 catch_fork_kind;
 
 static void
-catch_fork_command_1 (char *arg, int from_tty, 
+catch_fork_command_1 (char *arg_entry, int from_tty,
 		      struct cmd_list_element *command)
 {
+  const char *arg = arg_entry;
   struct gdbarch *gdbarch = get_current_arch ();
-  char *cond_string = NULL;
+  const char *cond_string = NULL;
   catch_fork_kind fork_kind;
   int tempflag;
 
@@ -11827,7 +11828,7 @@ catch_fork_command_1 (char *arg, int from_tty,
 
   if (!arg)
     arg = "";
-  arg = skip_spaces (arg);
+  arg = skip_spaces_const (arg);
 
   /* The allowed syntax is:
      catch [v]fork
@@ -11860,19 +11861,20 @@ catch_fork_command_1 (char *arg, int from_tty,
 }
 
 static void
-catch_exec_command_1 (char *arg, int from_tty, 
+catch_exec_command_1 (char *arg_entry, int from_tty,
 		      struct cmd_list_element *command)
 {
+  const char *arg = arg_entry;
   struct exec_catchpoint *c;
   struct gdbarch *gdbarch = get_current_arch ();
   int tempflag;
-  char *cond_string = NULL;
+  const char *cond_string = NULL;
 
   tempflag = get_cmd_context (command) == CATCH_TEMPORARY;
 
   if (!arg)
     arg = "";
-  arg = skip_spaces (arg);
+  arg = skip_spaces_const (arg);
 
   /* The allowed syntax is:
      catch exec
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 7d08057..6940270 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1295,7 +1295,7 @@ extern void
 
 extern void init_catchpoint (struct breakpoint *b,
 			     struct gdbarch *gdbarch, int tempflag,
-			     char *cond_string,
+			     const char *cond_string,
 			     const struct breakpoint_ops *ops);
 
 /* Add breakpoint B on the breakpoint list, and notify the user, the
@@ -1641,7 +1641,7 @@ extern struct gdbarch *get_sal_arch (struct symtab_and_line sal);
 
 extern void breakpoint_free_objfile (struct objfile *objfile);
 
-extern char *ep_parse_optional_if_clause (char **arg);
+extern const char *ep_parse_optional_if_clause (const char **arg);
 
 /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" to
    UIOUT iff debugging multiple threads.  */
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index b353c18..8eac7c4 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -238,8 +238,8 @@ number_is_in_list (const char *list, int number)
 
 /* See documentation in cli-utils.h.  */
 
-char *
-remove_trailing_whitespace (const char *start, char *s)
+const char *
+remove_trailing_whitespace (const char *start, const char *s)
 {
   while (s > start && isspace (*(s - 1)))
     --s;
@@ -288,7 +288,7 @@ extract_arg (char **arg)
 /* See documentation in cli-utils.h.  */
 
 int
-check_for_argument (char **str, char *arg, int arg_len)
+check_for_argument (const char **str, const char *arg, int arg_len)
 {
   if (strncmp (*str, arg, arg_len) == 0
       && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len])))
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index c80bae0..b1207b6 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -137,7 +137,15 @@ extern int number_is_in_list (const char *list, int number);
 /* Reverse S to the last non-whitespace character without skipping past
    START.  */
 
-extern char *remove_trailing_whitespace (const char *start, char *s);
+extern const char *remove_trailing_whitespace (const char *start,
+					       const char *s);
+
+/* Same, for non-const S.  */
+static inline char *
+remove_trailing_whitespace (const char *start, char *s)
+{
+  return (char *) remove_trailing_whitespace (start, (const char *) s);
+}
 
 /* A helper function to extract an argument from *ARG.  An argument is
    delimited by whitespace.  The return value is either NULL if no
@@ -156,6 +164,15 @@ extern char *extract_arg_const (const char **arg);
    string.  The argument must also either be at the end of the string,
    or be followed by whitespace.  Returns 1 if it finds the argument,
    0 otherwise.  If the argument is found, it updates *STR.  */
-extern int check_for_argument (char **str, char *arg, int arg_len);
+extern int check_for_argument (const char **str, const char *arg, int arg_len);
+
+/* Same, for non-const STR.  */
+
+static inline int
+check_for_argument (char **str, const char *arg, int arg_len)
+{
+  return check_for_argument (const_cast<const char **> (str),
+			     arg, arg_len);
+}
 
 #endif /* CLI_UTILS_H */
-- 
2.5.5

  parent reply	other threads:[~2017-04-04 17:26 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-04 17:25 [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Pedro Alves
2017-04-04 17:26 ` [PATCH 06/18] -Wwrite-strings: Constify target_pid_to_str and target_thread_extra_thread_info Pedro Alves
2017-04-04 18:44   ` John Baldwin
2017-04-04 17:26 ` [PATCH 03/18] -Wwrite-strings: Don't initialize string command variables to empty string Pedro Alves
2017-04-04 17:26 ` [PATCH 04/18] -Wwrite-strings: Constify shell_escape and plug make_command leak Pedro Alves
2017-04-04 17:26 ` [PATCH 07/18] -Wwrite-strings: Constify work break character arrays Pedro Alves
2017-04-05  8:46   ` Philipp Rudo
2017-04-05 13:17     ` Pedro Alves
2017-04-04 17:26 ` [PATCH 09/18] -Wwrite-strings: MI -info-os Pedro Alves
2017-04-04 17:26 ` Pedro Alves [this message]
2017-04-04 17:26 ` [PATCH 15/18] -Wwrite-strings: execute_command calls with string literals Pedro Alves
2017-04-05  7:13   ` Metzger, Markus T
2017-04-05 13:10     ` Pedro Alves
2017-04-04 17:26 ` [PATCH 01/18] -Wwrite-strings: Constify struct disassemble_info's disassembler_options field Pedro Alves
2017-04-05  7:22   ` Nick Clifton
2017-04-04 17:26 ` [PATCH 14/18] -Wwrite-strings: Add a PyArg_ParseTupleAndKeywords "const char *" overload Pedro Alves
2017-04-04 18:37   ` Sergio Durigan Junior
2017-04-05 12:58     ` Pedro Alves
2017-04-05 15:49       ` Sergio Durigan Junior
2017-04-04 17:26 ` [PATCH 08/18] -Wwrite-strings: Constify mi_cmd_argv_ftype's 'command' parameter Pedro Alves
2017-04-04 17:26 ` [PATCH 02/18] -Wwrite-strings: Constify macroexp.c:init_shared_buffer Pedro Alves
2017-04-04 17:26 ` [PATCH 05/18] -Wwrite-strings: Constify warning_pre_print Pedro Alves
2017-04-04 17:31 ` [PATCH 10/18] -Wwrite-strings: gdbserver's 'port' parsing Pedro Alves
2017-04-04 17:32 ` [PATCH 13/18] -Wwrite-strings: Wrap PyGetSetDef for construction with string literals Pedro Alves
2017-04-04 18:40   ` Sergio Durigan Junior
2017-04-05 12:35     ` Pedro Alves
2017-04-05 15:48       ` Sergio Durigan Junior
2017-04-05  8:49   ` Philipp Rudo
2017-04-05 13:03     ` Pedro Alves
2017-04-04 17:32 ` [PATCH 11/18] -Wwrite-strings: gdbserver/win32-low.c and TARGET_WAITKIND_EXECD Pedro Alves
2017-04-04 17:32 ` [PATCH 18/18] -Wwrite-strings: Remove -Wno-write-strings Pedro Alves
2019-02-14 16:17   ` Thomas Schwinge
2017-04-04 17:33 ` [PATCH 12/18] -Wwrite-strings: More fix-old-Python-API wrappers Pedro Alves
2017-04-04 17:36 ` [PATCH 17/18] -Wwrite-strings: The Rest Pedro Alves
2017-04-04 18:44   ` John Baldwin
2017-04-05 12:59     ` Pedro Alves
2017-04-04 18:42 ` [PATCH 00/18] gdb: Enable -Wwrite-strings (aka remove -Wno-write-strings) Sergio Durigan Junior
2017-04-04 19:37 ` Simon Marchi
2017-04-05 18:05 ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1491326751-16180-17-git-send-email-palves@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).