[RFA] Remove a cleanup from trace_dump_actions

Message ID 20180519151757.18031-1-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey May 19, 2018, 3:17 p.m. UTC
  This changes trace_dump_actions to use std::string, removing a
cleanup.

Tested by the buildbot.

gdb/ChangeLog
2018-05-19  Tom Tromey  <tom@tromey.com>

	* tracepoint.c (trace_dump_actions): Use std::string.
---
 gdb/ChangeLog    |  4 ++++
 gdb/tracepoint.c | 20 ++++----------------
 2 files changed, 8 insertions(+), 16 deletions(-)
  

Comments

Simon Marchi May 20, 2018, 11:44 p.m. UTC | #1
On 2018-05-19 11:17 AM, Tom Tromey wrote:
> This changes trace_dump_actions to use std::string, removing a
> cleanup.

LGTM, but I would suggest finding another name for cmd, to avoid
shadowing the other cmd variable.

Simon
  
Tom Tromey May 21, 2018, 3:52 p.m. UTC | #2
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

Simon> On 2018-05-19 11:17 AM, Tom Tromey wrote:
>> This changes trace_dump_actions to use std::string, removing a
>> cleanup.

Simon> LGTM, but I would suggest finding another name for cmd, to avoid
Simon> shadowing the other cmd variable.

I renamed it to "exp", since it is an expression, not a command.

Tom
  

Patch

diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index e170d704bc..d83af78dd5 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -2679,9 +2679,6 @@  trace_dump_actions (struct command_line *action,
 	     STEPPING_ACTIONS should be equal.  */
 	  if (stepping_frame == stepping_actions)
 	    {
-	      char *cmd = NULL;
-	      struct cleanup *old_chain
-		= make_cleanup (free_current_contents, &cmd);
 	      int trace_string = 0;
 
 	      if (*action_exp == '/')
@@ -2706,20 +2703,13 @@  trace_dump_actions (struct command_line *action,
 		    info_args_command (NULL, from_tty);
 		  else
 		    {		/* variable */
+		      std::string contents;
+		      const char *cmd = action_exp;
 		      if (next_comma != NULL)
 			{
 			  size_t len = next_comma - action_exp;
-
-			  cmd = (char *) xrealloc (cmd, len + 1);
-			  memcpy (cmd, action_exp, len);
-			  cmd[len] = 0;
-			}
-		      else
-			{
-			  size_t len = strlen (action_exp);
-
-			  cmd = (char *) xrealloc (cmd, len + 1);
-			  memcpy (cmd, action_exp, len + 1);
+			  contents = std::string (action_exp, len);
+			  cmd = contents.c_str ();
 			}
 
 		      printf_filtered ("%s = ", cmd);
@@ -2729,8 +2719,6 @@  trace_dump_actions (struct command_line *action,
 		  action_exp = next_comma;
 		}
 	      while (action_exp && *action_exp == ',');
-
-	      do_cleanups (old_chain);
 	    }
 	}
     }