aboutsummaryrefslogtreecommitdiff
path: root/gdb/target.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2018-08-07 21:37:40 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2018-08-07 21:38:27 -0400
commit09ce46f230fee766c386384cd1f5672d12fde276 (patch)
tree70c4f15a8d7f68622137032f6250cc971119b1dd /gdb/target.c
parentb825f3a90e33ab6f333d12d676d51419f8fed77b (diff)
downloadgdb-09ce46f230fee766c386384cd1f5672d12fde276.zip
gdb-09ce46f230fee766c386384cd1f5672d12fde276.tar.gz
gdb-09ce46f230fee766c386384cd1f5672d12fde276.tar.bz2
Make target_options_to_string return an std::string
Return an std::string instead of a char *, saving some manual freeing. I only manually tested with "set debug target 1" and "set debug lin-lwp 1", since this only deals with debug output. gdb/ChangeLog: * target.h (target_options_to_string): Return an std::string. * target.c (str_comma_list_concat_elem): Return void, use std::string. (do_option): Likewise. (target_options_to_string): Return an std::string. * linux-nat.c (linux_nat_target::wait): Adjust. * target-debug.h (target_debug_print_options): Adjust.
Diffstat (limited to 'gdb/target.c')
-rw-r--r--gdb/target.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/gdb/target.c b/gdb/target.c
index eba07cc..a5245ab 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3441,51 +3441,45 @@ target_continue (ptid_t ptid, enum gdb_signal signal)
target_resume (ptid, 0, signal);
}
-/* Concatenate ELEM to LIST, a comma separate list, and return the
- result. The LIST incoming argument is released. */
+/* Concatenate ELEM to LIST, a comma separate list. */
-static char *
-str_comma_list_concat_elem (char *list, const char *elem)
+static void
+str_comma_list_concat_elem (std::string *list, const char *elem)
{
- if (list == NULL)
- return xstrdup (elem);
- else
- return reconcat (list, list, ", ", elem, (char *) NULL);
+ if (!list->empty ())
+ list->append (", ");
+
+ list->append (elem);
}
/* Helper for target_options_to_string. If OPT is present in
TARGET_OPTIONS, append the OPT_STR (string version of OPT) in RET.
- Returns the new resulting string. OPT is removed from
- TARGET_OPTIONS. */
+ OPT is removed from TARGET_OPTIONS. */
-static char *
-do_option (int *target_options, char *ret,
+static void
+do_option (int *target_options, std::string *ret,
int opt, const char *opt_str)
{
if ((*target_options & opt) != 0)
{
- ret = str_comma_list_concat_elem (ret, opt_str);
+ str_comma_list_concat_elem (ret, opt_str);
*target_options &= ~opt;
}
-
- return ret;
}
-char *
+std::string
target_options_to_string (int target_options)
{
- char *ret = NULL;
+ std::string ret;
#define DO_TARG_OPTION(OPT) \
- ret = do_option (&target_options, ret, OPT, #OPT)
+ do_option (&target_options, &ret, OPT, #OPT)
DO_TARG_OPTION (TARGET_WNOHANG);
if (target_options != 0)
- ret = str_comma_list_concat_elem (ret, "unknown???");
+ str_comma_list_concat_elem (&ret, "unknown???");
- if (ret == NULL)
- ret = xstrdup ("");
return ret;
}