Use std::string thread.c

This changes a few spots in thread.c to use std::string, removing some
cleanups.

ChangeLog
2017-09-03  Tom Tromey  <tom@tromey.com>

	* thread.c (print_thread_info_1): Use string_printf.
	(thread_apply_command, thread_apply_all_command): Use
	std::string.
This commit is contained in:
Tom Tromey 2017-08-11 14:48:17 -06:00
parent 1ccbe9985f
commit 7ffd83d70f
2 changed files with 17 additions and 22 deletions

View File

@ -1,3 +1,9 @@
2017-09-03 Tom Tromey <tom@tromey.com>
* thread.c (print_thread_info_1): Use string_printf.
(thread_apply_command, thread_apply_all_command): Use
std::string.
2017-09-03 Tom Tromey <tom@tromey.com> 2017-09-03 Tom Tromey <tom@tromey.com>
* valprint.c (val_print_string): Update. * valprint.c (val_print_string): Update.

View File

@ -1343,22 +1343,19 @@ print_thread_info_1 (struct ui_out *uiout, char *requested_threads,
} }
else else
{ {
struct cleanup *str_cleanup; std::string contents;
char *contents;
if (extra_info && name) if (extra_info && name)
contents = xstrprintf ("%s \"%s\" (%s)", target_id, contents = string_printf ("%s \"%s\" (%s)", target_id,
name, extra_info); name, extra_info);
else if (extra_info) else if (extra_info)
contents = xstrprintf ("%s (%s)", target_id, extra_info); contents = string_printf ("%s (%s)", target_id, extra_info);
else if (name) else if (name)
contents = xstrprintf ("%s \"%s\"", target_id, name); contents = string_printf ("%s \"%s\"", target_id, name);
else else
contents = xstrdup (target_id); contents = target_id;
str_cleanup = make_cleanup (xfree, contents);
uiout->field_string ("target-id", contents); uiout->field_string ("target-id", contents.c_str ());
do_cleanups (str_cleanup);
} }
if (tp->state == THREAD_RUNNING) if (tp->state == THREAD_RUNNING)
@ -1701,8 +1698,6 @@ tp_array_compar (const thread_info *a, const thread_info *b)
static void static void
thread_apply_all_command (char *cmd, int from_tty) thread_apply_all_command (char *cmd, int from_tty)
{ {
char *saved_cmd;
tp_array_compar_ascending = false; tp_array_compar_ascending = false;
if (cmd != NULL if (cmd != NULL
&& check_for_argument (&cmd, "-ascending", strlen ("-ascending"))) && check_for_argument (&cmd, "-ascending", strlen ("-ascending")))
@ -1718,8 +1713,7 @@ thread_apply_all_command (char *cmd, int from_tty)
/* Save a copy of the command in case it is clobbered by /* Save a copy of the command in case it is clobbered by
execute_command. */ execute_command. */
saved_cmd = xstrdup (cmd); std::string saved_cmd = cmd;
make_cleanup (xfree, saved_cmd);
int tc = live_threads_count (); int tc = live_threads_count ();
if (tc != 0) if (tc != 0)
@ -1761,7 +1755,7 @@ thread_apply_all_command (char *cmd, int from_tty)
execute_command (cmd, from_tty); execute_command (cmd, from_tty);
/* Restore exact command used previously. */ /* Restore exact command used previously. */
strcpy (cmd, saved_cmd); strcpy (cmd, saved_cmd.c_str ());
} }
} }
} }
@ -1772,8 +1766,6 @@ static void
thread_apply_command (char *tidlist, int from_tty) thread_apply_command (char *tidlist, int from_tty)
{ {
char *cmd = NULL; char *cmd = NULL;
struct cleanup *old_chain;
char *saved_cmd;
tid_range_parser parser; tid_range_parser parser;
if (tidlist == NULL || *tidlist == '\000') if (tidlist == NULL || *tidlist == '\000')
@ -1799,8 +1791,7 @@ thread_apply_command (char *tidlist, int from_tty)
/* Save a copy of the command in case it is clobbered by /* Save a copy of the command in case it is clobbered by
execute_command. */ execute_command. */
saved_cmd = xstrdup (cmd); std::string saved_cmd = cmd;
old_chain = make_cleanup (xfree, saved_cmd);
scoped_restore_current_thread restore_thread; scoped_restore_current_thread restore_thread;
@ -1857,10 +1848,8 @@ thread_apply_command (char *tidlist, int from_tty)
execute_command (cmd, from_tty); execute_command (cmd, from_tty);
/* Restore exact command used previously. */ /* Restore exact command used previously. */
strcpy (cmd, saved_cmd); strcpy (cmd, saved_cmd.c_str ());
} }
do_cleanups (old_chain);
} }
/* Switch to the specified thread. Will dispatch off to thread_apply_command /* Switch to the specified thread. Will dispatch off to thread_apply_command