aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Metzger <mmetzger@sourceware.org>2013-03-11 08:47:10 +0000
committerMarkus Metzger <mmetzger@sourceware.org>2013-03-11 08:47:10 +0000
commit7c1687a9661c460fac39e57a451a90c5f48213d9 (patch)
tree35ee2e97db0ea8485c239d209c625aa80eaad35e
parent25ea693b87da84e449d731c609b0fd744092e70d (diff)
downloadgdb-7c1687a9661c460fac39e57a451a90c5f48213d9.zip
gdb-7c1687a9661c460fac39e57a451a90c5f48213d9.tar.gz
gdb-7c1687a9661c460fac39e57a451a90c5f48213d9.tar.bz2
Provide default target methods for record targets that are likely to be shared
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.
-rw-r--r--gdb/ChangeLog20
-rw-r--r--gdb/record-full.c58
-rw-r--r--gdb/record.c99
-rw-r--r--gdb/record.h12
-rw-r--r--gdb/target.c17
-rw-r--r--gdb/target.h6
6 files changed, 153 insertions, 59 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6701fbe..789622a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,25 @@
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
to ...
(record_full_memory_query): ...this. Update all users.
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 5ffa6b7..e7af504 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -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;
diff --git a/gdb/record.c b/gdb/record.c
index 8b44717..36150f7 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -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"));
diff --git a/gdb/record.h b/gdb/record.h
index b428eaf..04d6b4a 100644
--- a/gdb/record.h
+++ b/gdb/record.h
@@ -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_ */
diff --git a/gdb/target.c b/gdb/target.c
index efd5f63..e41f074 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -4244,6 +4244,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)
{
struct target_ops *t;
diff --git a/gdb/target.h b/gdb/target.h
index ba22292..adf9f05 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -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);