X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Ftracefile-tfile.c;h=ea19177475179f741289353995d82cf858a78e48;hb=bb7322c67111024f5977deb85abd777ec713b1a9;hp=af8e3bd83ba615154ad75de185ff21c99968e80f;hpb=f6ac5f3d63e03a81c4ff3749aba234961cc9090e;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c index af8e3bd83b..ea19177475 100644 --- a/gdb/tracefile-tfile.c +++ b/gdb/tracefile-tfile.c @@ -1,6 +1,6 @@ /* Trace file TFILE format support in GDB. - Copyright (C) 1997-2018 Free Software Foundation, Inc. + Copyright (C) 1997-2020 Free Software Foundation, Inc. This file is part of GDB. @@ -20,8 +20,8 @@ #include "defs.h" #include "tracefile.h" #include "readline/tilde.h" -#include "filestuff.h" -#include "rsp-low.h" /* bin2hex */ +#include "gdbsupport/filestuff.h" +#include "gdbsupport/rsp-low.h" /* bin2hex */ #include "regcache.h" #include "inferior.h" #include "gdbthread.h" @@ -31,7 +31,8 @@ #include "remote.h" #include "xml-tdesc.h" #include "target-descriptions.h" -#include "buffer.h" +#include "gdbsupport/buffer.h" +#include "gdbsupport/pathstuff.h" #include #ifndef O_LARGEFILE @@ -40,22 +41,19 @@ /* The tfile target. */ +static const target_info tfile_target_info = { + "tfile", + N_("Local trace dump file"), + N_("Use a trace file as a target.\n\ +Specify the filename of the trace file.") +}; + class tfile_target final : public tracefile_target { public: - const char *shortname () override - { return "tfile"; } - - const char *longname () override - { return _("Local trace dump file"); } + const target_info &info () const override + { return tfile_target_info; } - const char *doc () override - { - return _("\ -Use a trace file as a target. Specify the filename of the trace file."); - } - - void open (const char *, int) override; void close () override; void fetch_registers (struct regcache *, int) override; enum target_xfer_status xfer_partial (enum target_object object, @@ -67,7 +65,7 @@ Use a trace file as a target. Specify the filename of the trace file."); void files_info () override; int trace_find (enum trace_find_type type, int num, CORE_ADDR addr1, CORE_ADDR addr2, int *tpp) override; - int get_trace_state_variable_value (int tsv, LONGEST *val) override; + bool get_trace_state_variable_value (int tsv, LONGEST *val) override; traceframe_info_up traceframe_info () override; void get_tracepoint_status (struct breakpoint *tp, @@ -266,31 +264,32 @@ tfile_write_uploaded_tp (struct trace_file_writer *self, fprintf (writer->fp, ":F%x", utp->orig_size); if (utp->cond) fprintf (writer->fp, - ":X%x,%s", (unsigned int) strlen (utp->cond) / 2, - utp->cond); + ":X%x,%s", (unsigned int) strlen (utp->cond.get ()) / 2, + utp->cond.get ()); fprintf (writer->fp, "\n"); - for (char *act : utp->actions) + for (const auto &act : utp->actions) fprintf (writer->fp, "tp A%x:%s:%s\n", - utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act); - for (char *act : utp->step_actions) + utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act.get ()); + for (const auto &act : utp->step_actions) fprintf (writer->fp, "tp S%x:%s:%s\n", - utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act); + utp->number, phex_nz (utp->addr, sizeof (utp->addr)), act.get ()); if (utp->at_string) { encode_source_string (utp->number, utp->addr, - "at", utp->at_string, buf, MAX_TRACE_UPLOAD); + "at", utp->at_string.get (), + buf, MAX_TRACE_UPLOAD); fprintf (writer->fp, "tp Z%s\n", buf); } if (utp->cond_string) { encode_source_string (utp->number, utp->addr, - "cond", utp->cond_string, + "cond", utp->cond_string.get (), buf, MAX_TRACE_UPLOAD); fprintf (writer->fp, "tp Z%s\n", buf); } - for (char *act : utp->cmd_strings) + for (const auto &act : utp->cmd_strings) { - encode_source_string (utp->number, utp->addr, "cmd", act, + encode_source_string (utp->number, utp->addr, "cmd", act.get (), buf, MAX_TRACE_UPLOAD); fprintf (writer->fp, "tp Z%s\n", buf); } @@ -311,7 +310,7 @@ tfile_write_tdesc (struct trace_file_writer *self) = (struct tfile_trace_file_writer *) self; gdb::optional tdesc - = target_fetch_description_xml (target_stack); + = target_fetch_description_xml (current_top_target ()); if (!tdesc) return; @@ -451,8 +450,10 @@ tfile_read (gdb_byte *readbuf, int size) error (_("Premature end of file while reading trace file")); } -void -tfile_target::open (const char *arg, int from_tty) +/* Open the tfile target. */ + +static void +tfile_target_open (const char *arg, int from_tty) { int flags; int scratch_chan; @@ -470,8 +471,7 @@ tfile_target::open (const char *arg, int from_tty) gdb::unique_xmalloc_ptr 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; @@ -512,7 +512,7 @@ tfile_target::open (const char *arg, int from_tty) ts->disconnected_tracing = 0; ts->circular_buffer = 0; - TRY + try { /* Read through a section of newline-terminated lines that define things like tracepoints. */ @@ -548,17 +548,16 @@ tfile_target::open (const char *arg, int from_tty) if (trace_regblock_size == 0) error (_("No register block size recorded in trace file")); } - CATCH (ex, RETURN_MASK_ALL) + catch (const gdb_exception &ex) { /* Remove the partially set up target. */ unpush_target (&tfile_ops); - throw_exception (ex); + throw; } - END_CATCH inferior_appeared (current_inferior (), TFILE_PID); - inferior_ptid = pid_to_ptid (TFILE_PID); - add_thread_silent (inferior_ptid); + inferior_ptid = ptid_t (TFILE_PID); + add_thread_silent (&tfile_ops, inferior_ptid); if (ts->traceframe_count <= 0) warning (_("No traceframes present in this file.")); @@ -617,14 +616,10 @@ tfile_interp_line (char *line, struct uploaded_tp **utpp, void tfile_target::close () { - int pid; + gdb_assert (trace_fd != -1); - if (trace_fd < 0) - return; - - pid = ptid_get_pid (inferior_ptid); inferior_ptid = null_ptid; /* Avoid confusion from thread stuff. */ - exit_inferior_silent (pid); + exit_inferior_silent (current_inferior ()); ::close (trace_fd); trace_fd = -1; @@ -896,16 +891,16 @@ tfile_target::fetch_registers (struct regcache *regcache, int regno) /* Make sure we stay within block bounds. */ if (offset + regsize > trace_regblock_size) break; - if (regcache_register_status (regcache, regn) == REG_UNKNOWN) + if (regcache->get_register_status (regn) == REG_UNKNOWN) { if (regno == regn) { - regcache_raw_supply (regcache, regno, regs + offset); + regcache->raw_supply (regno, regs + offset); break; } else if (regno == -1) { - regcache_raw_supply (regcache, regn, regs + offset); + regcache->raw_supply (regn, regs + offset); } } } @@ -1033,11 +1028,11 @@ tfile_target::xfer_partial (enum target_object object, /* Iterate through the blocks of a trace frame, looking for a 'V' block with a matching tsv number. */ -int +bool tfile_target::get_trace_state_variable_value (int tsvnum, LONGEST *val) { int pos; - int found = 0; + bool found = false; /* Iterate over blocks in current frame and find the last 'V' block in which tsv number is TSVNUM. In one trace frame, there @@ -1058,7 +1053,7 @@ tfile_target::get_trace_state_variable_value (int tsvnum, LONGEST *val) *val = extract_signed_integer ((gdb_byte *) val, 8, gdbarch_byte_order (target_gdbarch ())); - found = 1; + found = true; } pos += (4 + 8); } @@ -1136,8 +1131,9 @@ tfile_append_tdesc_line (const char *line) buffer_grow_str (&trace_tdesc, "\n"); } +void _initialize_tracefile_tfile (); void -_initialize_tracefile_tfile (void) +_initialize_tracefile_tfile () { - add_target_with_completer (&tfile_ops, filename_completer); + add_target (tfile_target_info, tfile_target_open, filename_completer); }