From cb791d59489576280e416262eb61ab59765a0baf Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sun, 10 Sep 2017 14:48:30 -0600 Subject: Make extract_arg return a std::string Change extract_arg to return a std::string and fix up all the users. I think string is mildly better than unique_xmalloc_ptr, 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-11 Tom Tromey * 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-11 Tom Tromey * gdb.base/ena-dis-br.exp (test_ena_dis_br): Update test. --- gdb/cli/cli-utils.c | 14 +++++++------- gdb/cli/cli-utils.h | 13 +++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'gdb/cli') 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 0c25a7e..a77954c 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 empty if no argument + was found. */ -extern char *extract_arg (char **arg); +extern std::string extract_arg (char **arg); -/* A const-correct version of the above. +/* A const-correct version of the above. */ - 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, -- cgit v1.1