/* Trace file TFILE format support in GDB.
- Copyright (C) 1997-2019 Free Software Foundation, Inc.
+ Copyright (C) 1997-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "regcache.h"
#include "inferior.h"
#include "gdbthread.h"
-#include "exec.h" /* exec_bfd */
+#include "exec.h"
#include "completer.h"
#include "filenames.h"
#include "remote.h"
#include "xml-tdesc.h"
#include "target-descriptions.h"
#include "gdbsupport/buffer.h"
+#include "gdbsupport/pathstuff.h"
#include <algorithm>
#ifndef O_LARGEFILE
static const target_info tfile_target_info = {
"tfile",
N_("Local trace dump file"),
- N_("Use a trace file as a target. Specify the filename of the trace file.")
+ N_("Use a trace file as a target.\n\
+Specify the filename of the trace file.")
};
class tfile_target final : public tracefile_target
= (struct tfile_trace_file_writer *) self;
gdb::optional<std::string> tdesc
- = target_fetch_description_xml (current_top_target ());
+ = target_fetch_description_xml (current_inferior ()->top_target ());
if (!tdesc)
return;
gdb::unique_xmalloc_ptr<char> filename (tilde_expand (arg));
if (!IS_ABSOLUTE_PATH (filename.get ()))
- filename.reset (concat (current_directory, "/", filename.get (),
- (char *) NULL));
+ filename = gdb_abspath (filename.get ());
flags = O_BINARY | O_LARGEFILE;
flags |= O_RDONLY;
- scratch_chan = gdb_open_cloexec (filename.get (), flags, 0);
+ scratch_chan = gdb_open_cloexec (filename.get (), flags, 0).release ();
if (scratch_chan < 0)
perror_with_name (filename.get ());
/* Looks semi-reasonable. Toss the old trace file and work on the new. */
- unpush_target (&tfile_ops);
+ current_inferior ()->unpush_target (&tfile_ops);
trace_filename = filename.release ();
trace_fd = scratch_chan;
&& (startswith (header + 1, "TRACE0\n"))))
error (_("File is not a valid trace file."));
- push_target (&tfile_ops);
+ current_inferior ()->push_target (&tfile_ops);
trace_regblock_size = 0;
ts = current_trace_status ();
catch (const gdb_exception &ex)
{
/* Remove the partially set up target. */
- unpush_target (&tfile_ops);
+ current_inferior ()->unpush_target (&tfile_ops);
throw;
}
inferior_appeared (current_inferior (), TFILE_PID);
- inferior_ptid = ptid_t (TFILE_PID);
- add_thread_silent (inferior_ptid);
+
+ thread_info *thr = add_thread_silent (&tfile_ops, ptid_t (TFILE_PID));
+ switch_to_thread (thr);
if (ts->traceframe_count <= 0)
warning (_("No traceframes present in this file."));
merge_uploaded_tracepoints (&uploaded_tps);
- post_create_inferior (&tfile_ops, from_tty);
+ post_create_inferior (from_tty);
}
/* Interpret the given line from the definitions part of the trace
void
tfile_target::close ()
{
- if (trace_fd < 0)
- return;
+ gdb_assert (trace_fd != -1);
- inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */
+ switch_to_no_thread (); /* Avoid confusion from thread stuff. */
exit_inferior_silent (current_inferior ());
::close (trace_fd);
if (num == -1)
{
if (tpp)
- *tpp = -1;
+ *tpp = -1;
return -1;
}
break;
tfile_read ((gdb_byte *) &data_size, 4);
data_size = (unsigned int) extract_unsigned_integer
- ((gdb_byte *) &data_size, 4,
+ ((gdb_byte *) &data_size, 4,
gdbarch_byte_order (target_gdbarch ()));
offset += 4;
case 'M':
lseek (trace_fd, cur_offset + pos + 8, SEEK_SET);
tfile_read ((gdb_byte *) &mlen, 2);
- mlen = (unsigned short)
- extract_unsigned_integer ((gdb_byte *) &mlen, 2,
- gdbarch_byte_order
- (target_gdbarch ()));
+ mlen = (unsigned short)
+ extract_unsigned_integer ((gdb_byte *) &mlen, 2,
+ gdbarch_byte_order
+ (target_gdbarch ()));
lseek (trace_fd, mlen, SEEK_CUR);
pos += (8 + 2 + mlen);
break;
amt = len;
if (maddr != offset)
- lseek (trace_fd, offset - maddr, SEEK_CUR);
+ lseek (trace_fd, offset - maddr, SEEK_CUR);
tfile_read (readbuf, amt);
*xfered_len = amt;
return TARGET_XFER_OK;
buffer_grow_str (&trace_tdesc, "\n");
}
+void _initialize_tracefile_tfile ();
void
-_initialize_tracefile_tfile (void)
+_initialize_tracefile_tfile ()
{
add_target (tfile_target_info, tfile_target_open, filename_completer);
}