From 7c1687a9661c460fac39e57a451a90c5f48213d9 Mon Sep 17 00:00:00 2001 From: Markus Metzger Date: Mon, 11 Mar 2013 08:47:10 +0000 Subject: [PATCH] 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. --- gdb/ChangeLog | 20 ++++++++++ gdb/record-full.c | 58 ++------------------------- gdb/record.c | 99 ++++++++++++++++++++++++++++++++++++++++++++--- gdb/record.h | 12 ++++++ gdb/target.c | 17 ++++++++ gdb/target.h | 6 +++ 6 files changed, 153 insertions(+), 59 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6701fbea04..789622ad06 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,23 @@ +2013-03-11 Markus Metzger + + * 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 * record-full.h, record-full.c (record_memory_query): Rename diff --git a/gdb/record-full.c b/gdb/record-full.c index 5ffa6b73e7..e7af504d5a 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 8b447176e3..36150f7154 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 b428eaf91c..04d6b4ac9f 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 efd5f630d5..e41f0741f8 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -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) { diff --git a/gdb/target.h b/gdb/target.h index ba22292e09..adf9f054fb 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); -- 2.34.1