Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 07/12] Remove some cleanups from tracepoint.c
Date: Thu, 28 Sep 2017 20:11:00 -0000	[thread overview]
Message-ID: <20170928195011.27382-8-tom@tromey.com> (raw)
In-Reply-To: <20170928195011.27382-1-tom@tromey.com>

This removes some cleanups from tracepoint.c by using std::string.  It
also removes some unused cleanup declarations.

gdb/ChangeLog
2017-09-28  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (trace_variable_command): Use std::string.
	(encode_actions_1): Remove unused declarations.
	(create_tsv_from_upload): Use std::string.
---
 gdb/ChangeLog    |  6 ++++++
 gdb/tracepoint.c | 42 ++++++++++++------------------------------
 2 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 30e3a3a..daa55f6 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -371,10 +371,9 @@ validate_trace_state_variable_name (const char *name)
 static void
 trace_variable_command (char *args, int from_tty)
 {
-  struct cleanup *old_chain;
   LONGEST initval = 0;
   struct trace_state_variable *tsv;
-  char *name, *p;
+  char *name_start, *p;
 
   if (!args || !*args)
     error_no_arg (_("Syntax is $NAME [ = EXPR ]"));
@@ -385,23 +384,22 @@ trace_variable_command (char *args, int from_tty)
   if (*p++ != '$')
     error (_("Name of trace variable should start with '$'"));
 
-  name = p;
+  name_start = p;
   while (isalnum (*p) || *p == '_')
     p++;
-  name = savestring (name, p - name);
-  old_chain = make_cleanup (xfree, name);
+  std::string name (name_start, p - name_start);
 
   p = skip_spaces (p);
   if (*p != '=' && *p != '\0')
     error (_("Syntax must be $NAME [ = EXPR ]"));
 
-  validate_trace_state_variable_name (name);
+  validate_trace_state_variable_name (name.c_str ());
 
   if (*p == '=')
     initval = value_as_long (parse_and_eval (++p));
 
   /* If the variable already exists, just change its initial value.  */
-  tsv = find_trace_state_variable (name);
+  tsv = find_trace_state_variable (name.c_str ());
   if (tsv)
     {
       if (tsv->initial_value != initval)
@@ -412,12 +410,11 @@ trace_variable_command (char *args, int from_tty)
       printf_filtered (_("Trace state variable $%s "
 			 "now has initial value %s.\n"),
 		       tsv->name, plongest (tsv->initial_value));
-      do_cleanups (old_chain);
       return;
     }
 
   /* Create a new variable.  */
-  tsv = create_trace_state_variable (name);
+  tsv = create_trace_state_variable (name.c_str ());
   tsv->initial_value = initval;
 
   observer_notify_tsv_created (tsv);
@@ -425,8 +422,6 @@ trace_variable_command (char *args, int from_tty)
   printf_filtered (_("Trace state variable $%s "
 		     "created, with initial value %s.\n"),
 		   tsv->name, plongest (tsv->initial_value));
-
-  do_cleanups (old_chain);
 }
 
 static void
@@ -663,7 +658,6 @@ void
 validate_actionline (const char *line, struct breakpoint *b)
 {
   struct cmd_list_element *c;
-  struct cleanup *old_chain = NULL;
   const char *tmp_p;
   const char *p;
   struct bp_location *loc;
@@ -999,8 +993,6 @@ collection_list::collect_symbol (struct symbol *sym,
   /* Expressions are the most general case.  */
   if (treat_as_expr)
     {
-      struct cleanup *old_chain1 = NULL;
-
       agent_expr_up aexpr = gen_trace_for_var (scope, gdbarch,
 					       sym, trace_string);
 
@@ -1383,7 +1375,6 @@ encode_actions_1 (struct command_line *action,
 	      else
 		{
 		  unsigned long addr;
-		  struct cleanup *old_chain1 = NULL;
 
 		  expression_up exp = parse_exp_1 (&action_exp, tloc->address,
 						   block_for_pc (tloc->address),
@@ -1478,8 +1469,6 @@ encode_actions_1 (struct command_line *action,
 	      action_exp = skip_spaces (action_exp);
 
 		{
-		  struct cleanup *old_chain1 = NULL;
-
 		  expression_up exp = parse_exp_1 (&action_exp, tloc->address,
 						   block_for_pc (tloc->address),
 						   1);
@@ -3310,7 +3299,7 @@ static struct trace_state_variable *
 create_tsv_from_upload (struct uploaded_tsv *utsv)
 {
   const char *namebase;
-  char *buf;
+  std::string buf;
   int try_num = 0;
   struct trace_state_variable *tsv;
   struct cleanup *old_chain;
@@ -3318,33 +3307,26 @@ create_tsv_from_upload (struct uploaded_tsv *utsv)
   if (utsv->name)
     {
       namebase = utsv->name;
-      buf = xstrprintf ("%s", namebase);
+      buf = namebase;
     }
   else
     {
       namebase = "__tsv";
-      buf = xstrprintf ("%s_%d", namebase, try_num++);
+      buf = string_printf ("%s_%d", namebase, try_num++);
     }
 
   /* Fish for a name that is not in use.  */
   /* (should check against all internal vars?)  */
-  while (find_trace_state_variable (buf))
-    {
-      xfree (buf);
-      buf = xstrprintf ("%s_%d", namebase, try_num++);
-    }
-
-  old_chain = make_cleanup (xfree, buf);
+  while (find_trace_state_variable (buf.c_str ()))
+    buf = string_printf ("%s_%d", namebase, try_num++);
 
   /* We have an available name, create the variable.  */
-  tsv = create_trace_state_variable (buf);
+  tsv = create_trace_state_variable (buf.c_str ());
   tsv->initial_value = utsv->initial_value;
   tsv->builtin = utsv->builtin;
 
   observer_notify_tsv_created (tsv);
 
-  do_cleanups (old_chain);
-
   return tsv;
 }
 
-- 
2.9.5


  parent reply	other threads:[~2017-09-28 20:11 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-28 19:50 [RFA 00/12] some minor cleanup removals Tom Tromey
2017-09-28 19:50 ` [RFA 02/12] Remove cleanup from display_gdb_prompt Tom Tromey
2017-09-28 21:56   ` Pedro Alves
2017-09-28 19:50 ` [RFA 11/12] Remove a cleanup from symtab.c Tom Tromey
2017-09-28 19:50 ` [RFA 09/12] Remove cleanup from xstormy16-tdep.c Tom Tromey
2017-09-28 19:50 ` [RFA 04/12] Remove cleanup from tilegx-tdep.c Tom Tromey
2017-09-28 22:00   ` Pedro Alves
2017-09-28 19:50 ` [RFA 06/12] Remove cleanups from cp-support.c Tom Tromey
2017-09-28 19:50 ` [RFA 05/12] Remove some cleanups from stack.c Tom Tromey
2017-09-28 22:06   ` Pedro Alves
2017-09-28 19:50 ` [RFA 03/12] Remove cleanups from utils.c Tom Tromey
2017-09-28 22:00   ` Pedro Alves
2017-09-28 19:50 ` [RFA 10/12] Remove cleanup from mt-tdep.c Tom Tromey
2017-09-28 19:50 ` [RFA 01/12] Introduce string_vprintf Tom Tromey
2017-09-28 21:53   ` Pedro Alves
2017-09-29  2:38     ` Tom Tromey
2017-09-29  3:00       ` Tom Tromey
2017-09-29 10:25         ` Pedro Alves
2017-09-28 19:50 ` [RFA 08/12] Remove cleanup from complaints.c Tom Tromey
2017-09-28 22:09   ` Pedro Alves
2017-09-28 19:50 ` [RFA 12/12] Remove some unused declarations Tom Tromey
2017-09-28 20:11 ` Tom Tromey [this message]
2017-09-28 21:04 ` [RFA 00/12] some minor cleanup removals Sergio Durigan Junior
2017-09-28 22:11   ` Pedro Alves

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=20170928195011.27382-8-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