Provide default target methods for record targets that are likely to be shared
authorMarkus Metzger <mmetzger@sourceware.org>
Mon, 11 Mar 2013 08:47:10 +0000 (08:47 +0000)
committerMarkus Metzger <mmetzger@sourceware.org>
Mon, 11 Mar 2013 08:47:10 +0000 (08:47 +0000)
between different record targets.

gdb/
* record.h (record_disconnect): New.
(record_detach): New.
(record_mourn_inferior): New.
(record_kill): New.
* record-full.c (record_disconnect, record_detach,
record_mourn_inferior, record_kill): Move to...
* record.c: ...here.
(DEBUG): New.
(record_stop): New.
(record_unpush): New.
(cmd_record_stop): Call record_stop. Replace unpush_target
call with record_unpush call.
(record_disconnect, record_detach): Assert that the target
is of record stratum. Call record_unpush, record_stop, and
DEBUG.
(record_mourn_inferior, record_kill): Assert that the target
is of record stratum. Call record_unpush and DEBUG.

gdb/ChangeLog
gdb/record-full.c
gdb/record.c
gdb/record.h
gdb/target.c
gdb/target.h

index 6701fbea04125664eaa57f745c6be4db1a90e0e4..789622ad06b80b9060b73c09ef51fa9b7a80d951 100644 (file)
@@ -1,3 +1,23 @@
+2013-03-11  Markus Metzger  <markus.t.metzger@intel.com>
+
+       * record.h (record_disconnect): New.
+       (record_detach): New.
+       (record_mourn_inferior): New.
+       (record_kill): New.
+       * record-full.c (record_disconnect, record_detach,
+       record_mourn_inferior, record_kill): Move to...
+       * record.c: ...here.
+       (DEBUG): New.
+       (record_stop): New.
+       (record_unpush): New.
+       (cmd_record_stop): Call record_stop. Replace unpush_target
+       call with record_unpush call.
+       (record_disconnect, record_detach): Assert that the target
+       is of record stratum. Call record_unpush, record_stop, and
+       DEBUG.
+       (record_mourn_inferior, record_kill): Assert that the target
+       is of record stratum. Call record_unpush and DEBUG.
+
 2013-03-11  Markus Metzger  <markus.t.metzger@intel.com>
 
        * record-full.h, record-full.c (record_memory_query): Rename
index 5ffa6b73e70140dc9dfbb7c5797ce76822bafb9c..e7af504d5afd71900a97cb9e7c00df55ed46f311 100644 (file)
@@ -1523,56 +1523,6 @@ record_full_stopped_by_watchpoint (void)
     return record_full_beneath_to_stopped_by_watchpoint ();
 }
 
-/* "to_disconnect" method for process record target.  */
-
-static void
-record_full_disconnect (struct target_ops *target, char *args, int from_tty)
-{
-  if (record_debug)
-    fprintf_unfiltered (gdb_stdlog,
-                       "Process record: record_full_disconnect\n");
-
-  unpush_target (&record_full_ops);
-  target_disconnect (args, from_tty);
-}
-
-/* "to_detach" method for process record target.  */
-
-static void
-record_full_detach (struct target_ops *ops, char *args, int from_tty)
-{
-  if (record_debug)
-    fprintf_unfiltered (gdb_stdlog, "Process record: record_full_detach\n");
-
-  unpush_target (&record_full_ops);
-  target_detach (args, from_tty);
-}
-
-/* "to_mourn_inferior" method for process record target.  */
-
-static void
-record_full_mourn_inferior (struct target_ops *ops)
-{
-  if (record_debug)
-    fprintf_unfiltered (gdb_stdlog, "Process record: "
-                                   "record_full_mourn_inferior\n");
-
-  unpush_target (&record_full_ops);
-  target_mourn_inferior ();
-}
-
-/* Close process record target before killing the inferior process.  */
-
-static void
-record_full_kill (struct target_ops *ops)
-{
-  if (record_debug)
-    fprintf_unfiltered (gdb_stdlog, "Process record: record_full_kill\n");
-
-  unpush_target (&record_full_ops);
-  target_kill ();
-}
-
 static int
 record_full_stopped_data_address (struct target_ops *ops, CORE_ADDR *addr_p)
 {
@@ -2117,10 +2067,10 @@ init_record_full_ops (void)
   record_full_ops.to_close = record_full_close;
   record_full_ops.to_resume = record_full_resume;
   record_full_ops.to_wait = record_full_wait;
-  record_full_ops.to_disconnect = record_full_disconnect;
-  record_full_ops.to_detach = record_full_detach;
-  record_full_ops.to_mourn_inferior = record_full_mourn_inferior;
-  record_full_ops.to_kill = record_full_kill;
+  record_full_ops.to_disconnect = record_disconnect;
+  record_full_ops.to_detach = record_detach;
+  record_full_ops.to_mourn_inferior = record_mourn_inferior;
+  record_full_ops.to_kill = record_kill;
   record_full_ops.to_create_inferior = find_default_create_inferior;
   record_full_ops.to_store_registers = record_full_store_registers;
   record_full_ops.to_xfer_partial = record_full_xfer_partial;
index 8b447176e3ba96b08184158fb98329cbe19d6930..36150f71547dbb189ab6b53cdc5784faa10db42c 100644 (file)
@@ -33,6 +33,10 @@ struct cmd_list_element *set_record_cmdlist = NULL;
 struct cmd_list_element *show_record_cmdlist = NULL;
 struct cmd_list_element *info_record_cmdlist = NULL;
 
+#define DEBUG(msg, args...)                                            \
+  if (record_debug)                                                    \
+    fprintf_unfiltered (gdb_stdlog, "record: " msg "\n", ##args)
+
 /* Find the record target in the target stack.  */
 
 static struct target_ops *
@@ -71,13 +75,96 @@ record_read_memory (struct gdbarch *gdbarch,
 {
   int ret = target_read_memory (memaddr, myaddr, len);
 
-  if (ret && record_debug)
-    printf_unfiltered (_("Process record: error reading memory "
-                        "at addr %s len = %ld.\n"),
-                      paddress (gdbarch, memaddr), (long) len);
+  if (ret != 0)
+    DEBUG ("error reading memory at addr %s len = %ld.\n",
+          paddress (gdbarch, memaddr), (long) len);
+
   return ret;
 }
 
+/* Stop recording.  */
+
+static void
+record_stop (struct target_ops *t)
+{
+  DEBUG ("stop %s", t->to_shortname);
+
+  if (t->to_stop_recording != NULL)
+    t->to_stop_recording ();
+}
+
+/* Unpush the record target.  */
+
+static void
+record_unpush (struct target_ops *t)
+{
+  DEBUG ("unpush %s", t->to_shortname);
+
+  unpush_target (t);
+}
+
+/* See record.h.  */
+
+void
+record_disconnect (struct target_ops *t, char *args, int from_tty)
+{
+  gdb_assert (t->to_stratum == record_stratum);
+
+  DEBUG ("disconnect %s", t->to_shortname);
+
+  record_stop (t);
+  record_unpush (t);
+
+  target_disconnect (args, from_tty);
+}
+
+/* See record.h.  */
+
+void
+record_detach (struct target_ops *t, char *args, int from_tty)
+{
+  gdb_assert (t->to_stratum == record_stratum);
+
+  DEBUG ("detach %s", t->to_shortname);
+
+  record_stop (t);
+  record_unpush (t);
+
+  target_detach (args, from_tty);
+}
+
+/* See record.h.  */
+
+void
+record_mourn_inferior (struct target_ops *t)
+{
+  gdb_assert (t->to_stratum == record_stratum);
+
+  DEBUG ("mourn inferior %s", t->to_shortname);
+
+  /* It is safer to not stop recording.  Resources will be freed when
+     threads are discarded.  */
+  record_unpush (t);
+
+  target_mourn_inferior ();
+}
+
+/* See record.h.  */
+
+void
+record_kill (struct target_ops *t)
+{
+  gdb_assert (t->to_stratum == record_stratum);
+
+  DEBUG ("kill %s", t->to_shortname);
+
+  /* It is safer to not stop recording.  Resources will be freed when
+     threads are discarded.  */
+  record_unpush (t);
+
+  target_kill ();
+}
+
 /* Implement "show record debug" command.  */
 
 static void
@@ -131,7 +218,9 @@ cmd_record_stop (char *args, int from_tty)
   struct target_ops *t;
 
   t = require_record_target ();
-  unpush_target (t);
+
+  record_stop (t);
+  record_unpush (t);
 
   printf_unfiltered (_("Process record is stopped and all execution "
                       "logs are deleted.\n"));
index b428eaf91c4e4f0cea144e84aa9684f5a6a907bf..04d6b4ac9ffb1b1b20fd1229cd28693b92f5dfea 100644 (file)
@@ -41,4 +41,16 @@ extern int record_read_memory (struct gdbarch *gdbarch,
 /* The "record goto" command.  */
 extern void cmd_record_goto (char *arg, int from_tty);
 
+/* The default "to_disconnect" target method for record targets.  */
+extern void record_disconnect (struct target_ops *, char *, int);
+
+/* The default "to_detach" target method for record targets.  */
+extern void record_detach (struct target_ops *, char *, int);
+
+/* The default "to_mourn_inferior" target method for record targets.  */
+extern void record_mourn_inferior (struct target_ops *);
+
+/* The default "to_kill" target method for record targets.  */
+extern void record_kill (struct target_ops *);
+
 #endif /* _RECORD_H_ */
index efd5f630d536a4a80777a9df34d41864075636f9..e41f0741f85e3ac1954299d46a8c4c7554e97351 100644 (file)
@@ -4243,6 +4243,23 @@ target_read_btrace (struct btrace_target_info *btinfo,
 
 /* See target.h.  */
 
+void
+target_stop_recording (void)
+{
+  struct target_ops *t;
+
+  for (t = current_target.beneath; t != NULL; t = t->beneath)
+    if (t->to_stop_recording != NULL)
+      {
+       t->to_stop_recording ();
+       return;
+      }
+
+  /* This is optional.  */
+}
+
+/* See target.h.  */
+
 void
 target_info_record (void)
 {
index ba22292e0914f8efe8d051bdd0a931e5ff603857..adf9f054fbd3375d015e0d4f419233de4e1fa389 100644 (file)
@@ -882,6 +882,9 @@ struct target_ops
     VEC (btrace_block_s) *(*to_read_btrace) (struct btrace_target_info *,
                                             enum btrace_read_type);
 
+    /* Stop trace recording.  */
+    void (*to_stop_recording) (void);
+
     /* Print information about the recording.  */
     void (*to_info_record) (void);
 
@@ -1967,6 +1970,9 @@ extern void target_teardown_btrace (struct btrace_target_info *btinfo);
 extern VEC (btrace_block_s) *target_read_btrace (struct btrace_target_info *,
                                                 enum btrace_read_type);
 
+/* See to_stop_recording in struct target_ops.  */
+extern void target_stop_recording (void);
+
 /* See to_info_record in struct target_ops.  */
 extern void target_info_record (void);
 
This page took 0.033217 seconds and 4 git commands to generate.