From patchwork Tue Aug 29 19:25:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 22410 Received: (qmail 6438 invoked by alias); 29 Aug 2017 19:36:48 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 6426 invoked by uid 89); 29 Aug 2017 19:36:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy3-pub.mail.unifiedlayer.com Received: from gproxy3-pub.mail.unifiedlayer.com (HELO gproxy3-pub.mail.unifiedlayer.com) (69.89.30.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 29 Aug 2017 19:36:46 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy3.mail.unifiedlayer.com (Postfix) with ESMTP id 8CC8641AFF for ; Tue, 29 Aug 2017 13:25:31 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id 37RU1w00C2f2jeq017RXBB; Tue, 29 Aug 2017 13:25:31 -0600 X-Authority-Analysis: v=2.2 cv=fJ5J5dSe c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=M-BK_tGMrjEV_u1xx6AA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-76-94.hlrn.qwest.net ([75.166.76.94]:36914 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dmm8e-004DCm-6D; Tue, 29 Aug 2017 13:25:28 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 02/10] Use std::string thread.c Date: Tue, 29 Aug 2017 13:25:16 -0600 Message-Id: <20170829192524.29971-3-tom@tromey.com> In-Reply-To: <20170829192524.29971-1-tom@tromey.com> References: <20170829192524.29971-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dmm8e-004DCm-6D X-Source-Sender: 75-166-76-94.hlrn.qwest.net (bapiya.Home) [75.166.76.94]:36914 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes a few spots in thread.c to use std::string, removing some cleanups. ChangeLog 2017-08-29 Tom Tromey * thread.c (print_thread_info_1): Use string_printf. (thread_apply_command, thread_apply_all_command): Use std::string. --- gdb/ChangeLog | 6 ++++++ gdb/thread.c | 33 +++++++++++---------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7e3b7bf..1c4896c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2017-08-29 Tom Tromey + * thread.c (print_thread_info_1): Use string_printf. + (thread_apply_command, thread_apply_all_command): Use + std::string. + +2017-08-29 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