Use ui_file_as_string in execute_command_to_string
authorPedro Alves <palves@redhat.com>
Tue, 8 Nov 2016 15:26:45 +0000 (15:26 +0000)
committerPedro Alves <palves@redhat.com>
Tue, 8 Nov 2016 15:26:45 +0000 (15:26 +0000)
... and then return std::string and adjust all callers.

gdb/ChangeLog:
2016-11-08  Pedro Alves  <palves@redhat.com>

* 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/ChangeLog
gdb/gdbcmd.h
gdb/guile/guile.c
gdb/python/python.c
gdb/top.c

index f88e50595b4d735fa897a70cf47486f62ea18c54..68f8cf0d494e3a6a181c6aabbf9946066374da53 100644 (file)
@@ -1,3 +1,14 @@
+2016-11-08  Pedro Alves  <palves@redhat.com>
+
+       * 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.
+
 2016-11-08  Pedro Alves  <palves@redhat.com>
 
        * guile/scm-breakpoint.c (gdbscm_breakpoint_commands): Use
index 512b72ca10be6a0e3f9cd0b0ebe2123cb6859146..6db49e224a20a70169f0c0d20c15f8110443c386 100644 (file)
@@ -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 *);
 
index 3a19eecc2a7c95e49ad4121e9f51360ac2784024..9a126a1fb1ae882d1d39f5098c49792c3cfc52bd 100644 (file)
@@ -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;
 }
 
index d6bd6bf4a7afd7ba4455e4793884c028885e577a..d9940c2cdf9be3d81bdb70635b8874390c406828 100644 (file)
@@ -614,7 +614,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,
@@ -639,6 +638,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.  */
@@ -657,13 +658,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)
@@ -675,12 +672,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;
 }
 
index c7a9c21634a7013a10db86737a01af4a99e87e02..504a4dede1230bfd3e49ba93963ea4d608b6cbf0 100644 (file)
--- 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.  */
@@ -725,7 +724,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);
 
This page took 0.030348 seconds and 4 git commands to generate.