aboutsummaryrefslogtreecommitdiff
path: root/gdb/cli
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2017-04-05 19:21:36 +0100
committerPedro Alves <palves@redhat.com>2017-04-05 19:21:36 +0100
commit63160a43508fb50d9013df061b2191de71f67b50 (patch)
tree8bb51f1a9eb796916af8ebaeb56e71e966ead758 /gdb/cli
parent9b2eba3dcc6b41f17180e1aee29ed133f942c733 (diff)
downloadgdb-63160a43508fb50d9013df061b2191de71f67b50.zip
gdb-63160a43508fb50d9013df061b2191de71f67b50.tar.gz
gdb-63160a43508fb50d9013df061b2191de71f67b50.tar.bz2
-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.
Diffstat (limited to 'gdb/cli')
-rw-r--r--gdb/cli/cli-utils.c6
-rw-r--r--gdb/cli/cli-utils.h22
2 files changed, 23 insertions, 5 deletions
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..9848a27 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -137,7 +137,16 @@ 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 +165,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 */