From 12e03cd06ada8ca7e62fa52aa84946256c1bc654 Mon Sep 17 00:00:00 2001 From: Yao Qi Date: Mon, 10 Feb 2014 15:22:55 +0800 Subject: Share some code between ctf and tfile target. 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 * 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/tracefile.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'gdb/tracefile.c') diff --git a/gdb/tracefile.c b/gdb/tracefile.c index 9945ae5..7972290 100644 --- a/gdb/tracefile.c +++ b/gdb/tracefile.c @@ -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 -- cgit v1.1