* [RFA 1/3] Rename _const functions to use overloading instead
2017-09-11 0:33 [RFA 0/3] preparation for command constification; cleanup removal Tom Tromey
2017-09-11 0:33 ` [RFA 2/3] Constify language_enum Tom Tromey
@ 2017-09-11 0:33 ` Tom Tromey
2017-09-11 19:16 ` Simon Marchi
2017-09-11 0:33 ` [RFA 3/3] Make extract_arg return a std::string Tom Tromey
2 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2017-09-11 0:33 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This renames a few functions -- skip_spaces_const,
skip_to_space_const, get_number_const, extract_arg_const -- to drop
the "_const" suffix and instead rely on overloading.
This makes future const fixes simpler by reducing the number of lines
that must be changed. I think it is also not any less clear, as all
these functions have the same interface as their non-const versions by
design. Furthermore there's an example of using an overload in-tree
already, namely check_for_argument.
This patch was largely created using some perl one-liners; then a few
fixes were applied by hand.
ChangeLog
2017-09-10 Tom Tromey <tom@tromey.com>
* common/common-utils.h (skip_to_space): Remove macro, redeclare
as function.
(skip_to_space): Rename from skip_to_space_const.
* common/common-utils.c (skip_to_space): New function.
(skip_to_space): Rename from skip_to_space_const.
* cli/cli-utils.h (get_number): Rename from get_number_const.
(extract_arg): Rename from extract_arg_const.
* cli/cli-utils.c (get_number): Rename from get_number_const.
(extract_arg): Rename from extract_arg_const.
(number_or_range_parser::get_number): Use ::get_number.
* aarch64-linux-tdep.c, ada-lang.c, arm-linux-tdep.c, ax-gdb.c,
break-catch-throw.c, breakpoint.c, cli/cli-cmds.c, cli/cli-dump.c,
cli/cli-script.c, cli/cli-setshow.c, compile/compile.c,
completer.c, demangle.c, disasm.c, findcmd.c, linespec.c,
linux-tdep.c, linux-thread-db.c, location.c, mi/mi-parse.c,
minsyms.c, nat/linux-procfs.c, printcmd.c, probe.c,
python/py-breakpoint.c, record.c, rust-exp.y, serial.c, stack.c,
stap-probe.c, tid-parse.c, tracepoint.c: Update all callers.
---
gdb/ChangeLog | 21 +++++++++++++++++++++
gdb/aarch64-linux-tdep.c | 2 +-
gdb/ada-lang.c | 12 ++++++------
gdb/arm-linux-tdep.c | 2 +-
gdb/ax-gdb.c | 6 +++---
gdb/break-catch-throw.c | 6 +++---
gdb/breakpoint.c | 36 ++++++++++++++++++------------------
gdb/cli/cli-cmds.c | 4 ++--
gdb/cli/cli-dump.c | 8 ++++----
gdb/cli/cli-script.c | 4 ++--
gdb/cli/cli-setshow.c | 2 +-
gdb/cli/cli-utils.c | 16 ++++++++--------
gdb/cli/cli-utils.h | 6 +++---
gdb/common/common-utils.c | 12 ++++++++++--
gdb/common/common-utils.h | 6 +++---
gdb/compile/compile.c | 2 +-
gdb/completer.c | 6 +++---
gdb/demangle.c | 8 ++++----
gdb/disasm.c | 2 +-
gdb/findcmd.c | 8 ++++----
gdb/linespec.c | 12 ++++++------
gdb/linux-tdep.c | 12 ++++++------
gdb/linux-thread-db.c | 2 +-
gdb/location.c | 6 +++---
gdb/mi/mi-parse.c | 12 ++++++------
gdb/minsyms.c | 2 +-
gdb/nat/linux-procfs.c | 2 +-
gdb/printcmd.c | 6 +++---
gdb/probe.c | 6 +++---
gdb/python/py-breakpoint.c | 2 +-
gdb/record.c | 2 +-
gdb/rust-exp.y | 2 +-
gdb/serial.c | 2 +-
gdb/stack.c | 2 +-
gdb/stap-probe.c | 16 ++++++++--------
gdb/tid-parse.c | 2 +-
gdb/tracepoint.c | 20 ++++++++++----------
37 files changed, 153 insertions(+), 124 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1781ddd..a906d50 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,24 @@
+2017-09-10 Tom Tromey <tom@tromey.com>
+
+ * common/common-utils.h (skip_to_space): Remove macro, redeclare
+ as function.
+ (skip_to_space): Rename from skip_to_space_const.
+ * common/common-utils.c (skip_to_space): New function.
+ (skip_to_space): Rename from skip_to_space_const.
+ * cli/cli-utils.h (get_number): Rename from get_number_const.
+ (extract_arg): Rename from extract_arg_const.
+ * cli/cli-utils.c (get_number): Rename from get_number_const.
+ (extract_arg): Rename from extract_arg_const.
+ (number_or_range_parser::get_number): Use ::get_number.
+ * aarch64-linux-tdep.c, ada-lang.c, arm-linux-tdep.c, ax-gdb.c,
+ break-catch-throw.c, breakpoint.c, cli/cli-cmds.c, cli/cli-dump.c,
+ cli/cli-script.c, cli/cli-setshow.c, compile/compile.c,
+ completer.c, demangle.c, disasm.c, findcmd.c, linespec.c,
+ linux-tdep.c, linux-thread-db.c, location.c, mi/mi-parse.c,
+ minsyms.c, nat/linux-procfs.c, printcmd.c, probe.c,
+ python/py-breakpoint.c, record.c, rust-exp.y, serial.c, stack.c,
+ stap-probe.c, tid-parse.c, tracepoint.c: Update all callers.
+
2017-09-10 Andrew Burgess <andrew.burgess@embecosm.com>
* utils.c (abort_with_message): Don't compare gdb_stderr to NULL,
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index 4381359..b6052ba 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -305,7 +305,7 @@ aarch64_stap_parse_special_token (struct gdbarch *gdbarch,
regname, p->saved_arg);
++tmp;
- tmp = skip_spaces_const (tmp);
+ tmp = skip_spaces (tmp);
/* Now we expect a number. It can begin with '#' or simply
a digit. */
if (*tmp == '#')
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index fdc2a90..bfd67bc 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -12732,13 +12732,13 @@ ada_get_next_arg (const char **argsp)
const char *end;
char *result;
- args = skip_spaces_const (args);
+ args = skip_spaces (args);
if (args[0] == '\0')
return NULL; /* No more arguments. */
/* Find the end of the current argument. */
- end = skip_to_space_const (args);
+ end = skip_to_space (args);
/* Adjust ARGSP to point to the start of the next argument. */
@@ -12785,12 +12785,12 @@ catch_ada_exception_command_split (const char *args,
/* Check to see if we have a condition. */
- args = skip_spaces_const (args);
+ args = skip_spaces (args);
if (startswith (args, "if")
&& (isspace (args[2]) || args[2] == '\0'))
{
args += 2;
- args = skip_spaces_const (args);
+ args = skip_spaces (args);
if (args[0] == '\0')
error (_("Condition missing after `if' keyword"));
@@ -13044,14 +13044,14 @@ catch_ada_exception_command (char *arg_entry, int from_tty,
static void
catch_ada_assert_command_split (const char *args, char **cond_string)
{
- args = skip_spaces_const (args);
+ args = skip_spaces (args);
/* Check whether a condition was provided. */
if (startswith (args, "if")
&& (isspace (args[2]) || args[2] == '\0'))
{
args += 2;
- args = skip_spaces_const (args);
+ args = skip_spaces (args);
if (args[0] == '\0')
error (_("condition missing after `if' keyword"));
*cond_string = xstrdup (args);
diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c
index f3ca8f7..72b91d4 100644
--- a/gdb/arm-linux-tdep.c
+++ b/gdb/arm-linux-tdep.c
@@ -1211,7 +1211,7 @@ arm_stap_parse_special_token (struct gdbarch *gdbarch,
regname, p->saved_arg);
++tmp;
- tmp = skip_spaces_const (tmp);
+ tmp = skip_spaces (tmp);
if (*tmp == '#' || *tmp == '$')
++tmp;
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index c888e8c..227590b 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -2702,7 +2702,7 @@ maint_agent_printf_command (char *exp, int from_tty)
cmdrest = exp;
- cmdrest = skip_spaces_const (cmdrest);
+ cmdrest = skip_spaces (cmdrest);
if (*cmdrest++ != '"')
error (_("Must start with a format string."));
@@ -2718,14 +2718,14 @@ maint_agent_printf_command (char *exp, int from_tty)
if (*cmdrest++ != '"')
error (_("Bad format string, non-terminated '\"'."));
- cmdrest = skip_spaces_const (cmdrest);
+ cmdrest = skip_spaces (cmdrest);
if (*cmdrest != ',' && *cmdrest != 0)
error (_("Invalid argument syntax"));
if (*cmdrest == ',')
cmdrest++;
- cmdrest = skip_spaces_const (cmdrest);
+ cmdrest = skip_spaces (cmdrest);
nargs = 0;
while (*cmdrest != '\0')
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index c8612db..faa878e 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -402,7 +402,7 @@ extract_exception_regexp (const char **string)
const char *start;
const char *last, *last_space;
- start = skip_spaces_const (*string);
+ start = skip_spaces (*string);
last = start;
last_space = start;
@@ -416,7 +416,7 @@ extract_exception_regexp (const char **string)
/* No "if" token here. Skip to the next word start. */
last_space = skip_to_space (last);
- last = skip_spaces_const (last_space);
+ last = skip_spaces (last_space);
}
*string = last;
@@ -438,7 +438,7 @@ catch_exception_command_1 (enum exception_event_kind ex_event,
if (!arg)
arg = "";
- arg = skip_spaces_const (arg);
+ arg = skip_spaces (arg);
std::string except_rx = extract_exception_regexp (&arg);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 123420c..b642bc6 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1048,8 +1048,8 @@ condition_completer (struct cmd_list_element *cmd,
{
const char *space;
- text = skip_spaces_const (text);
- space = skip_to_space_const (text);
+ text = skip_spaces (text);
+ space = skip_to_space (text);
if (*space == '\0')
{
int len;
@@ -1084,7 +1084,7 @@ condition_completer (struct cmd_list_element *cmd,
}
/* We're completing the expression part. */
- text = skip_spaces_const (space);
+ text = skip_spaces (space);
expression_completer (cmd, tracker, text, word);
}
@@ -2431,7 +2431,7 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
if (*cmdrest == ',')
++cmdrest;
- cmdrest = skip_spaces_const (cmdrest);
+ cmdrest = skip_spaces (cmdrest);
if (*cmdrest++ != '"')
error (_("No format string following the location"));
@@ -2447,14 +2447,14 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
if (*cmdrest++ != '"')
error (_("Bad format string, non-terminated '\"'."));
- cmdrest = skip_spaces_const (cmdrest);
+ cmdrest = skip_spaces (cmdrest);
if (!(*cmdrest == ',' || *cmdrest == '\0'))
error (_("Invalid argument syntax"));
if (*cmdrest == ',')
cmdrest++;
- cmdrest = skip_spaces_const (cmdrest);
+ cmdrest = skip_spaces (cmdrest);
/* For each argument, make an expression. */
@@ -8460,7 +8460,7 @@ add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled)
if (!arg)
arg = "";
- arg = skip_spaces_const (arg);
+ arg = skip_spaces (arg);
std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ());
@@ -9204,9 +9204,9 @@ init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch,
const char *endp;
char *marker_str;
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
- endp = skip_to_space_const (p);
+ endp = skip_to_space (p);
marker_str = savestring (p, endp - p);
t->static_trace_marker_id = marker_str;
@@ -9504,7 +9504,7 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
const char *cond_start = NULL;
const char *cond_end = NULL;
- tok = skip_spaces_const (tok);
+ tok = skip_spaces (tok);
if ((*tok == '"' || *tok == ',') && rest)
{
@@ -9512,7 +9512,7 @@ find_condition_and_thread (const char *tok, CORE_ADDR pc,
return;
}
- end_tok = skip_to_space_const (tok);
+ end_tok = skip_to_space (tok);
toklen = end_tok - tok;
@@ -9569,9 +9569,9 @@ decode_static_tracepoint_spec (const char **arg_p)
char *marker_str;
int i;
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
- endp = skip_to_space_const (p);
+ endp = skip_to_space (p);
marker_str = savestring (p, endp - p);
old_chain = make_cleanup (xfree, marker_str);
@@ -11064,8 +11064,8 @@ watch_command_1 (const char *arg, int accessflag, int from_tty,
else if (val != NULL)
release_value (val);
- tok = skip_spaces_const (arg);
- end_tok = skip_to_space_const (tok);
+ tok = skip_spaces (arg);
+ end_tok = skip_to_space (tok);
toklen = end_tok - tok;
if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
@@ -11583,7 +11583,7 @@ ep_parse_optional_if_clause (const char **arg)
/* Skip any extra leading whitespace, and record the start of the
condition string. */
- *arg = skip_spaces_const (*arg);
+ *arg = skip_spaces (*arg);
cond_string = *arg;
/* Assume that the condition occupies the remainder of the arg
@@ -11619,7 +11619,7 @@ catch_fork_command_1 (char *arg_entry, int from_tty,
if (!arg)
arg = "";
- arg = skip_spaces_const (arg);
+ arg = skip_spaces (arg);
/* The allowed syntax is:
catch [v]fork
@@ -11664,7 +11664,7 @@ catch_exec_command_1 (char *arg_entry, int from_tty,
if (!arg)
arg = "";
- arg = skip_spaces_const (arg);
+ arg = skip_spaces (arg);
/* The allowed syntax is:
catch exec
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index a2041fa..883844e 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1240,7 +1240,7 @@ disassemble_command (char *arg, int from_tty)
}
}
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
}
if ((flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE))
@@ -1277,7 +1277,7 @@ disassemble_command (char *arg, int from_tty)
/* Two arguments. */
int incl_flag = 0;
low = pc;
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
if (p[0] == '+')
{
++p;
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 8e59ed4..8d57119 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -45,7 +45,7 @@ scan_expression (const char **cmd, const char *def)
end = (*cmd) + strcspn (*cmd, " \t");
exp = savestring ((*cmd), end - (*cmd));
- (*cmd) = skip_spaces_const (end);
+ (*cmd) = skip_spaces (end);
return gdb::unique_xmalloc_ptr<char> (exp);
}
}
@@ -71,10 +71,10 @@ scan_filename (const char **cmd, const char *defname)
/* FIXME: should parse a possibly quoted string. */
const char *end;
- (*cmd) = skip_spaces_const (*cmd);
+ (*cmd) = skip_spaces (*cmd);
end = *cmd + strcspn (*cmd, " \t");
filename.reset (savestring ((*cmd), end - (*cmd)));
- (*cmd) = skip_spaces_const (end);
+ (*cmd) = skip_spaces (end);
}
gdb_assert (filename != NULL);
@@ -538,7 +538,7 @@ restore_command (char *args_in, int from_tty)
{
binary_flag = 1;
args += strlen (binary_string);
- args = skip_spaces_const (args);
+ args = skip_spaces (args);
}
/* Parse offset (optional). */
if (args != NULL && *args != '\0')
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 9b2ffd0..02f66cc 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -888,7 +888,7 @@ line_first_arg (const char *p)
{
const char *first_arg = p + find_command_name_length (p);
- return skip_spaces_const (first_arg);
+ return skip_spaces (first_arg);
}
/* Process one input line. If the command is an "end", return such an
@@ -932,7 +932,7 @@ process_next_line (char *p, struct command_line **command, int parse_commands,
const char *cmd_name = p;
struct cmd_list_element *cmd
= lookup_cmd_1 (&cmd_name, cmdlist, NULL, 1);
- cmd_name = skip_spaces_const (cmd_name);
+ cmd_name = skip_spaces (cmd_name);
bool inline_cmd = *cmd_name != '\0';
/* If commands are parsed, we skip initial spaces. Otherwise,
diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c
index c6e5ebc..f89d268 100644
--- a/gdb/cli/cli-setshow.c
+++ b/gdb/cli/cli-setshow.c
@@ -134,7 +134,7 @@ is_unlimited_literal (const char *arg)
{
size_t len = sizeof ("unlimited") - 1;
- arg = skip_spaces_const (arg);
+ arg = skip_spaces (arg);
return (strncmp (arg, "unlimited", len) == 0
&& (isspace (arg[len]) || arg[len] == '\0'));
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index 8eac7c4..a00bc52 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -93,7 +93,7 @@ get_number_trailer (const char **pp, int trailer)
++p;
retval = 0;
}
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
*pp = p;
return retval;
}
@@ -101,7 +101,7 @@ get_number_trailer (const char **pp, int trailer)
/* See documentation in cli-utils.h. */
int
-get_number_const (const char **pp)
+get_number (const char **pp)
{
return get_number_trailer (pp, '\0');
}
@@ -172,8 +172,8 @@ number_or_range_parser::get_number ()
and also remember the end of the final token. */
temp = &m_end_ptr;
- m_end_ptr = skip_spaces_const (m_cur_tok + 1);
- m_end_value = get_number_const (temp);
+ m_end_ptr = skip_spaces (m_cur_tok + 1);
+ m_end_value = ::get_number (temp);
if (m_end_value < m_last_retval)
{
error (_("inverted range"));
@@ -250,7 +250,7 @@ remove_trailing_whitespace (const char *start, const char *s)
/* See documentation in cli-utils.h. */
char *
-extract_arg_const (const char **arg)
+extract_arg (const char **arg)
{
const char *result;
@@ -258,13 +258,13 @@ extract_arg_const (const char **arg)
return NULL;
/* Find the start of the argument. */
- *arg = skip_spaces_const (*arg);
+ *arg = skip_spaces (*arg);
if (!**arg)
return NULL;
result = *arg;
/* Find the end of the argument. */
- *arg = skip_to_space_const (*arg + 1);
+ *arg = skip_to_space (*arg + 1);
if (result == *arg)
return NULL;
@@ -280,7 +280,7 @@ extract_arg (char **arg)
const char *arg_const = *arg;
char *result;
- result = extract_arg_const (&arg_const);
+ result = extract_arg (&arg_const);
*arg += arg_const - *arg;
return result;
}
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index 9848a27..038ddad 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -33,9 +33,9 @@ extern int get_number_trailer (const char **pp, int trailer);
/* Convenience. Like get_number_trailer, but with no TRAILER. */
-extern int get_number_const (const char **);
+extern int get_number (const char **);
-/* Like get_number_const, but takes a non-const "char **". */
+/* Like get_number, but takes a non-const "char **". */
extern int get_number (char **);
@@ -159,7 +159,7 @@ extern char *extract_arg (char **arg);
Since the returned value is xmalloc'd, it eventually needs to be
xfree'ed, which prevents us from making it const as well. */
-extern char *extract_arg_const (const char **arg);
+extern char *extract_arg (const char **arg);
/* A helper function that looks for an argument at the start of a
string. The argument must also either be at the end of the string,
diff --git a/gdb/common/common-utils.c b/gdb/common/common-utils.c
index e75a1b9..6b10d11 100644
--- a/gdb/common/common-utils.c
+++ b/gdb/common/common-utils.c
@@ -298,7 +298,7 @@ skip_spaces (char *chp)
/* A const-correct version of the above. */
const char *
-skip_spaces_const (const char *chp)
+skip_spaces (const char *chp)
{
if (chp == NULL)
return NULL;
@@ -310,7 +310,7 @@ skip_spaces_const (const char *chp)
/* See documentation in common-utils.h. */
const char *
-skip_to_space_const (const char *chp)
+skip_to_space (const char *chp)
{
if (chp == NULL)
return NULL;
@@ -319,6 +319,14 @@ skip_to_space_const (const char *chp)
return chp;
}
+/* See documentation in common-utils.h. */
+
+char *
+skip_to_space (char *chp)
+{
+ return (char *) skip_to_space ((const char *) chp);
+}
+
/* See common/common-utils.h. */
void
diff --git a/gdb/common/common-utils.h b/gdb/common/common-utils.h
index 787bac9..6475c28 100644
--- a/gdb/common/common-utils.h
+++ b/gdb/common/common-utils.h
@@ -93,16 +93,16 @@ extern char *skip_spaces (char *inp);
/* A const-correct version of the above. */
-extern const char *skip_spaces_const (const char *inp);
+extern const char *skip_spaces (const char *inp);
/* Skip leading non-whitespace characters in INP, returning an updated
pointer. If INP is NULL, return NULL. */
-#define skip_to_space(INP) ((char *) skip_to_space_const (INP))
+extern char *skip_to_space (char *inp);
/* A const-correct version of the above. */
-extern const char *skip_to_space_const (const char *inp);
+extern const char *skip_to_space (const char *inp);
/* Assumes that V is an argv for a program, and iterates through
freeing all the elements. */
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index fc23d12..4a2f339 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -367,7 +367,7 @@ get_selected_pc_producer_options (void)
cs = symtab->producer;
while (*cs != 0 && *cs != '-')
- cs = skip_spaces_const (skip_to_space_const (cs));
+ cs = skip_spaces (skip_to_space (cs));
if (*cs != '-')
return NULL;
return cs;
diff --git a/gdb/completer.c b/gdb/completer.c
index 5d81f24..3022333 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -699,7 +699,7 @@ collect_explicit_location_matches (completion_tracker &tracker,
keyword. */
if (keyword != word)
{
- keyword = skip_spaces_const (keyword);
+ keyword = skip_spaces (keyword);
tracker.advance_custom_word_point_by (keyword - word);
complete_on_enum (tracker, linespec_keywords, keyword, keyword);
@@ -729,7 +729,7 @@ skip_keyword (completion_tracker &tracker,
const char * const *keywords, const char **text_p)
{
const char *text = *text_p;
- const char *after = skip_to_space_const (text);
+ const char *after = skip_to_space (text);
size_t len = after - text;
if (text[len] != ' ')
@@ -1903,7 +1903,7 @@ expand_preserving_ws (const char *orig, size_t orig_len,
{
while (p_orig < orig_end && *p_orig == ' ')
res += *p_orig++;
- p_lcd = skip_spaces_const (p_lcd);
+ p_lcd = skip_spaces (p_lcd);
}
else
{
diff --git a/gdb/demangle.c b/gdb/demangle.c
index d034f4e..892ad18 100644
--- a/gdb/demangle.c
+++ b/gdb/demangle.c
@@ -174,20 +174,20 @@ demangle_command (char *args, int from_tty)
while (processing_args
&& *arg_start == '-')
{
- const char *p = skip_to_space_const (arg_start);
+ const char *p = skip_to_space (arg_start);
if (strncmp (arg_start, "-l", p - arg_start) == 0)
- lang_name.reset (extract_arg_const (&p));
+ lang_name.reset (extract_arg (&p));
else if (strncmp (arg_start, "--", p - arg_start) == 0)
processing_args = 0;
else
{
- gdb::unique_xmalloc_ptr<char> option (extract_arg_const (&p));
+ gdb::unique_xmalloc_ptr<char> option (extract_arg (&p));
error (_("Unrecognized option '%s' to demangle command. "
"Try \"help demangle\"."), option.get ());
}
- arg_start = skip_spaces_const (p);
+ arg_start = skip_spaces (p);
}
name = arg_start;
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 5f22e78..cdab181 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -1044,7 +1044,7 @@ disassembler_options_completer (struct cmd_list_element *ignore,
const char *separator = strrchr (text, ',');
if (separator != NULL)
text = separator + 1;
- text = skip_spaces_const (text);
+ text = skip_spaces (text);
complete_on_enum (tracker, opts->name, text, word);
}
}
diff --git a/gdb/findcmd.c b/gdb/findcmd.c
index e35c224..f905e70 100644
--- a/gdb/findcmd.c
+++ b/gdb/findcmd.c
@@ -110,7 +110,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
}
}
- s = skip_spaces_const (s);
+ s = skip_spaces (s);
}
/* Get the search range. */
@@ -120,7 +120,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
if (*s == ',')
++s;
- s = skip_spaces_const (s);
+ s = skip_spaces (s);
if (*s == '+')
{
@@ -171,7 +171,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
struct type *t;
ULONGEST pattern_buf_size_need;
- s = skip_spaces_const (s);
+ s = skip_spaces (s);
v = parse_to_comma_and_eval (&s);
t = value_type (v);
@@ -220,7 +220,7 @@ parse_find_args (char *args, ULONGEST *max_countp,
if (*s == ',')
++s;
- s = skip_spaces_const (s);
+ s = skip_spaces (s);
}
if (pattern_buf_end == pattern_buf)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index abe6615..b69ab62 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -474,7 +474,7 @@ linespec_lexer_lex_keyword (const char *p)
if (i != IF_KEYWORD_INDEX)
{
p += len;
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
for (j = 0; linespec_keywords[j] != NULL; ++j)
{
int nextlen = strlen (linespec_keywords[j]);
@@ -709,7 +709,7 @@ linespec_lexer_lex_string (linespec_parser *parser)
{
if (isspace (*PARSER_STREAM (parser)))
{
- p = skip_spaces_const (PARSER_STREAM (parser));
+ p = skip_spaces (PARSER_STREAM (parser));
/* When we get here we know we've found something followed by
a space (we skip over parens and templates below).
So if we find a keyword now, we know it is a keyword and not,
@@ -856,7 +856,7 @@ linespec_lexer_lex_one (linespec_parser *parser)
if (parser->lexer.current.type == LSTOKEN_CONSUMED)
{
/* Skip any whitespace. */
- PARSER_STREAM (parser) = skip_spaces_const (PARSER_STREAM (parser));
+ PARSER_STREAM (parser) = skip_spaces (PARSER_STREAM (parser));
/* Check for a keyword, they end the linespec. */
keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser));
@@ -1770,7 +1770,7 @@ set_completion_after_number (linespec_parser *parser,
{
if (*PARSER_STREAM (parser) == ' ')
{
- parser->completion_word = skip_spaces_const (PARSER_STREAM (parser) + 1);
+ parser->completion_word = skip_spaces (PARSER_STREAM (parser) + 1);
parser->complete_what = next;
}
else
@@ -2000,7 +2000,7 @@ linespec_parse_basic (linespec_parser *parser)
if (ptr[i] == ' ')
{
LS_TOKEN_STOKEN (token).length = i;
- PARSER_STREAM (parser) = skip_spaces_const (ptr + i + 1);
+ PARSER_STREAM (parser) = skip_spaces (ptr + i + 1);
break;
}
}
@@ -2697,7 +2697,7 @@ parse_linespec (linespec_parser *parser, const char *arg)
advances past a keyword automatically, so skip it
manually. */
parser->completion_word
- = skip_spaces_const (skip_to_space_const (PARSER_STREAM (parser)));
+ = skip_spaces (skip_to_space (PARSER_STREAM (parser)));
parser->complete_what = linespec_complete_what::EXPRESSION;
}
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 61ea13c..9ca1aca 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -440,7 +440,7 @@ read_mapping (const char *line,
p++;
*endaddr = strtoulst (p, &p, 16);
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
*permissions = p;
while (*p && !isspace (*p))
p++;
@@ -448,7 +448,7 @@ read_mapping (const char *line,
*offset = strtoulst (p, &p, 16);
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
*device = p;
while (*p && !isspace (*p))
p++;
@@ -456,7 +456,7 @@ read_mapping (const char *line,
*inode = strtoulst (p, &p, 10);
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
*filename = p;
}
@@ -740,7 +740,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
pid = current_inferior ()->pid;
}
- args = skip_spaces_const (args);
+ args = skip_spaces (args);
if (args && args[0])
error (_("Too many parameters: %s"), args);
@@ -870,7 +870,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
printf_filtered (_("Process: %s\n"),
pulongest (strtoulst (p, &p, 10)));
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
if (*p == '(')
{
/* ps command also relies on no trailing fields
@@ -884,7 +884,7 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args,
}
}
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
if (*p)
printf_filtered (_("State: %c\n"), *p++);
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 6567e93..0e16f6a 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -1560,7 +1560,7 @@ info_auto_load_libthread_db (char *args, int from_tty)
char *pids;
int i;
- cs = skip_spaces_const (cs);
+ cs = skip_spaces (cs);
if (*cs)
error (_("'info auto-load libthread-db' does not accept any parameters"));
diff --git a/gdb/location.c b/gdb/location.c
index 3238c9a..cda26e8 100644
--- a/gdb/location.c
+++ b/gdb/location.c
@@ -746,7 +746,7 @@ string_to_explicit_location (const char **argp,
len = strlen (opt.get ());
/* Get the argument string. */
- *argp = skip_spaces_const (*argp);
+ *argp = skip_spaces (*argp);
/* All options have a required argument. Checking for this
required argument is deferred until later. */
@@ -779,7 +779,7 @@ string_to_explicit_location (const char **argp,
else if (strncmp (opt.get (), "-line", len) == 0)
{
set_oarg (explicit_location_lex_one (argp, language, NULL));
- *argp = skip_spaces_const (*argp);
+ *argp = skip_spaces (*argp);
if (have_oarg)
{
EL_EXPLICIT (location)->line_offset
@@ -808,7 +808,7 @@ string_to_explicit_location (const char **argp,
return location;
}
- *argp = skip_spaces_const (*argp);
+ *argp = skip_spaces (*argp);
/* It's a little lame to error after the fact, but in this
case, it provides a much better user experience to issue
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index fea85d5..ad1478e 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -119,7 +119,7 @@ mi_parse_argv (const char *args, struct mi_parse *parse)
char *arg;
/* Skip leading white space. */
- chp = skip_spaces_const (chp);
+ chp = skip_spaces (chp);
/* Three possibilities: EOF, quoted string, or other text. */
switch (*chp)
{
@@ -242,7 +242,7 @@ mi_parse (const char *cmd, char **token)
std::unique_ptr<struct mi_parse> parse (new struct mi_parse);
/* Before starting, skip leading white space. */
- cmd = skip_spaces_const (cmd);
+ cmd = skip_spaces (cmd);
/* Find/skip any token and then extract it. */
for (chp = cmd; *chp >= '0' && *chp <= '9'; chp++)
@@ -254,7 +254,7 @@ mi_parse (const char *cmd, char **token)
/* This wasn't a real MI command. Return it as a CLI_COMMAND. */
if (*chp != '-')
{
- chp = skip_spaces_const (chp);
+ chp = skip_spaces (chp);
parse->command = xstrdup (chp);
parse->op = CLI_COMMAND;
@@ -279,7 +279,7 @@ mi_parse (const char *cmd, char **token)
_("Undefined MI command: %s"), parse->command);
/* Skip white space following the command. */
- chp = skip_spaces_const (chp);
+ chp = skip_spaces (chp);
/* Parse the --thread and --frame options, if present. At present,
some important commands, like '-break-*' are implemented by
@@ -352,7 +352,7 @@ mi_parse (const char *cmd, char **token)
option = "--language";
chp += ls;
- lang_name = extract_arg_const (&chp);
+ lang_name = extract_arg (&chp);
old_chain = make_cleanup (xfree, lang_name);
parse->language = language_enum (lang_name);
@@ -367,7 +367,7 @@ mi_parse (const char *cmd, char **token)
if (*chp != '\0' && !isspace (*chp))
error (_("Invalid value for the '%s' option"), option);
- chp = skip_spaces_const (chp);
+ chp = skip_spaces (chp);
}
/* For new argv commands, attempt to return the parsed argument
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 69b9e40..37edbd8 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -90,7 +90,7 @@ msymbol_hash_iw (const char *string)
while (*string && *string != '(')
{
- string = skip_spaces_const (string);
+ string = skip_spaces (string);
if (*string && *string != '(')
{
hash = SYMBOL_HASH_NEXT (hash, *string);
diff --git a/gdb/nat/linux-procfs.c b/gdb/nat/linux-procfs.c
index cca35cb..8020a43 100644
--- a/gdb/nat/linux-procfs.c
+++ b/gdb/nat/linux-procfs.c
@@ -96,7 +96,7 @@ enum proc_state
static enum proc_state
parse_proc_status_state (const char *state)
{
- state = skip_spaces_const (state);
+ state = skip_spaces (state);
switch (state[0])
{
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index a7d5762..033d687 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2447,7 +2447,7 @@ ui_printf (const char *arg, struct ui_file *stream)
if (s == 0)
error_no_arg (_("format-control string and values to print"));
- s = skip_spaces_const (s);
+ s = skip_spaces (s);
/* A format string should follow, enveloped in double quotes. */
if (*s++ != '"')
@@ -2460,14 +2460,14 @@ ui_printf (const char *arg, struct ui_file *stream)
if (*s++ != '"')
error (_("Bad format string, non-terminated '\"'."));
- s = skip_spaces_const (s);
+ s = skip_spaces (s);
if (*s != ',' && *s != 0)
error (_("Invalid argument syntax"));
if (*s == ',')
s++;
- s = skip_spaces_const (s);
+ s = skip_spaces (s);
{
int nargs = 0;
diff --git a/gdb/probe.c b/gdb/probe.c
index 686e90e..7b3b888 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -558,12 +558,12 @@ parse_probe_linespec (const char *str, char **provider,
{
*probe_name = *objname = NULL;
- *provider = extract_arg_const (&str);
+ *provider = extract_arg (&str);
if (*provider != NULL)
{
- *probe_name = extract_arg_const (&str);
+ *probe_name = extract_arg (&str);
if (*probe_name != NULL)
- *objname = extract_arg_const (&str);
+ *objname = extract_arg (&str);
}
}
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 6156eb6..d57c2fa 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -673,7 +673,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
TRY
{
gdb::unique_xmalloc_ptr<char>
- copy_holder (xstrdup (skip_spaces_const (spec)));
+ copy_holder (xstrdup (skip_spaces (spec)));
char *copy = copy_holder.get ();
switch (type)
diff --git a/gdb/record.c b/gdb/record.c
index 7eef827..59fb240 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -431,7 +431,7 @@ get_insn_number (char **arg)
const char *begin, *end, *pos;
begin = *arg;
- pos = skip_spaces_const (begin);
+ pos = skip_spaces (begin);
if (!isdigit (*pos))
error (_("Expected positive number, got: %s."), pos);
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 5d99994..88c6623 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -1515,7 +1515,7 @@ lex_number (void)
gdb_assert (subexps[0].rm_eo > 0);
if (lexptr[subexps[0].rm_eo - 1] == '.')
{
- const char *next = skip_spaces_const (&lexptr[subexps[0].rm_eo]);
+ const char *next = skip_spaces (&lexptr[subexps[0].rm_eo]);
if (rust_identifier_start_p (*next) || *next == '.')
{
diff --git a/gdb/serial.c b/gdb/serial.c
index 01294d1..91fdcbb 100644
--- a/gdb/serial.c
+++ b/gdb/serial.c
@@ -212,7 +212,7 @@ serial_open (const char *name)
ops = serial_interface_lookup ("pipe");
/* Discard ``|'' and any space before the command itself. */
++open_name;
- open_name = skip_spaces_const (open_name);
+ open_name = skip_spaces (open_name);
}
/* Check for a colon, suggesting an IP address/port pair.
Do this *after* checking for all the interesting prefixes. We
diff --git a/gdb/stack.c b/gdb/stack.c
index 2433009..f48fa1d 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1285,7 +1285,7 @@ parse_frame_specification (const char *frame_exp, int *selected_frame_p)
const char *p;
/* Skip leading white space, bail of EOL. */
- frame_exp = skip_spaces_const (frame_exp);
+ frame_exp = skip_spaces (frame_exp);
if (!*frame_exp)
break;
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index c0cc662..3dc2d73 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -769,7 +769,7 @@ stap_parse_single_operand (struct stap_parse_info *p)
We handle the register displacement here, and the other cases
recursively. */
if (p->inside_paren_p)
- tmp = skip_spaces_const (tmp);
+ tmp = skip_spaces (tmp);
while (isdigit (*tmp))
{
@@ -818,7 +818,7 @@ stap_parse_single_operand (struct stap_parse_info *p)
tmp = endp;
if (p->inside_paren_p)
- tmp = skip_spaces_const (tmp);
+ tmp = skip_spaces (tmp);
/* If "stap_is_integer_prefix" returns true, it means we can
accept integers without a prefix here. But we also need to
@@ -901,7 +901,7 @@ stap_parse_argument_conditionally (struct stap_parse_info *p)
have to parse it as it was a separate expression, without
left-side or precedence. */
++p->arg;
- p->arg = skip_spaces_const (p->arg);
+ p->arg = skip_spaces (p->arg);
++p->inside_paren_p;
stap_parse_argument_1 (p, 0, STAP_OPERAND_PREC_NONE);
@@ -913,7 +913,7 @@ stap_parse_argument_conditionally (struct stap_parse_info *p)
++p->arg;
if (p->inside_paren_p)
- p->arg = skip_spaces_const (p->arg);
+ p->arg = skip_spaces (p->arg);
}
else
error (_("Cannot parse expression `%s'."), p->saved_arg);
@@ -935,7 +935,7 @@ stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
gdb_assert (p->arg != NULL);
if (p->inside_paren_p)
- p->arg = skip_spaces_const (p->arg);
+ p->arg = skip_spaces (p->arg);
if (!has_lhs)
{
@@ -981,7 +981,7 @@ stap_parse_argument_1 (struct stap_parse_info *p, int has_lhs,
p->arg = tmp_exp_buf;
if (p->inside_paren_p)
- p->arg = skip_spaces_const (p->arg);
+ p->arg = skip_spaces (p->arg);
/* Parse the right-side of the expression. */
stap_parse_argument_conditionally (p);
@@ -1074,7 +1074,7 @@ stap_parse_argument (const char **arg, struct type *atype,
reallocate_expout (&p.pstate);
- p.arg = skip_spaces_const (p.arg);
+ p.arg = skip_spaces (p.arg);
*arg = p.arg;
/* We can safely return EXPOUT here. */
@@ -1189,7 +1189,7 @@ stap_parse_probe_arguments (struct stap_probe *probe, struct gdbarch *gdbarch)
arg.aexpr = expr;
/* Start it over again. */
- cur = skip_spaces_const (cur);
+ cur = skip_spaces (cur);
VEC_safe_push (stap_probe_arg_s, probe->args_u.vec, &arg);
}
diff --git a/gdb/tid-parse.c b/gdb/tid-parse.c
index 84e9bfe..83dc07c 100644
--- a/gdb/tid-parse.c
+++ b/gdb/tid-parse.c
@@ -229,7 +229,7 @@ tid_range_parser::get_tid_or_range (int *inf_num,
{
/* Setup the number range parser to return numbers in the
whole [1,INT_MAX] range. */
- m_range_parser.setup_range (1, INT_MAX, skip_spaces_const (p + 1));
+ m_range_parser.setup_range (1, INT_MAX, skip_spaces (p + 1));
m_state = STATE_STAR_RANGE;
}
else
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index dbd850f..437db59 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -618,7 +618,7 @@ decode_agent_options (const char *exp, int *trace_string)
else
error (_("Undefined collection format \"%c\"."), *exp);
- exp = skip_spaces_const (exp);
+ exp = skip_spaces (exp);
return exp;
}
@@ -685,7 +685,7 @@ validate_actionline (const char *line, struct breakpoint *b)
if (line == NULL)
return;
- p = skip_spaces_const (line);
+ p = skip_spaces (line);
/* Symbol lookup etc. */
if (*p == '\0') /* empty line: just prompt for another line. */
@@ -708,7 +708,7 @@ validate_actionline (const char *line, struct breakpoint *b)
do
{ /* Repeat over a comma-separated list. */
QUIT; /* Allow user to bail out with ^C. */
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
if (*p == '$') /* Look for special pseudo-symbols. */
{
@@ -771,7 +771,7 @@ validate_actionline (const char *line, struct breakpoint *b)
do
{ /* Repeat over a comma-separated list. */
QUIT; /* Allow user to bail out with ^C. */
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
tmp_p = p;
for (loc = t->loc; loc; loc = loc->next)
@@ -801,7 +801,7 @@ validate_actionline (const char *line, struct breakpoint *b)
{
char *endp;
- p = skip_spaces_const (p);
+ p = skip_spaces (p);
t->step_count = strtol (p, &endp, 0);
if (endp == p || t->step_count == 0)
error (_("while-stepping step count `%s' is malformed."), line);
@@ -1311,7 +1311,7 @@ encode_actions_1 (struct command_line *action,
{
QUIT; /* Allow user to bail out with ^C. */
action_exp = action->line;
- action_exp = skip_spaces_const (action_exp);
+ action_exp = skip_spaces (action_exp);
cmd = lookup_cmd (&action_exp, cmdlist, "", -1, 1);
if (cmd == 0)
@@ -1327,7 +1327,7 @@ encode_actions_1 (struct command_line *action,
do
{ /* Repeat over a comma-separated list. */
QUIT; /* Allow user to bail out with ^C. */
- action_exp = skip_spaces_const (action_exp);
+ action_exp = skip_spaces (action_exp);
if (0 == strncasecmp ("$reg", action_exp, 4))
{
@@ -1487,7 +1487,7 @@ encode_actions_1 (struct command_line *action,
do
{ /* Repeat over a comma-separated list. */
QUIT; /* Allow user to bail out with ^C. */
- action_exp = skip_spaces_const (action_exp);
+ action_exp = skip_spaces (action_exp);
{
struct cleanup *old_chain1 = NULL;
@@ -2733,7 +2733,7 @@ trace_dump_actions (struct command_line *action,
QUIT; /* Allow user to bail out with ^C. */
action_exp = action->line;
- action_exp = skip_spaces_const (action_exp);
+ action_exp = skip_spaces (action_exp);
/* The collection actions to be done while stepping are
bracketed by the commands "while-stepping" and "end". */
@@ -2776,7 +2776,7 @@ trace_dump_actions (struct command_line *action,
QUIT; /* Allow user to bail out with ^C. */
if (*action_exp == ',')
action_exp++;
- action_exp = skip_spaces_const (action_exp);
+ action_exp = skip_spaces (action_exp);
next_comma = strchr (action_exp, ',');
--
2.9.4
^ permalink raw reply [flat|nested] 8+ messages in thread* [RFA 3/3] Make extract_arg return a std::string
2017-09-11 0:33 [RFA 0/3] preparation for command constification; cleanup removal Tom Tromey
2017-09-11 0:33 ` [RFA 2/3] Constify language_enum Tom Tromey
2017-09-11 0:33 ` [RFA 1/3] Rename _const functions to use overloading instead Tom Tromey
@ 2017-09-11 0:33 ` Tom Tromey
2017-09-11 19:52 ` Simon Marchi
2 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2017-09-11 0:33 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
Change extract_arg to return a std::string and fix up all the users.
I think string is mildly better than unique_xmalloc_ptr<char>, when
possible, because it provides a more robust API.
I changed the error messages emitted from find_location_by_number to
avoid either writing to a string or an extra allocation; this can be
changed but I thought that the new message was not any less clear.
You can see an example in the testsuite patch.
ChangeLog
2017-09-10 Tom Tromey <tom@tromey.com>
* demangle.c (demangle_command): Update.
* breakpoint.c (disable_command): Update.
(enable_command): Update.
(find_location_by_number): Make "number" const. Use
get_number_trailer.
* cli/cli-utils.c (extract_arg): Return std::string.
* probe.c (parse_probe_linespec): Update. Change types.
(collect_probes): Take string arguments.
(parse_probe_linespec): Likewise.
(info_probes_for_ops): Update.
(enable_probes_command): Update.
(disable_probes_command): Update.
* break-catch-sig.c (catch_signal_split_args): Update.
* mi/mi-parse.c (mi_parse): Update.
testsuite/ChangeLog
2017-09-10 Tom Tromey <tom@tromey.com>
* gdb.base/ena-dis-br.exp (test_ena_dis_br): Update test.
---
gdb/ChangeLog | 17 ++++++++++++
gdb/break-catch-sig.c | 12 ++++-----
gdb/breakpoint.c | 39 ++++++++++++++-------------
gdb/cli/cli-utils.c | 14 +++++-----
gdb/cli/cli-utils.h | 13 ++++-----
gdb/demangle.c | 14 +++++-----
gdb/mi/mi-parse.c | 12 +++------
gdb/probe.c | 50 +++++++++++++++--------------------
gdb/testsuite/ChangeLog | 4 +++
gdb/testsuite/gdb.base/ena-dis-br.exp | 2 +-
10 files changed, 91 insertions(+), 86 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4c2a924..3201486 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,22 @@
2017-09-10 Tom Tromey <tom@tromey.com>
+ * demangle.c (demangle_command): Update.
+ * breakpoint.c (disable_command): Update.
+ (enable_command): Update.
+ (find_location_by_number): Make "number" const. Use
+ get_number_trailer.
+ * cli/cli-utils.c (extract_arg): Return std::string.
+ * probe.c (parse_probe_linespec): Update. Change types.
+ (collect_probes): Take string arguments.
+ (parse_probe_linespec): Likewise.
+ (info_probes_for_ops): Update.
+ (enable_probes_command): Update.
+ (disable_probes_command): Update.
+ * break-catch-sig.c (catch_signal_split_args): Update.
+ * mi/mi-parse.c (mi_parse): Update.
+
+2017-09-10 Tom Tromey <tom@tromey.com>
+
* language.h (language_enum): Make argument const.
* language.c (language_enum): Make argument const.
diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c
index 805084f..237dbaa 100644
--- a/gdb/break-catch-sig.c
+++ b/gdb/break-catch-sig.c
@@ -343,12 +343,12 @@ catch_signal_split_args (char *arg, bool *catch_all)
gdb_signal signal_number;
char *endptr;
- gdb::unique_xmalloc_ptr<char> one_arg (extract_arg (&arg));
- if (one_arg == NULL)
+ std::string one_arg = extract_arg (&arg);
+ if (one_arg.empty ())
break;
/* Check for the special flag "all". */
- if (strcmp (one_arg.get (), "all") == 0)
+ if (strcmp (one_arg.c_str (), "all") == 0)
{
arg = skip_spaces (arg);
if (*arg != '\0' || !first)
@@ -361,14 +361,14 @@ catch_signal_split_args (char *arg, bool *catch_all)
first = false;
/* Check if the user provided a signal name or a number. */
- num = (int) strtol (one_arg.get (), &endptr, 0);
+ num = (int) strtol (one_arg.c_str (), &endptr, 0);
if (*endptr == '\0')
signal_number = gdb_signal_from_command (num);
else
{
- signal_number = gdb_signal_from_name (one_arg.get ());
+ signal_number = gdb_signal_from_name (one_arg.c_str ());
if (signal_number == GDB_SIGNAL_UNKNOWN)
- error (_("Unknown signal name '%s'."), one_arg.get ());
+ error (_("Unknown signal name '%s'."), one_arg.c_str ());
}
result.push_back (signal_number);
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index b642bc6..79543fe 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -14489,20 +14489,17 @@ map_breakpoint_numbers (const char *args,
}
static struct bp_location *
-find_location_by_number (char *number)
+find_location_by_number (const char *number)
{
- char *dot = strchr (number, '.');
- char *p1;
+ const char *p1;
int bp_num;
int loc_num;
struct breakpoint *b;
struct bp_location *loc;
- *dot = '\0';
-
p1 = number;
- bp_num = get_number (&p1);
- if (bp_num == 0)
+ bp_num = get_number_trailer (&p1, '.');
+ if (bp_num == 0 || p1[0] != '.')
error (_("Bad breakpoint number '%s'"), number);
ALL_BREAKPOINTS (b)
@@ -14514,7 +14511,9 @@ find_location_by_number (char *number)
if (!b || b->number != bp_num)
error (_("Bad breakpoint number '%s'"), number);
- p1 = dot+1;
+ /* Skip the dot. */
+ ++p1;
+ const char *save = p1;
loc_num = get_number (&p1);
if (loc_num == 0)
error (_("Bad breakpoint location number '%s'"), number);
@@ -14524,7 +14523,7 @@ find_location_by_number (char *number)
for (;loc_num && loc; --loc_num, loc = loc->next)
;
if (!loc)
- error (_("Bad breakpoint location number '%s'"), dot+1);
+ error (_("Bad breakpoint location number '%s'"), save);
return loc;
}
@@ -14592,13 +14591,13 @@ disable_command (char *args, int from_tty)
}
else
{
- char *num = extract_arg (&args);
+ std::string num = extract_arg (&args);
- while (num)
+ while (!num.empty ())
{
- if (strchr (num, '.'))
+ if (num.find ('.') != std::string::npos)
{
- struct bp_location *loc = find_location_by_number (num);
+ struct bp_location *loc = find_location_by_number (num.c_str ());
if (loc)
{
@@ -14615,7 +14614,8 @@ disable_command (char *args, int from_tty)
update_global_location_list (UGLL_DONT_INSERT);
}
else
- map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL);
+ map_breakpoint_numbers (num.c_str (), do_map_disable_breakpoint,
+ NULL);
num = extract_arg (&args);
}
}
@@ -14723,13 +14723,13 @@ enable_command (char *args, int from_tty)
}
else
{
- char *num = extract_arg (&args);
+ std::string num = extract_arg (&args);
- while (num)
+ while (!num.empty ())
{
- if (strchr (num, '.'))
+ if (num.find ('.') != std::string::npos)
{
- struct bp_location *loc = find_location_by_number (num);
+ struct bp_location *loc = find_location_by_number (num.c_str ());
if (loc)
{
@@ -14746,7 +14746,8 @@ enable_command (char *args, int from_tty)
update_global_location_list (UGLL_MAY_INSERT);
}
else
- map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL);
+ map_breakpoint_numbers (num.c_str (), do_map_enable_breakpoint,
+ NULL);
num = extract_arg (&args);
}
}
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index a00bc52..d5273b5 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -249,36 +249,36 @@ remove_trailing_whitespace (const char *start, const char *s)
/* See documentation in cli-utils.h. */
-char *
+std::string
extract_arg (const char **arg)
{
const char *result;
if (!*arg)
- return NULL;
+ return std::string ();
/* Find the start of the argument. */
*arg = skip_spaces (*arg);
if (!**arg)
- return NULL;
+ return std::string ();
result = *arg;
/* Find the end of the argument. */
*arg = skip_to_space (*arg + 1);
if (result == *arg)
- return NULL;
+ return std::string ();
- return savestring (result, *arg - result);
+ return std::string (result, *arg - result);
}
/* See documentation in cli-utils.h. */
-char *
+std::string
extract_arg (char **arg)
{
const char *arg_const = *arg;
- char *result;
+ std::string result;
result = extract_arg (&arg_const);
*arg += arg_const - *arg;
diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h
index 038ddad..c17b4dd 100644
--- a/gdb/cli/cli-utils.h
+++ b/gdb/cli/cli-utils.h
@@ -149,17 +149,14 @@ remove_trailing_whitespace (const char *start, 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
- argument was found, or an xmalloc'd string. */
+ delimited by whitespace. The return value is either empty if no
+ argument was found. */
-extern char *extract_arg (char **arg);
+extern std::string extract_arg (char **arg);
-/* A const-correct version of "extract_arg".
+/* A const-correct version of "extract_arg". */
- Since the returned value is xmalloc'd, it eventually needs to be
- xfree'ed, which prevents us from making it const as well. */
-
-extern char *extract_arg (const char **arg);
+extern std::string extract_arg (const char **arg);
/* A helper function that looks for an argument at the start of a
string. The argument must also either be at the end of the string,
diff --git a/gdb/demangle.c b/gdb/demangle.c
index 892ad18..5430fb6 100644
--- a/gdb/demangle.c
+++ b/gdb/demangle.c
@@ -170,21 +170,21 @@ demangle_command (char *args, int from_tty)
std::string arg_buf = args != NULL ? args : "";
arg_start = arg_buf.c_str ();
- gdb::unique_xmalloc_ptr<char> lang_name;
+ std::string lang_name;
while (processing_args
&& *arg_start == '-')
{
const char *p = skip_to_space (arg_start);
if (strncmp (arg_start, "-l", p - arg_start) == 0)
- lang_name.reset (extract_arg (&p));
+ lang_name = extract_arg (&p);
else if (strncmp (arg_start, "--", p - arg_start) == 0)
processing_args = 0;
else
{
- gdb::unique_xmalloc_ptr<char> option (extract_arg (&p));
+ std::string option = extract_arg (&p);
error (_("Unrecognized option '%s' to demangle command. "
- "Try \"help demangle\"."), option.get ());
+ "Try \"help demangle\"."), option.c_str ());
}
arg_start = skip_spaces (p);
@@ -195,13 +195,13 @@ demangle_command (char *args, int from_tty)
if (*name == '\0')
error (_("Usage: demangle [-l language] [--] name"));
- if (lang_name != NULL)
+ if (!lang_name.empty ())
{
enum language lang_enum;
- lang_enum = language_enum (lang_name.get ());
+ lang_enum = language_enum (lang_name.c_str ());
if (lang_enum == language_unknown)
- error (_("Unknown language \"%s\""), lang_name.get ());
+ error (_("Unknown language \"%s\""), lang_name.c_str ());
lang = language_def (lang_enum);
}
else
diff --git a/gdb/mi/mi-parse.c b/gdb/mi/mi-parse.c
index ad1478e..cf05fa0 100644
--- a/gdb/mi/mi-parse.c
+++ b/gdb/mi/mi-parse.c
@@ -347,20 +347,14 @@ mi_parse (const char *cmd, char **token)
}
else if (strncmp (chp, "--language ", ls) == 0)
{
- char *lang_name;
- struct cleanup *old_chain;
-
option = "--language";
chp += ls;
- lang_name = extract_arg (&chp);
- old_chain = make_cleanup (xfree, lang_name);
+ std::string lang_name = extract_arg (&chp);
- parse->language = language_enum (lang_name);
+ parse->language = language_enum (lang_name.c_str ());
if (parse->language == language_unknown
|| parse->language == language_auto)
- error (_("Invalid --language argument: %s"), lang_name);
-
- do_cleanups (old_chain);
+ error (_("Invalid --language argument: %s"), lang_name.c_str ());
}
else
break;
diff --git a/gdb/probe.c b/gdb/probe.c
index 7b3b888..11fc775 100644
--- a/gdb/probe.c
+++ b/gdb/probe.c
@@ -275,8 +275,8 @@ find_probe_by_pc (CORE_ADDR pc)
Each argument is a regexp, or NULL, which matches anything. */
static VEC (bound_probe_s) *
-collect_probes (char *objname, char *provider, char *probe_name,
- const struct probe_ops *pops)
+collect_probes (const std::string &objname, const std::string &provider,
+ const std::string &probe_name, const struct probe_ops *pops)
{
struct objfile *objfile;
VEC (bound_probe_s) *result = NULL;
@@ -285,12 +285,15 @@ collect_probes (char *objname, char *provider, char *probe_name,
cleanup = make_cleanup (VEC_cleanup (bound_probe_s), &result);
- if (provider != NULL)
- prov_pat.emplace (provider, REG_NOSUB, _("Invalid provider regexp"));
- if (probe_name != NULL)
- probe_pat.emplace (probe_name, REG_NOSUB, _("Invalid probe regexp"));
- if (objname != NULL)
- obj_pat.emplace (objname, REG_NOSUB, _("Invalid object file regexp"));
+ if (!provider.empty ())
+ prov_pat.emplace (provider.c_str (), REG_NOSUB,
+ _("Invalid provider regexp"));
+ if (!probe_name.empty ())
+ probe_pat.emplace (probe_name.c_str (), REG_NOSUB,
+ _("Invalid probe regexp"));
+ if (!objname.empty ())
+ obj_pat.emplace (objname.c_str (), REG_NOSUB,
+ _("Invalid object file regexp"));
ALL_OBJFILES (objfile)
{
@@ -301,7 +304,7 @@ collect_probes (char *objname, char *provider, char *probe_name,
if (! objfile->sf || ! objfile->sf->sym_probe_fns)
continue;
- if (objname)
+ if (obj_pat)
{
if (obj_pat->exec (objfile_name (objfile), 0, NULL, 0) != 0)
continue;
@@ -316,11 +319,11 @@ collect_probes (char *objname, char *provider, char *probe_name,
if (pops != NULL && probe->pops != pops)
continue;
- if (provider
+ if (prov_pat
&& prov_pat->exec (probe->provider, 0, NULL, 0) != 0)
continue;
- if (probe_name
+ if (probe_pat
&& probe_pat->exec (probe->name, 0, NULL, 0) != 0)
continue;
@@ -553,16 +556,14 @@ exists_probe_with_pops (VEC (bound_probe_s) *probes,
[PROBE [OBJNAME]]] from the provided string STR. */
static void
-parse_probe_linespec (const char *str, char **provider,
- char **probe_name, char **objname)
+parse_probe_linespec (const char *str, std::string *provider,
+ std::string *probe_name, std::string *objname)
{
- *probe_name = *objname = NULL;
-
*provider = extract_arg (&str);
- if (*provider != NULL)
+ if (!provider->empty ())
{
*probe_name = extract_arg (&str);
- if (*probe_name != NULL)
+ if (!probe_name->empty ())
*objname = extract_arg (&str);
}
}
@@ -573,7 +574,7 @@ void
info_probes_for_ops (const char *arg, int from_tty,
const struct probe_ops *pops)
{
- char *provider, *probe_name = NULL, *objname = NULL;
+ std::string provider, probe_name, objname;
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
VEC (bound_probe_s) *probes;
int i, any_found;
@@ -587,9 +588,6 @@ info_probes_for_ops (const char *arg, int from_tty,
struct gdbarch *gdbarch = get_current_arch ();
parse_probe_linespec (arg, &provider, &probe_name, &objname);
- make_cleanup (xfree, provider);
- make_cleanup (xfree, probe_name);
- make_cleanup (xfree, objname);
probes = collect_probes (objname, provider, probe_name, pops);
make_cleanup (VEC_cleanup (probe_p), &probes);
@@ -721,16 +719,13 @@ info_probes_command (char *arg, int from_tty)
static void
enable_probes_command (char *arg, int from_tty)
{
- char *provider, *probe_name = NULL, *objname = NULL;
+ std::string provider, probe_name, objname;
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
VEC (bound_probe_s) *probes;
struct bound_probe *probe;
int i;
parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
- make_cleanup (xfree, provider);
- make_cleanup (xfree, probe_name);
- make_cleanup (xfree, objname);
probes = collect_probes (objname, provider, probe_name, NULL);
if (VEC_empty (bound_probe_s, probes))
@@ -765,16 +760,13 @@ enable_probes_command (char *arg, int from_tty)
static void
disable_probes_command (char *arg, int from_tty)
{
- char *provider, *probe_name = NULL, *objname = NULL;
+ std::string provider, probe_name, objname;
struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
VEC (bound_probe_s) *probes;
struct bound_probe *probe;
int i;
parse_probe_linespec ((const char *) arg, &provider, &probe_name, &objname);
- make_cleanup (xfree, provider);
- make_cleanup (xfree, probe_name);
- make_cleanup (xfree, objname);
probes = collect_probes (objname, provider, probe_name, NULL /* pops */);
if (VEC_empty (bound_probe_s, probes))
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 8d8dc3c..d730fda 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2017-09-10 Tom Tromey <tom@tromey.com>
+
+ * gdb.base/ena-dis-br.exp (test_ena_dis_br): Update test.
+
2017-09-08 Christoph Weinmann <christoph.t.weinmann@intel.com>
* gdb.fortran/printing-types.exp: New file.
diff --git a/gdb/testsuite/gdb.base/ena-dis-br.exp b/gdb/testsuite/gdb.base/ena-dis-br.exp
index 8abca35..d407408 100644
--- a/gdb/testsuite/gdb.base/ena-dis-br.exp
+++ b/gdb/testsuite/gdb.base/ena-dis-br.exp
@@ -369,7 +369,7 @@ proc test_ena_dis_br { what } {
# Now enable(disable) $b1 fooo.1, it should give error on fooo.
gdb_test "$what $b1 fooo.1" \
- "Bad breakpoint number 'fooo'" \
+ "Bad breakpoint number 'fooo\\.1'" \
"$what \$b1 fooo.1"
# $b1 should be enabled(disabled).
--
2.9.4
^ permalink raw reply [flat|nested] 8+ messages in thread