From: Tom Tromey Date: Fri, 11 Aug 2017 20:48:17 +0000 (-0600) Subject: Use std::string thread.c X-Git-Tag: users/ARM/embedded-binutils-master-2017q4~1223 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7ffd83d70f2792a8a538e8599959a6ed7f5b751d;p=external%2Fbinutils.git 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 * thread.c (print_thread_info_1): Use string_printf. (thread_apply_command, thread_apply_all_command): Use std::string. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 33b264d..73847c5 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2017-09-03 Tom Tromey + * thread.c (print_thread_info_1): Use string_printf. + (thread_apply_command, thread_apply_all_command): Use + std::string. + +2017-09-03 Tom Tromey + * valprint.c (val_print_string): Update. * gdbcore.h (memory_error_message): Return std::string. * corefile.c (memory_error_message): Return std::string. diff --git a/gdb/thread.c b/gdb/thread.c index 3cf1b94..8a0ed0c 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -1343,22 +1343,19 @@ print_thread_info_1 (struct ui_out *uiout, char *requested_threads, } else { - struct cleanup *str_cleanup; - char *contents; + std::string contents; if (extra_info && name) - contents = xstrprintf ("%s \"%s\" (%s)", target_id, - name, extra_info); + contents = string_printf ("%s \"%s\" (%s)", target_id, + name, 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) - contents = xstrprintf ("%s \"%s\"", target_id, name); + contents = string_printf ("%s \"%s\"", target_id, name); else - contents = xstrdup (target_id); - str_cleanup = make_cleanup (xfree, contents); + contents = target_id; - uiout->field_string ("target-id", contents); - do_cleanups (str_cleanup); + uiout->field_string ("target-id", contents.c_str ()); } if (tp->state == THREAD_RUNNING) @@ -1701,8 +1698,6 @@ tp_array_compar (const thread_info *a, const thread_info *b) static void thread_apply_all_command (char *cmd, int from_tty) { - char *saved_cmd; - tp_array_compar_ascending = false; if (cmd != NULL && 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 execute_command. */ - saved_cmd = xstrdup (cmd); - make_cleanup (xfree, saved_cmd); + std::string saved_cmd = cmd; int tc = live_threads_count (); if (tc != 0) @@ -1761,7 +1755,7 @@ thread_apply_all_command (char *cmd, int from_tty) execute_command (cmd, from_tty); /* 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) { char *cmd = NULL; - struct cleanup *old_chain; - char *saved_cmd; tid_range_parser parser; 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 execute_command. */ - saved_cmd = xstrdup (cmd); - old_chain = make_cleanup (xfree, saved_cmd); + std::string saved_cmd = cmd; scoped_restore_current_thread restore_thread; @@ -1857,10 +1848,8 @@ thread_apply_command (char *tidlist, int from_tty) execute_command (cmd, from_tty); /* 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