From patchwork Wed Oct 19 01:12:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 16638 Received: (qmail 124389 invoked by alias); 19 Oct 2016 01:12:39 -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 124249 invoked by uid 89); 19 Oct 2016 01:12:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=oo, *result, OO, CATCH X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 19 Oct 2016 01:12:35 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42FEA8AE73 for ; Wed, 19 Oct 2016 01:12:34 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9J1CJjk019701 for ; Tue, 18 Oct 2016 21:12:33 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 15/31] Use ui_file_as_string in execute_command_to_string Date: Wed, 19 Oct 2016 02:12:03 +0100 Message-Id: <1476839539-8374-16-git-send-email-palves@redhat.com> In-Reply-To: <1476839539-8374-1-git-send-email-palves@redhat.com> References: <1476839539-8374-1-git-send-email-palves@redhat.com> ... and then return std::string and adjust all callers. gdb/ChangeLog: yyyy-mm-yy Pedro Alves * gdbcmd.h (execute_command_to_string): Now returns std::string. (lookup_struct_elt_type): Adjust to use std::string. * top.c (execute_command_to_string): Use ui_file_as_string and return std::string. * guile/guile.c (gdbscm_execute_gdb_command): Adjust to use std::string. * python/python.c (execute_gdb_command): Adjust to use std::string. --- gdb/gdbcmd.h | 2 +- gdb/guile/guile.c | 18 ++++++------------ gdb/python/python.c | 19 ++++++------------- gdb/top.c | 5 ++--- 4 files changed, 15 insertions(+), 29 deletions(-) diff --git a/gdb/gdbcmd.h b/gdb/gdbcmd.h index 512b72c..6db49e2 100644 --- a/gdb/gdbcmd.h +++ b/gdb/gdbcmd.h @@ -128,7 +128,7 @@ extern struct cmd_list_element *showchecklist; extern struct cmd_list_element *save_cmdlist; extern void execute_command (char *, int); -extern char *execute_command_to_string (char *p, int from_tty); +extern std::string execute_command_to_string (char *p, int from_tty); enum command_control_type execute_control_command (struct command_line *); diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c index 3a19eec..9a126a1 100644 --- a/gdb/guile/guile.c +++ b/gdb/guile/guile.c @@ -311,7 +311,6 @@ gdbscm_execute_gdb_command (SCM command_scm, SCM rest) int from_tty = 0, to_string = 0; const SCM keywords[] = { from_tty_keyword, to_string_keyword, SCM_BOOL_F }; char *command; - char *result = NULL; struct cleanup *cleanups; struct gdb_exception except = exception_none; @@ -324,6 +323,8 @@ gdbscm_execute_gdb_command (SCM command_scm, SCM rest) executed. */ cleanups = make_cleanup (xfree, command); + std::string to_string_res; + TRY { struct cleanup *inner_cleanups; @@ -333,12 +334,9 @@ gdbscm_execute_gdb_command (SCM command_scm, SCM rest) prevent_dont_repeat (); if (to_string) - result = execute_command_to_string (command, from_tty); + to_string_res = execute_command_to_string (command, from_tty); else - { - execute_command (command, from_tty); - result = NULL; - } + execute_command (command, from_tty); /* Do any commands attached to breakpoint we stopped at. */ bpstat_do_actions (); @@ -354,12 +352,8 @@ gdbscm_execute_gdb_command (SCM command_scm, SCM rest) do_cleanups (cleanups); GDBSCM_HANDLE_GDB_EXCEPTION (except); - if (result) - { - SCM r = gdbscm_scm_from_c_string (result); - xfree (result); - return r; - } + if (to_string) + return gdbscm_scm_from_c_string (to_string_res.c_str ()); return SCM_UNSPECIFIED; } diff --git a/gdb/python/python.c b/gdb/python/python.c index 7e34d26..0ca7d9a 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -619,7 +619,6 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) PyObject *from_tty_obj = NULL, *to_string_obj = NULL; int from_tty, to_string; static char *keywords[] = {"command", "from_tty", "to_string", NULL }; - char *result = NULL; if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!O!", keywords, &arg, &PyBool_Type, &from_tty_obj, @@ -644,6 +643,8 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) to_string = cmp; } + std::string to_string_res; + TRY { /* Copy the argument text in case the command modifies it. */ @@ -663,13 +664,9 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) prevent_dont_repeat (); if (to_string) - result = execute_command_to_string (copy, from_tty); + to_string_res = execute_command_to_string (copy, from_tty); else - { - result = NULL; - execute_command (copy, from_tty); - } - + execute_command (copy, from_tty); do_cleanups (cleanup); } CATCH (except, RETURN_MASK_ALL) @@ -681,12 +678,8 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) /* Do any commands attached to breakpoint we stopped at. */ bpstat_do_actions (); - if (result) - { - PyObject *r = PyString_FromString (result); - xfree (result); - return r; - } + if (to_string) + return PyString_FromString (to_string_res.c_str ()); Py_RETURN_NONE; } diff --git a/gdb/top.c b/gdb/top.c index 3cfa113..762a9a8 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -690,12 +690,11 @@ execute_command (char *p, int from_tty) returned string, do not display it to the screen. BATCH_FLAG will be temporarily set to true. */ -char * +std::string execute_command_to_string (char *p, int from_tty) { struct ui_file *str_file; struct cleanup *cleanup; - char *retval; /* GDB_STDOUT should be better already restored during these restoration callbacks. */ @@ -726,7 +725,7 @@ execute_command_to_string (char *p, int from_tty) execute_command (p, from_tty); - retval = ui_file_xstrdup (str_file, NULL); + std::string retval = ui_file_as_string (str_file); do_cleanups (cleanup);