22 #include "readline/tilde.h"
30 #include "filenames.h"
72 if (writer->
fp != NULL)
86 writer->
pathname = tilde_expand (filename);
88 if (writer->
fp == NULL)
89 error (
_(
"Unable to open file '%s' for saving trace data (%s)"),
106 written = fwrite (
"\x7fTRACE0\n", 8, 1, writer->
fp);
120 fprintf (writer->
fp,
"R %x\n", size);
133 fprintf (writer->
fp,
"status %c;%s",
138 char *buf = (
char *) alloca (strlen (ts->
stop_desc) * 2 + 1);
141 fprintf (writer->
fp,
":%s", buf);
158 fprintf (writer->
fp,
";starttime:%s",
163 fprintf (writer->
fp,
";stoptime:%s",
166 if (ts->
notes != NULL)
168 char *buf = (
char *) alloca (strlen (ts->
notes) * 2 + 1);
171 fprintf (writer->
fp,
";notes:%s", buf);
175 char *buf = (
char *) alloca (strlen (ts->
user_name) * 2 + 1);
178 fprintf (writer->
fp,
";username:%s", buf);
180 fprintf (writer->
fp,
"\n");
196 buf = (
char *)
xmalloc (strlen (utsv->
name) * 2 + 1);
200 fprintf (writer->
fp,
"tsv %x:%s:%x:%s\n",
208 #define MAX_TRACE_UPLOAD 2000
223 fprintf (writer->
fp,
"tp T%x:%s:%c:%x:%x",
230 ":X%x,%s", (
unsigned int) strlen (utp->
cond) / 2,
232 fprintf (writer->
fp,
"\n");
234 fprintf (writer->
fp,
"tp A%x:%s:%s\n",
237 fprintf (writer->
fp,
"tp S%x:%s:%s\n",
243 fprintf (writer->
fp,
"tp Z%s\n", buf);
250 fprintf (writer->
fp,
"tp Z%s\n", buf);
256 fprintf (writer->
fp,
"tp Z%s\n", buf);
258 fprintf (writer->
fp,
"tp V%x:%s:%x:%s\n",
274 fprintf (writer->
fp,
"\n");
287 if (fwrite (buf, len, 1, writer->
fp) < 1)
302 if (fwrite (&gotten, 4, 1, writer->
fp) < 1)
345 #define TRACE_HEADER_SIZE 8
347 #define TFILE_PID (1)
374 else if (gotten < size)
375 error (
_(
"Premature end of file while reading trace file"));
396 error (
_(
"No trace file specified."));
398 filename = tilde_expand (arg);
399 if (!IS_ABSOLUTE_PATH(filename))
411 if (scratch_chan < 0)
427 if (!(header[0] == 0x7f
429 error (
_(
"File is not a valid trace file."));
467 error (
_(
"Excessively long lines in trace file"));
476 error (
_(
"No register block size recorded in trace file"));
491 warning (
_(
"No traceframes present in this file."));
520 p += strlen (
"status ");
530 p += strlen (
"tsv ");
534 warning (
_(
"Ignoring trace file definition \"%s\""), line);
616 int tfnum = 0, found = 0;
617 unsigned int data_size;
619 off_t
offset, tframe_offset;
672 if (addr1 <= tfaddr && tfaddr <= addr2)
677 if (!(addr1 <= tfaddr && tfaddr <= addr2))
716 char *wantedp = data;
718 if (*wantedp == blocktype)
748 if ((*callback) (block_type, data))
760 mlen = (
unsigned short)
765 pos += (8 + 2 + mlen);
772 error (
_(
"Unknown block type '%c' (0x%x) in trace frame"),
773 block_type, block_type);
799 int offset, regn, regsize;
828 else if (regno == -1)
842 const char *annex,
gdb_byte *readbuf,
851 error (
_(
"tfile_xfer_partial: trace file is read-only"));
873 mlen = (
unsigned short)
880 if (maddr <= offset && offset < (maddr + mlen))
882 amt = (maddr + mlen) - offset;
893 if (offset < maddr && maddr < (offset + len))
894 if (low_addr_available == 0 || low_addr_available > maddr)
895 low_addr_available = maddr;
898 pos += (8 + 2 + mlen);
904 if (offset < low_addr_available)
905 len =
min (len, low_addr_available - offset);
984 mlen = (
unsigned short)
1008 warning (
_(
"Unhandled trace block type (%d) '%c ' "
1009 "while building trace frame info."),
1010 blocktype, blocktype);
1034 =
"Use a trace file as a target. Specify the filename of the trace file.";
struct gdbarch * target_gdbarch(void)
static CORE_ADDR tfile_get_traceframe_address(off_t tframe_offset)
ssize_t read(int fd, void *buf, size_t count)
ULONGEST extract_unsigned_integer(const gdb_byte *, int, enum bfd_endian)
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)
static void tfile_write_uploaded_tsv(struct trace_file_writer *self, struct uploaded_tsv *utsv)
void parse_tracepoint_definition(char *line, struct uploaded_tp **utpp)
static int tfile_trace_find(struct target_ops *self, enum trace_find_type type, int num, CORE_ADDR addr1, CORE_ADDR addr2, int *tpp)
struct gdbarch * get_regcache_arch(const struct regcache *regcache)
const struct trace_file_write_ops * ops
void warning(const char *fmt,...)
void push_target(struct target_ops *t)
int bin2hex(const gdb_byte *bin, char *hex, int count)
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)
static void tfile_write_regblock_type(struct trace_file_writer *self, int size)
#define VEC_safe_push(T, V, O)
FILE * gdb_fopen_cloexec(const char *filename, const char *opentype)
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)
int(* to_get_trace_state_variable_value)(struct target_ops *, int tsv, LONGEST *val) TARGET_DEFAULT_RETURN(0)
void printf_filtered(const char *format,...)
struct traceframe_info *(* to_traceframe_info)(struct target_ops *) TARGET_DEFAULT_NORETURN(tcomplain())
void parse_tsv_definition(char *line, struct uploaded_tsv **utsvp)
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
static void tfile_write_definition_end(struct trace_file_writer *self)
void initialize_file_ftype(void)
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
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t err
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
int encode_source_string(int tpnum, ULONGEST addr, char *srctype, char *src, char *buf, int buf_size)
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)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
void add_target_with_completer(struct target_ops *t, completer_ftype *completer)
enum target_xfer_status exec_read_partial_read_only(gdb_byte *readbuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
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())
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)
static void tfile_write_uploaded_tp(struct trace_file_writer *self, struct uploaded_tp *utp)
const char * stop_reason_names[]
initialize_file_ftype _initialize_tracefile_tfile
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)
int(* walk_blocks_callback_func)(char blocktype, void *data)
int ptid_get_pid(ptid_t ptid)
void throw_exception(struct gdb_exception exception)
const char const char int
static void init_tfile_ops(void)
void discard_cleanups(struct cleanup *old_chain)
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
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)
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 struct traceframe_info * tfile_traceframe_info(struct target_ops *self)
struct trace_file_writer * tfile_trace_file_writer_new(void)
void target_preopen(int from_tty)
LONGEST extract_signed_integer(const gdb_byte *, int, enum bfd_endian)
enum bfd_endian byte_order
void parse_trace_status(char *line, struct trace_status *ts)
void error(const char *fmt,...)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int int rusage_t pid_t pid
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
const ULONGEST const LONGEST len