public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 6/8] Remove cleanup from backtrace_command
Date: Fri, 13 Oct 2017 21:00:00 -0000	[thread overview]
Message-ID: <20171013205950.22943-7-tom@tromey.com> (raw)
In-Reply-To: <20171013205950.22943-1-tom@tromey.com>

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-10-13  Tom Tromey  <tom@tromey.com>

	* stack.c (backtrace_command): Use std::string.
	(backtrace_command_1): Make "count_exp" const.
---
 gdb/ChangeLog |  5 +++++
 gdb/stack.c   | 17 +++++++----------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/gdb/stack.c b/gdb/stack.c
index 4de3675bc5..63c3d837de 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
-- 
2.13.6

  parent reply	other threads:[~2017-10-13 21:00 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-13 21:00 [RFA 0/8] Constify many commands Tom Tromey
2017-10-13 21:00 ` [RFA 2/8] Constify add_com_suppress_notification Tom Tromey
2017-10-16  9:03   ` Yao Qi
2017-10-16 15:55     ` Tom Tromey
2017-10-13 21:00 ` [RFA 8/8] Constify add_com Tom Tromey
2017-10-16  9:59   ` Yao Qi
2017-10-13 21:00 ` Tom Tromey [this message]
2017-10-16  9:46   ` [RFA 6/8] Remove cleanup from backtrace_command Yao Qi
2017-10-13 21:00 ` [RFA 1/8] Constify add_abbrev_prefix_cmd Tom Tromey
2017-10-16  9:02   ` Yao Qi
2017-10-16 15:54     ` Tom Tromey
2017-10-16 20:23       ` Yao Qi
2017-10-13 21:00 ` [RFA 7/8] Add truncate_repeat_arguments function Tom Tromey
2017-10-14  4:49   ` Tom Tromey
2017-10-16  3:07     ` Tom Tromey
2017-10-16  9:53       ` Yao Qi
2017-10-18  3:48         ` Tom Tromey
2017-11-06 16:38           ` Tom Tromey
2017-11-07 14:35           ` Pedro Alves
2017-10-13 21:00 ` [RFA 5/8] Constify add_path and friends Tom Tromey
2017-10-16  9:35   ` Yao Qi
2017-10-13 21:00 ` [RFA 4/8] Make strip_bg_char return a unique_xmalloc_ptr Tom Tromey
2017-10-16  9:33   ` Yao Qi
2017-10-16 18:37     ` Simon Marchi
2017-10-17 11:05       ` Yao Qi
2017-10-18  3:32         ` Tom Tromey
2017-10-18  9:37     ` Pedro Alves
2017-11-06 16:33       ` Tom Tromey
2017-10-13 21:00 ` [RFA 3/8] Make set_cmd_cfunc private Tom Tromey
2017-10-16  9:20   ` Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171013205950.22943-7-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).