]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Share some code between ctf and tfile target.
authorYao Qi <yao@codesourcery.com>
Mon, 10 Feb 2014 07:22:55 +0000 (15:22 +0800)
committerYao Qi <yao@codesourcery.com>
Sun, 23 Feb 2014 03:44:26 +0000 (11:44 +0800)
This patch move the duplicated code between tfile and ctf
targets into file tracefile.c.  The common part of target_ops
fields are set in init_tracefile_ops.

gdb:

2014-02-23  Yao Qi  <yao@codesourcery.com>

* ctf.c (ctf_has_stack, ctf_has_registers): Remove.
(ctf_thread_alive, ctf_get_trace_status): Remove.
(init_ctf_ops): Don't set some fields of ctf_ops.  Call
init_tracefile_ops.
* tracefile-tfile.c (tfile_get_trace_status): Remove.
(tfile_has_stack, tfile_has_registers): Remove.
(tfile_thread_alive): Remove.
(init_tfile_ops): Don't set some fields of tfile_ops.  Call
init_tracefile_ops.
* tracefile.c (tracefile_has_stack): New function.
(tracefile_has_registers): New function.
(tracefile_thread_alive): New function.
(tracefile_get_trace_status): New function.
(init_tracefile_ops): New function.
* tracefile.h (init_tracefile_ops): Declare.

gdb/ChangeLog
gdb/ctf.c
gdb/tracefile-tfile.c
gdb/tracefile.c
gdb/tracefile.h

index 4db4f2fb77212923ad9961702ef109066f5edfb5..a5f4710bac0184d4661cbe354789ab176c6508c5 100644 (file)
@@ -1,3 +1,21 @@
+2014-02-23  Yao Qi  <yao@codesourcery.com>
+
+       * ctf.c (ctf_has_stack, ctf_has_registers): Remove.
+       (ctf_thread_alive, ctf_get_trace_status): Remove.
+       (init_ctf_ops): Don't set some fields of ctf_ops.  Call
+       init_tracefile_ops.
+       * tracefile-tfile.c (tfile_get_trace_status): Remove.
+       (tfile_has_stack, tfile_has_registers): Remove.
+       (tfile_thread_alive): Remove.
+       (init_tfile_ops): Don't set some fields of tfile_ops.  Call
+       init_tracefile_ops.
+       * tracefile.c (tracefile_has_stack): New function.
+       (tracefile_has_registers): New function.
+       (tracefile_thread_alive): New function.
+       (tracefile_get_trace_status): New function.
+       (init_tracefile_ops): New function.
+       * tracefile.h (init_tracefile_ops): Declare.
+
 2014-02-23  Yao Qi  <yao@codesourcery.com>
 
        * tracepoint.c (TFILE_PID): Move it to tracefile-tfile.c.
index ae075f92e35b9101fb32e8d55d990681aa6d71b3..6924fb07f59e9602bfe8cff8db6228c3d7feb834 100644 (file)
--- a/gdb/ctf.c
+++ b/gdb/ctf.c
@@ -1734,35 +1734,6 @@ ctf_trace_find (struct target_ops *self, enum trace_find_type type, int num,
   return -1;
 }
 
-/* This is the implementation of target_ops method to_has_stack.
-   The target has a stack when GDB has already selected one trace
-   frame.  */
-
-static int
-ctf_has_stack (struct target_ops *ops)
-{
-  return get_traceframe_number () != -1;
-}
-
-/* This is the implementation of target_ops method to_has_registers.
-   The target has registers when GDB has already selected one trace
-   frame.  */
-
-static int
-ctf_has_registers (struct target_ops *ops)
-{
-  return get_traceframe_number () != -1;
-}
-
-/* This is the implementation of target_ops method to_thread_alive.
-   CTF trace data has one thread faked by GDB.  */
-
-static int
-ctf_thread_alive (struct target_ops *ops, ptid_t ptid)
-{
-  return 1;
-}
-
 /* This is the implementation of target_ops method to_traceframe_info.
    Iterate the events whose name is "memory", in current
    frame, extract memory range information, and return them in
@@ -1835,23 +1806,12 @@ ctf_traceframe_info (struct target_ops *self)
   return info;
 }
 
-/* This is the implementation of target_ops method to_get_trace_status.
-   The trace status for a file is that tracing can never be run.  */
-
-static int
-ctf_get_trace_status (struct target_ops *self, struct trace_status *ts)
-{
-  /* Other bits of trace status were collected as part of opening the
-     trace files, so nothing to do here.  */
-
-  return -1;
-}
-
 static void
 init_ctf_ops (void)
 {
   memset (&ctf_ops, 0, sizeof (ctf_ops));
 
+  init_tracefile_ops (&ctf_ops);
   ctf_ops.to_shortname = "ctf";
   ctf_ops.to_longname = "CTF file";
   ctf_ops.to_doc = "Use a CTF directory as a target.\n\
@@ -1861,16 +1821,10 @@ Specify the filename of the CTF directory.";
   ctf_ops.to_fetch_registers = ctf_fetch_registers;
   ctf_ops.to_xfer_partial = ctf_xfer_partial;
   ctf_ops.to_files_info = ctf_files_info;
-  ctf_ops.to_get_trace_status = ctf_get_trace_status;
   ctf_ops.to_trace_find = ctf_trace_find;
   ctf_ops.to_get_trace_state_variable_value
     = ctf_get_trace_state_variable_value;
-  ctf_ops.to_stratum = process_stratum;
-  ctf_ops.to_has_stack = ctf_has_stack;
-  ctf_ops.to_has_registers = ctf_has_registers;
   ctf_ops.to_traceframe_info = ctf_traceframe_info;
-  ctf_ops.to_thread_alive = ctf_thread_alive;
-  ctf_ops.to_magic = OPS_MAGIC;
 }
 
 #endif
index 0f4aa93a662f8b86e9bf2ff71b17df184aab6640..2daa560f641049e8457076d37b9edc56f079d218 100644 (file)
@@ -561,17 +561,6 @@ tfile_files_info (struct target_ops *t)
   printf_filtered ("\t`%s'\n", trace_filename);
 }
 
-/* The trace status for a file is that tracing can never be run.  */
-
-static int
-tfile_get_trace_status (struct target_ops *self, struct trace_status *ts)
-{
-  /* Other bits of trace status were collected as part of opening the
-     trace files, so nothing to do here.  */
-
-  return -1;
-}
-
 static void
 tfile_get_tracepoint_status (struct target_ops *self,
                             struct breakpoint *tp, struct uploaded_tp *utp)
@@ -1035,24 +1024,6 @@ tfile_has_memory (struct target_ops *ops)
   return 1;
 }
 
-static int
-tfile_has_stack (struct target_ops *ops)
-{
-  return get_traceframe_number () != -1;
-}
-
-static int
-tfile_has_registers (struct target_ops *ops)
-{
-  return get_traceframe_number () != -1;
-}
-
-static int
-tfile_thread_alive (struct target_ops *ops, ptid_t ptid)
-{
-  return 1;
-}
-
 /* Callback for traceframe_walk_blocks.  Builds a traceframe_info
    object for the tfile target's current traceframe.  */
 
@@ -1119,6 +1090,8 @@ tfile_traceframe_info (struct target_ops *self)
 static void
 init_tfile_ops (void)
 {
+  init_tracefile_ops (&tfile_ops);
+
   tfile_ops.to_shortname = "tfile";
   tfile_ops.to_longname = "Local trace dump file";
   tfile_ops.to_doc
@@ -1128,19 +1101,13 @@ init_tfile_ops (void)
   tfile_ops.to_fetch_registers = tfile_fetch_registers;
   tfile_ops.to_xfer_partial = tfile_xfer_partial;
   tfile_ops.to_files_info = tfile_files_info;
-  tfile_ops.to_get_trace_status = tfile_get_trace_status;
   tfile_ops.to_get_tracepoint_status = tfile_get_tracepoint_status;
   tfile_ops.to_trace_find = tfile_trace_find;
   tfile_ops.to_get_trace_state_variable_value
     = tfile_get_trace_state_variable_value;
-  tfile_ops.to_stratum = process_stratum;
   tfile_ops.to_has_all_memory = tfile_has_all_memory;
   tfile_ops.to_has_memory = tfile_has_memory;
-  tfile_ops.to_has_stack = tfile_has_stack;
-  tfile_ops.to_has_registers = tfile_has_registers;
   tfile_ops.to_traceframe_info = tfile_traceframe_info;
-  tfile_ops.to_thread_alive = tfile_thread_alive;
-  tfile_ops.to_magic = OPS_MAGIC;
 }
 
 extern initialize_file_ftype _initialize_tracefile_tfile;
index 9945ae5dc0d1a6c1e6e1f13c42d63e84b207f403..79722901ec585778e84a283fe57be913a27db762 100644 (file)
@@ -376,6 +376,60 @@ trace_save_ctf (const char *dirname, int target_does_save)
   do_cleanups (back_to);
 }
 
+/* This is the implementation of target_ops method to_has_stack.
+   The target has a stack when GDB has already selected one trace
+   frame.  */
+
+static int
+tracefile_has_stack (struct target_ops *ops)
+{
+  return get_traceframe_number () != -1;
+}
+
+/* This is the implementation of target_ops method to_has_registers.
+   The target has registers when GDB has already selected one trace
+   frame.  */
+
+static int
+tracefile_has_registers (struct target_ops *ops)
+{
+  return get_traceframe_number () != -1;
+}
+
+/* This is the implementation of target_ops method to_thread_alive.
+   tracefile has one thread faked by GDB.  */
+
+static int
+tracefile_thread_alive (struct target_ops *ops, ptid_t ptid)
+{
+  return 1;
+}
+
+/* This is the implementation of target_ops method to_get_trace_status.
+   The trace status for a file is that tracing can never be run.  */
+
+static int
+tracefile_get_trace_status (struct target_ops *self, struct trace_status *ts)
+{
+  /* Other bits of trace status were collected as part of opening the
+     trace files, so nothing to do here.  */
+
+  return -1;
+}
+
+/* Initialize OPS for tracefile related targets.  */
+
+void
+init_tracefile_ops (struct target_ops *ops)
+{
+  ops->to_stratum = process_stratum;
+  ops->to_get_trace_status = tracefile_get_trace_status;
+  ops->to_has_stack = tracefile_has_stack;
+  ops->to_has_registers = tracefile_has_registers;
+  ops->to_thread_alive = tracefile_thread_alive;
+  ops->to_magic = OPS_MAGIC;
+}
+
 extern initialize_file_ftype _initialize_tracefile;
 
 void
index 833de5ccd72bfc85d9d73df535228305ba08397b..db454e310774c48e930fbc9cd4b8bd17f3667121 100644 (file)
@@ -111,4 +111,6 @@ struct trace_file_writer
 
 extern struct trace_file_writer *tfile_trace_file_writer_new (void);
 
+extern void init_tracefile_ops (struct target_ops *ops);
+
 #endif /* TRACEFILE_H */