aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog10
-rw-r--r--gdb/linux-nat.c7
-rw-r--r--gdb/target-debug.h5
-rw-r--r--gdb/target.c36
-rw-r--r--gdb/target.h5
5 files changed, 31 insertions, 32 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 838029b..6702b44 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2018-08-07 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * 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.
+
2018-08-07 Tom Tromey <tom@tromey.com>
* Makefile.in (CPPFLAGS): New variable.
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index d2c88ad..64015e7 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -3555,14 +3555,11 @@ linux_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
if (debug_linux_nat)
{
- char *options_string;
-
- options_string = target_options_to_string (target_options);
+ std::string options_string = target_options_to_string (target_options);
fprintf_unfiltered (gdb_stdlog,
"linux_nat_wait: [%s], [%s]\n",
target_pid_to_str (ptid),
- options_string);
- xfree (options_string);
+ options_string.c_str ());
}
/* Flush the async file first. */
diff --git a/gdb/target-debug.h b/gdb/target-debug.h
index 331baf5..1e904b9 100644
--- a/gdb/target-debug.h
+++ b/gdb/target-debug.h
@@ -203,10 +203,9 @@ target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
static void
target_debug_print_options (int options)
{
- char *str = target_options_to_string (options);
+ std::string str = target_options_to_string (options);
- fputs_unfiltered (str, gdb_stdlog);
- xfree (str);
+ fputs_unfiltered (str.c_str (), gdb_stdlog);
}
static void
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;
}
diff --git a/gdb/target.h b/gdb/target.h
index 18c4a84..39aa8c3 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -116,9 +116,8 @@ struct syscall
const char *name;
};
-/* Return a pretty printed form of TARGET_OPTIONS.
- Space for the result is malloc'd, caller must free. */
-extern char *target_options_to_string (int target_options);
+/* Return a pretty printed form of TARGET_OPTIONS. */
+extern std::string target_options_to_string (int target_options);
/* Possible types of events that the inferior handler will have to
deal with. */