This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Remove cleanup from backtrace_command


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=022643b4456ee13752b0f3a8411238ab8c53bf6d

commit 022643b4456ee13752b0f3a8411238ab8c53bf6d
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Oct 12 08:08:00 2017 -0600

    Remove cleanup from backtrace_command
    
    This removes a cleanup from backtrace_command, replacing it with
    std::string.  This patch temporarily changes backtrace_command so that
    the parameter is named "args_in" and is immediately constified; this
    is fixed again in the constification patch.
    
    gdb/ChangeLog
    2017-11-07  Tom Tromey  <tom@tromey.com>
    
    	* stack.c (backtrace_command): Use std::string.
    	(backtrace_command_1): Make "count_exp" const.

Diff:
---
 gdb/ChangeLog |  5 +++++
 gdb/stack.c   | 17 +++++++----------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d8d956f..ce8110f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2017-11-07  Tom Tromey  <tom@tromey.com>
 
+	* stack.c (backtrace_command): Use std::string.
+	(backtrace_command_1): Make "count_exp" const.
+
+2017-11-07  Tom Tromey  <tom@tromey.com>
+
 	* source.c (directory_switch, mod_path, add_path): Constify.
 	* defs.h (add_path, mod_path, directory_switch): Constify.
 	* mi/mi-cmd-env.c (env_mod_path): Constify.
diff --git a/gdb/stack.c b/gdb/stack.c
index 24fad3c..6256bbe 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1692,7 +1692,7 @@ info_frame_command (char *addr_exp, int from_tty)
    frames.  */
 
 static void
-backtrace_command_1 (char *count_exp, int show_locals, int no_filters,
+backtrace_command_1 (const char *count_exp, int show_locals, int no_filters,
 		     int from_tty)
 {
   struct frame_info *fi;
@@ -1844,12 +1844,13 @@ backtrace_command_1 (char *count_exp, int show_locals, int no_filters,
 }
 
 static void
-backtrace_command (char *arg, int from_tty)
+backtrace_command (char *arg_in, int from_tty)
 {
-  struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   int fulltrace_arg = -1, arglen = 0, argc = 0, no_filters  = -1;
   int user_arg = 0;
+  const char *arg = arg_in;
 
+  std::string reconstructed_arg;
   if (arg)
     {
       char **argv;
@@ -1884,17 +1885,15 @@ backtrace_command (char *arg, int from_tty)
 	{
 	  if (arglen > 0)
 	    {
-	      arg = (char *) xmalloc (arglen + 1);
-	      make_cleanup (xfree, arg);
-	      arg[0] = 0;
 	      for (i = 0; i < argc; i++)
 		{
 		  if (i != fulltrace_arg && i != no_filters)
 		    {
-		      strcat (arg, argv[i]);
-		      strcat (arg, " ");
+		      reconstructed_arg += argv[i];
+		      reconstructed_arg += " ";
 		    }
 		}
+	      arg = reconstructed_arg.c_str ();
 	    }
 	  else
 	    arg = NULL;
@@ -1903,8 +1902,6 @@ backtrace_command (char *arg, int from_tty)
 
   backtrace_command_1 (arg, fulltrace_arg >= 0 /* show_locals */,
 		       no_filters >= 0 /* no frame-filters */, from_tty);
-
-  do_cleanups (old_chain);
 }
 
 /* Iterate over the local variables of a block B, calling CB with


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]