22 #include "readline/tilde.h" 30 #include "filenames.h" 77 if (writer->
fp != NULL)
91 writer->
pathname = tilde_expand (filename);
93 if (writer->
fp == NULL)
94 error (
_(
"Unable to open file '%s' for saving trace data (%s)"),
111 written = fwrite (
"\x7fTRACE0\n", 8, 1, writer->
fp);
125 fprintf (writer->
fp,
"R %x\n",
size);
138 fprintf (writer->
fp,
"status %c;%s",
143 char *buf = (
char *) alloca (strlen (ts->
stop_desc) * 2 + 1);
146 fprintf (writer->
fp,
":%s", buf);
163 fprintf (writer->
fp,
";starttime:%s",
168 fprintf (writer->
fp,
";stoptime:%s",
171 if (ts->
notes != NULL)
173 char *buf = (
char *) alloca (strlen (ts->
notes) * 2 + 1);
176 fprintf (writer->
fp,
";notes:%s", buf);
180 char *buf = (
char *) alloca (strlen (ts->
user_name) * 2 + 1);
183 fprintf (writer->
fp,
";username:%s", buf);
185 fprintf (writer->
fp,
"\n");
201 buf = (
char *)
xmalloc (strlen (utsv->
name) * 2 + 1);
205 fprintf (writer->
fp,
"tsv %x:%s:%x:%s\n",
207 utsv->
builtin, buf != NULL ? buf :
"");
213 #define MAX_TRACE_UPLOAD 2000 228 fprintf (writer->
fp,
"tp T%x:%s:%c:%x:%x",
235 ":X%x,%s", (
unsigned int) strlen (utp->
cond) / 2,
237 fprintf (writer->
fp,
"\n");
239 fprintf (writer->
fp,
"tp A%x:%s:%s\n",
242 fprintf (writer->
fp,
"tp S%x:%s:%s\n",
248 fprintf (writer->
fp,
"tp Z%s\n", buf);
255 fprintf (writer->
fp,
"tp Z%s\n", buf);
261 fprintf (writer->
fp,
"tp Z%s\n", buf);
263 fprintf (writer->
fp,
"tp V%x:%s:%x:%s\n",
285 const char *ptr = tdesc->c_str ();
290 const char *next = strchr (ptr,
'\n');
293 fprintf (writer->
fp,
"tdesc %.*s\n", (
int) (next - ptr), ptr);
297 else if (*ptr !=
'\0')
300 fprintf (writer->
fp,
"tdesc %s\n", ptr);
315 fprintf (writer->
fp,
"\n");
328 if (fwrite (buf, len, 1, writer->
fp) < 1)
343 if (fwrite (&gotten, 4, 1, writer->
fp) < 1)
387 #define TRACE_HEADER_SIZE 8 389 #define TFILE_PID (1) 418 else if (gotten <
size)
419 error (
_(
"Premature end of file while reading trace file"));
437 error (
_(
"No trace file specified."));
440 if (!IS_ABSOLUTE_PATH (filename.get ()))
447 if (scratch_chan < 0)
465 if (!(header[0] == 0x7f
467 error (
_(
"File is not a valid trace file."));
505 error (
_(
"Excessively long lines in trace file"));
517 error (
_(
"No register block size recorded in trace file"));
532 warning (
_(
"No traceframes present in this file."));
561 p += strlen (
"status ");
571 p += strlen (
"tsv ");
576 p += strlen (
"tdesc ");
580 warning (
_(
"Ignoring trace file definition \"%s\""), line);
663 int tfnum = 0, found = 0;
664 unsigned int data_size;
666 off_t
offset, tframe_offset;
719 if (addr1 <= tfaddr && tfaddr <= addr2)
724 if (!(addr1 <= tfaddr && tfaddr <= addr2))
763 char *wantedp = (
char *) data;
765 if (*wantedp == blocktype)
807 mlen = (
unsigned short)
812 pos += (8 + 2 + mlen);
819 error (
_(
"Unknown block type '%c' (0x%x) in trace frame"),
876 else if (regno == -1)
893 if (strcmp (annex,
"target.xml"))
897 error (
_(
"tfile_xfer_partial: tdesc is read-only"));
916 const char *annex,
gdb_byte *readbuf,
928 error (
_(
"tfile_xfer_partial: trace file is read-only"));
950 mlen = (
unsigned short)
959 amt = (maddr + mlen) -
offset;
971 if (low_addr_available == 0 || low_addr_available > maddr)
972 low_addr_available = maddr;
975 pos += (8 + 2 + mlen);
981 if (
offset < low_addr_available)
982 len = std::min (len, low_addr_available -
offset);
1053 unsigned short mlen;
1060 mlen = (
unsigned short)
1065 info->
memory.emplace_back (maddr, mlen);
1073 info->
tvars.push_back (vnum);
1081 warning (
_(
"Unhandled trace block type (%d) '%c ' " 1082 "while building trace frame info."),
1083 blocktype, blocktype);
1118 =
"Use a trace file as a target. Specify the filename of the trace file.";
struct gdbarch * target_gdbarch(void)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t err
static CORE_ADDR tfile_get_traceframe_address(off_t tframe_offset)
ssize_t read(int fd, void *buf, size_t count)
std::vector< mem_range > memory
static off_t trace_frames_offset
static void tfile_dtor(struct trace_file_writer *self)
void post_create_inferior(struct target_ops *target, int from_tty)
static int tfile_get_trace_state_variable_value(struct target_ops *self, int tsvnum, LONGEST *val)
int ptid_get_pid(const ptid_t &ptid)
mach_port_t mach_port_t name mach_port_t mach_port_t name kern_return_t int int rusage_t pid_t pid
static void tfile_write_uploaded_tsv(struct trace_file_writer *self, struct uploaded_tsv *utsv)
static int tfile_trace_find(struct target_ops *self, enum trace_find_type type, int num, CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
const struct trace_file_write_ops * ops
void warning(const char *fmt,...)
static void tfile_append_tdesc_line(const char *line)
void push_target(struct target_ops *t)
int bin2hex(const gdb_byte *bin, char *hex, int count)
void buffer_free(struct buffer *buffer)
static void tfile_close(struct target_ops *self)
int unpush_target(struct target_ops *t)
void internal_error(const char *file, int line, const char *fmt,...)
void(* to_close)(struct target_ops *)
static int match_blocktype(char blocktype, void *data)
void filename_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
static void tfile_write_regblock_type(struct trace_file_writer *self, int size)
const breakpoint_ops * ops
int gdbarch_num_regs(struct gdbarch *gdbarch)
struct tracepoint * get_tracepoint(int num)
ULONGEST traceframe_usage
static void tfile_read(gdb_byte *readbuf, int size)
static struct buffer trace_tdesc
int(* to_get_trace_state_variable_value)(struct target_ops *, int tsv, LONGEST *val) TARGET_DEFAULT_RETURN(0)
void printf_filtered(const char *format,...)
void(* to_files_info)(struct target_ops *) TARGET_DEFAULT_IGNORE()
struct trace_status * current_trace_status(void)
mach_port_t kern_return_t mach_port_t msgports mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
static void tfile_files_info(struct target_ops *t)
static void tfile_get_tracepoint_status(struct target_ops *self, struct breakpoint *tp, struct uploaded_tp *utp)
#define VEC_iterate(T, V, I, P)
struct tracepoint * get_tracepoint_by_number_on_target(int num)
#define CATCH(EXCEPTION, MASK)
void merge_uploaded_tracepoints(struct uploaded_tp **uploaded_tps)
static struct target_ops tfile_ops
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
static void tfile_write_definition_end(struct trace_file_writer *self)
struct target_ops current_target
int(* to_trace_find)(struct target_ops *, enum trace_find_type type, int num, CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) TARGET_DEFAULT_RETURN(-1)
void merge_uploaded_trace_state_variables(struct uploaded_tsv **uploaded_tsvs)
struct trace_file_writer base
static enum target_xfer_status tfile_xfer_partial_features(struct target_ops *ops, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
static ULONGEST extract_unsigned_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
static void tfile_interp_line(char *line, struct uploaded_tp **utpp, struct uploaded_tsv **utsvp)
static int tfile_target_save(struct trace_file_writer *self, const char *filename)
#define target_save_trace_data(filename)
void trace_reset_local_state(void)
enum trace_stop_reason stop_reason
ptid_t pid_to_ptid(int pid)
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
void init_tracefile_ops(struct target_ops *ops)
int get_traceframe_number(void)
void parse_trace_status(const char *line, struct trace_status *ts)
void add_target_with_completer(struct target_ops *t, completer_ftype *completer)
void _initialize_tracefile_tfile(void)
enum target_xfer_status exec_read_partial_read_only(gdb_byte *readbuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
static void tfile_write_tdesc(struct trace_file_writer *self)
static void tfile_fetch_registers(struct target_ops *ops, struct regcache *regcache, int regno)
void(* to_get_tracepoint_status)(struct target_ops *, struct breakpoint *tp, struct uploaded_tp *utp) TARGET_DEFAULT_NORETURN(tcomplain())
gdb_file_up gdb_fopen_cloexec(const char *filename, const char *opentype)
static void tfile_open(const char *arg, int from_tty)
static int startswith(const char *string, const char *pattern)
struct thread_info * add_thread_silent(ptid_t ptid)
enum target_xfer_status(* to_xfer_partial)(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) TARGET_DEFAULT_RETURN(TARGET_XFER_E_IO)
static void tfile_write_header(struct trace_file_writer *self)
traceframe_info_up(* to_traceframe_info)(struct target_ops *) TARGET_DEFAULT_NORETURN(tcomplain())
#define buffer_grow_str(BUFFER, STRING)
static void tfile_write_uploaded_tp(struct trace_file_writer *self, struct uploaded_tp *utp)
const char * stop_reason_names[]
enum target_xfer_status section_table_read_available_memory(gdb_byte *readbuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
static int traceframe_find_block_type(char type_wanted, int pos)
static void tfile_end(struct trace_file_writer *self)
gdb::optional< std::string > target_fetch_description_xml(struct target_ops *ops)
int(* walk_blocks_callback_func)(char blocktype, void *data)
void throw_exception(struct gdb_exception exception)
static void init_tfile_ops(void)
std::unique_ptr< traceframe_info > traceframe_info_up
void tracefile_fetch_registers(struct regcache *regcache, int regno)
void(* to_fetch_registers)(struct target_ops *, struct regcache *, int) TARGET_DEFAULT_IGNORE()
static enum target_xfer_status tfile_xfer_partial(struct target_ops *ops, enum target_object object, const char *annex, gdb_byte *readbuf, const gdb_byte *writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
char * phex_nz(ULONGEST l, int sizeof_l)
void void void void void void void void void perror_with_name(const char *string) ATTRIBUTE_NORETURN
int encode_source_string(int tpnum, ULONGEST addr, const char *srctype, const char *src, char *buf, int buf_size)
enum register_status regcache_register_status(const struct regcache *regcache, int regnum)
char * safe_strerror(int)
static const struct trace_file_write_ops tfile_write_ops
void(* to_open)(const char *, int)
void parse_tsv_definition(const char *line, struct uploaded_tsv **utsvp)
static LONGEST extract_signed_integer(const gdb_byte *addr, int len, enum bfd_endian byte_order)
static int build_traceframe_info(char blocktype, void *data)
static void tfile_start(struct trace_file_writer *self, const char *filename)
int gdb_open_cloexec(const char *filename, int flags, unsigned long mode)
static char * trace_filename
struct inferior * current_inferior(void)
void regcache_raw_supply(struct regcache *regcache, int regnum, const void *buf)
const char * to_shortname
unsigned long long ULONGEST
void exit_inferior_silent(int pid)
int register_size(struct gdbarch *gdbarch, int regnum)
static traceframe_info_up tfile_traceframe_info(struct target_ops *self)
int remote_register_number_and_offset(struct gdbarch *gdbarch, int regnum, int *pnum, int *poffset)
struct trace_file_writer * tfile_trace_file_writer_new(void)
void target_preopen(int from_tty)
void target_find_description(void)
enum bfd_endian byte_order
void error(const char *fmt,...)
void parse_tracepoint_definition(const char *line, struct uploaded_tp **utpp)
static int traceframe_walk_blocks(walk_blocks_callback_func callback, int pos, void *data)
static void tfile_write_raw_data(struct trace_file_writer *self, gdb_byte *buf, LONGEST len)
void inferior_appeared(struct inferior *inf, int pid)
static void tfile_write_status(struct trace_file_writer *self, struct trace_status *ts)
#define TRACE_HEADER_SIZE