From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/8] Use unique_ptr for trace_filename
Date: Sun, 09 Jul 2023 11:01:49 -0600 [thread overview]
Message-ID: <20230709-trace-cleanups-v1-3-c410e1072fab@tromey.com> (raw)
In-Reply-To: <20230709-trace-cleanups-v1-0-c410e1072fab@tromey.com>
This changes trace_filename to use unique_ptr, removing some manual
memory management.
---
gdb/tracefile-tfile.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index ff451c79e88..364f8c1f08e 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -415,7 +415,7 @@ static tfile_target tfile_ops;
#define TFILE_PID (1)
-static char *trace_filename;
+static gdb::unique_xmalloc_ptr<char> trace_filename;
static int trace_fd = -1;
static off_t trace_frames_offset;
static off_t cur_offset;
@@ -441,7 +441,7 @@ tfile_read (gdb_byte *readbuf, int size)
gotten = read (trace_fd, readbuf, size);
if (gotten < 0)
- perror_with_name (trace_filename);
+ perror_with_name (trace_filename.get ());
else if (gotten < size)
error (_("Premature end of file while reading trace file"));
}
@@ -479,7 +479,7 @@ tfile_target_open (const char *arg, int from_tty)
current_inferior ()->unpush_target (&tfile_ops);
- trace_filename = filename.release ();
+ trace_filename = std::move (filename);
trace_fd = scratch_chan;
/* Make sure this is clear. */
@@ -499,7 +499,7 @@ tfile_target_open (const char *arg, int from_tty)
trace_regblock_size = 0;
ts = current_trace_status ();
/* We know we're working with a file. Record its name. */
- ts->filename = trace_filename;
+ ts->filename = trace_filename.get ();
/* Set defaults in case there is no status line. */
ts->running_known = 0;
ts->stop_reason = trace_stop_reason_unknown;
@@ -620,8 +620,7 @@ tfile_target::close ()
::close (trace_fd);
trace_fd = -1;
- xfree (trace_filename);
- trace_filename = NULL;
+ trace_filename.reset ();
trace_tdesc.clear ();
trace_reset_local_state ();
@@ -630,7 +629,7 @@ tfile_target::close ()
void
tfile_target::files_info ()
{
- gdb_printf ("\t`%s'\n", trace_filename);
+ gdb_printf ("\t`%s'\n", trace_filename.get ());
}
void
--
2.41.0
next prev parent reply other threads:[~2023-07-09 17:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-09 17:01 [PATCH 0/8] Minor C++-ification and cleanup in trace targets Tom Tromey
2023-07-09 17:01 ` [PATCH 1/8] Remove a use of xfree Tom Tromey
2023-07-09 17:01 ` [PATCH 2/8] Replace use of xfree with byte_vector Tom Tromey
2023-07-09 17:01 ` Tom Tromey [this message]
2023-07-09 17:01 ` [PATCH 4/8] Use unique_ptr for trace_dirname Tom Tromey
2023-07-09 17:01 ` [PATCH 5/8] Use function_view in traceframe_walk_blocks Tom Tromey
2023-07-09 17:01 ` [PATCH 6/8] Constify tfile_interp_line Tom Tromey
2023-07-09 17:01 ` [PATCH 7/8] Move definition of ctf_target type Tom Tromey
2023-07-09 17:01 ` [PATCH 8/8] Change 'handle_id' to be a local variable Tom Tromey
2023-07-09 20:52 ` [PATCH 0/8] Minor C++-ification and cleanup in trace targets Keith Seitz
2023-07-10 19:02 ` Tom Tromey
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=20230709-trace-cleanups-v1-3-c410e1072fab@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).