Use std::string in ctf_start
authorTom Tromey <tom@tromey.com>
Sat, 9 Sep 2017 16:17:11 +0000 (10:17 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 11 Sep 2017 22:15:12 +0000 (16:15 -0600)
This changes ctf_start to use std::string, allowing for some cleanup
removal.

ChangeLog
2017-09-11  Tom Tromey  <tom@tromey.com>

* ctf.c (ctf_start): Use std::string.

gdb/ChangeLog
gdb/ctf.c

index 6a5344a044b184d23d3b64a942ca48f15adc5464..6534131f347f86aa020c0dc407943984b68e8da8 100644 (file)
@@ -1,3 +1,7 @@
+2017-09-11  Tom Tromey  <tom@tromey.com>
+
+       * ctf.c (ctf_start): Use std::string.
+
 2017-09-11  Tom Tromey  <tom@tromey.com>
 
        * ada-lang.c (is_known_support_routine): Update.
index 46a1bb52c358d0fe0fab1a77d4aab91ae422addb..d719163b35ab610236fc496bc7f322c8f124d88d 100644 (file)
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -311,8 +311,6 @@ ctf_target_save (struct trace_file_writer *self,
 static void
 ctf_start (struct trace_file_writer *self, const char *dirname)
 {
-  char *file_name;
-  struct cleanup *old_chain;
   struct ctf_trace_file_writer *writer
     = (struct ctf_trace_file_writer *) self;
   int i;
@@ -325,24 +323,20 @@ ctf_start (struct trace_file_writer *self, const char *dirname)
 
   memset (&writer->tcs, '\0', sizeof (writer->tcs));
 
-  file_name = xstrprintf ("%s/%s", dirname, CTF_METADATA_NAME);
-  old_chain = make_cleanup (xfree, file_name);
+  std::string file_name = string_printf ("%s/%s", dirname, CTF_METADATA_NAME);
 
-  writer->tcs.metadata_fd = fopen (file_name, "w");
+  writer->tcs.metadata_fd = fopen (file_name.c_str (), "w");
   if (writer->tcs.metadata_fd == NULL)
     error (_("Unable to open file '%s' for saving trace data (%s)"),
-          file_name, safe_strerror (errno));
-  do_cleanups (old_chain);
+          file_name.c_str (), safe_strerror (errno));
 
   ctf_save_metadata_header (&writer->tcs);
 
-  file_name = xstrprintf ("%s/%s", dirname, CTF_DATASTREAM_NAME);
-  old_chain = make_cleanup (xfree, file_name);
-  writer->tcs.datastream_fd = fopen (file_name, "w");
+  file_name = string_printf ("%s/%s", dirname, CTF_DATASTREAM_NAME);
+  writer->tcs.datastream_fd = fopen (file_name.c_str (), "w");
   if (writer->tcs.datastream_fd == NULL)
     error (_("Unable to open file '%s' for saving trace data (%s)"),
-          file_name, safe_strerror (errno));
-  do_cleanups (old_chain);
+          file_name.c_str (), safe_strerror (errno));
 }
 
 /* This is the implementation of trace_file_write_ops method