From: Pedro Alves <palves@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: [PATCH] Fix "is a record target open" checks.
Date: Tue, 14 Jan 2014 11:48:00 -0000 [thread overview]
Message-ID: <52D523FD.8060205@redhat.com> (raw)
In-Reply-To: <1389640367-5571-3-git-send-email-tromey@redhat.com>
On 01/13/2014 07:12 PM, Tom Tromey wrote:
> RECORD_IS_USED and find_record_target look at
> current_target.to_stratum to determine whether a record target is in
> use. This is bad because arch_stratum is greater than record_stratum.
This rationale doesn't look right for find_record_target.
Actually, the patch isn't complete -- record_full_open also
has the problem for instance. See below.
> To fix this, this patch adds find_target_at to determine whether a
> target appears at a given stratum. This may seem like overkill
> somehow, but I have a subsequent patch series that uses it more
> heavily.
I have no problem with find_target_at, though I think that
bit could/should instead be split and moved to the series that
actually needs it.
Instead, I'd rather apply a patch that fixes these record issues
completely, and only does that. (IMO this one could go in
immediately). WDYT?
---
Fix "is a record target open" checks.
RECORD_IS_USED and record_full_open look at current_target.to_stratum
to determine whether a record target is in use. This is wrong because
arch_stratum is greater than record_stratum, so if an arch_stratum
target is pushed, RECORD_IS_USED and record_full_open will miss it.
To fix this, we can use the existing find_record_target instead, which
looks up for a record stratum target across the target stack. Since
that means exporting find_record_target in record.h, RECORD_IS_USED
ends up redundant, so the patch eliminates it.
That exercise then reveals other issues:
- adjust_pc_after_break is gating record_full_... calls based on
RECORD_IS_USED. But, record_full_ calls shouldn't be made when
recording with the record-btrace target. So this adds a new
record_full_is_used predicate to be used in that spot.
- record_full_open says "Process record target already running", even
if the recording target is record-btrace ("process record" is the
original complete name of the record-full target). record_btrace_open
only says "The process is already being recorded." and does not
suggest "record stop", like record-full does. The patch factors out
and merges that error to a new record_preopen function that all record
targets call in their open routine.
Tested on x86_64 Fedora 17.
gdb/
2014-01-14 Pedro Alves <palves@redhat.com>
Tom Tromey <tromey@redhat.com>
* infrun.c (use_displaced_stepping): Use find_record_target
instead of RECORD_IS_USED.
(adjust_pc_after_break): Use record_full_is_used instead of
RECORD_IS_USED.
* record-btrace.c (record_btrace_open): Call record_preopen
instead of checking RECORD_IS_USED.
* record-full.c (record_full_shortname)
(record_full_core_shortname): New globals.
(record_full_is_used): New function.
(find_full_open): Call record_preopen instead of checking
RECORD_IS_USED.
(init_record_full_ops): Set the target's shortname to
record_full_shortname.
(init_record_full_core_ops): Set the target's shortname to
record_full_core_shortname.
* record-full.h (record_full_is_used): Declare.
* record.c (find_record_target): Make extern.
(record_preopen): New function.
* record.h (RECORD_IS_USED): Delete macro.
(find_record_target, record_preopen): Declare functions.
---
gdb/infrun.c | 4 ++--
gdb/record-btrace.c | 3 +--
gdb/record-full.c | 26 ++++++++++++++++++++------
gdb/record-full.h | 4 ++++
gdb/record.c | 13 +++++++++++--
gdb/record.h | 9 +++++++--
6 files changed, 45 insertions(+), 14 deletions(-)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 73038a3..311bf9c 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1240,7 +1240,7 @@ use_displaced_stepping (struct gdbarch *gdbarch)
return (((can_use_displaced_stepping == AUTO_BOOLEAN_AUTO && non_stop)
|| can_use_displaced_stepping == AUTO_BOOLEAN_TRUE)
&& gdbarch_displaced_step_copy_insn_p (gdbarch)
- && !RECORD_IS_USED);
+ && find_record_target () == NULL);
}
/* Clean out any stray displaced stepping state. */
@@ -3048,7 +3048,7 @@ adjust_pc_after_break (struct execution_control_state *ecs)
{
struct cleanup *old_cleanups = make_cleanup (null_cleanup, NULL);
- if (RECORD_IS_USED)
+ if (record_full_is_used ())
record_full_gdb_operation_disable_set ();
/* When using hardware single-step, a SIGTRAP is reported for both
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 5fd26e2..c3330e9 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -142,8 +142,7 @@ record_btrace_open (char *args, int from_tty)
DEBUG ("open");
- if (RECORD_IS_USED)
- error (_("The process is already being recorded."));
+ record_preopen ();
if (!target_has_execution)
error (_("The program is not being run."));
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 3fb77ef..9b05db7 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -246,6 +246,23 @@ static void record_full_goto_insn (struct record_full_entry *entry,
enum exec_direction_kind dir);
static void record_full_save (const char *recfilename);
+/* The shortnames of the record full targets. */
+static char record_full_shortname[] = "record-full";
+static char record_full_core_shortname[] = "record-core";
+
+/* See record-full.h. */
+
+int
+record_full_is_used (void)
+{
+ struct target_ops *t;
+
+ t = find_record_target ();
+ return (t != NULL
+ && (t->to_shortname == record_full_shortname
+ || t->to_shortname == record_full_core_shortname));
+}
+
/* Alloc and free functions for record_full_reg, record_full_mem, and
record_full_end entries. */
@@ -907,10 +924,7 @@ record_full_open (char *name, int from_tty)
if (record_debug)
fprintf_unfiltered (gdb_stdlog, "Process record: record_full_open\n");
- /* Check if record target is already running. */
- if (current_target.to_stratum == record_stratum)
- error (_("Process record target already running. Use \"record stop\" to "
- "stop record target first."));
+ record_preopen ();
/* Reset the tmp beneath pointers. */
tmp_to_resume_ops = NULL;
@@ -2041,7 +2055,7 @@ record_full_goto (ULONGEST target_insn)
static void
init_record_full_ops (void)
{
- record_full_ops.to_shortname = "record-full";
+ record_full_ops.to_shortname = record_full_shortname;
record_full_ops.to_longname = "Process record and replay target";
record_full_ops.to_doc =
"Log program while executing and replay execution from log.";
@@ -2277,7 +2291,7 @@ record_full_core_has_execution (struct target_ops *ops, ptid_t the_ptid)
static void
init_record_full_core_ops (void)
{
- record_full_core_ops.to_shortname = "record-core";
+ record_full_core_ops.to_shortname = record_full_core_shortname;
record_full_core_ops.to_longname = "Process record and replay target";
record_full_core_ops.to_doc =
"Log program while executing and replay execution from log.";
diff --git a/gdb/record-full.h b/gdb/record-full.h
index 517d786..ef3b387 100644
--- a/gdb/record-full.h
+++ b/gdb/record-full.h
@@ -25,6 +25,10 @@ extern int record_full_memory_query;
extern int record_full_arch_list_add_reg (struct regcache *regcache, int num);
extern int record_full_arch_list_add_mem (CORE_ADDR addr, int len);
extern int record_full_arch_list_add_end (void);
+
+/* Returns true if the process record target is open. */
+extern int record_full_is_used (void);
+
extern struct cleanup *record_full_gdb_operation_disable_set (void);
#endif /* RECORD_FULL_H */
diff --git a/gdb/record.c b/gdb/record.c
index e0df6b1..771bcff 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -57,9 +57,9 @@ struct cmd_list_element *info_record_cmdlist = NULL;
if (record_debug) \
fprintf_unfiltered (gdb_stdlog, "record: " msg "\n", ##args)
-/* Find the record target in the target stack. */
+/* See record.h. */
-static struct target_ops *
+struct target_ops *
find_record_target (void)
{
struct target_ops *t;
@@ -86,6 +86,15 @@ require_record_target (void)
return t;
}
+void
+record_preopen (void)
+{
+ /* Check if a record target is already running. */
+ if (find_record_target ())
+ error (_("The process is already being recorded. Use \"record stop\" to "
+ "stop recording first."));
+}
+
/* See record.h. */
int
diff --git a/gdb/record.h b/gdb/record.h
index ab5ea4b..958affc 100644
--- a/gdb/record.h
+++ b/gdb/record.h
@@ -22,8 +22,6 @@
struct cmd_list_element;
-#define RECORD_IS_USED (current_target.to_stratum == record_stratum)
-
extern unsigned int record_debug;
/* Allow record targets to add their own sub-commands. */
@@ -63,4 +61,11 @@ extern void record_mourn_inferior (struct target_ops *);
/* The default "to_kill" target method for record targets. */
extern void record_kill (struct target_ops *);
+/* Find the record_stratum target in the target stack. */
+extern struct target_ops *find_record_target (void);
+
+/* This is to be called by record_stratum targets' open routine before
+ it does anything. */
+extern void record_preopen (void);
+
#endif /* _RECORD_H_ */
--
1.7.11.7
next prev parent reply other threads:[~2014-01-14 11:48 UTC|newest]
Thread overview: 100+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-13 19:12 [RFC 00/32] clean up target delegation Tom Tromey
2014-01-13 19:12 ` [RFC 01/32] add "this" pointers to more target APIs Tom Tromey
2014-01-14 12:10 ` Pedro Alves
2014-01-14 20:25 ` Tom Tromey
2014-01-13 19:12 ` [RFC 03/32] introduce async_callback_ftype Tom Tromey
2014-01-14 10:35 ` Pedro Alves
2014-01-14 10:50 ` Joel Brobecker
2014-01-14 15:06 ` Tom Tromey
2014-01-14 17:19 ` Joel Brobecker
2014-01-14 17:27 ` Tom Tromey
2014-01-14 18:30 ` Pedro Alves
2014-01-14 19:45 ` Tom Tromey
2014-01-15 15:25 ` Tom Tromey
2014-01-13 19:12 ` [RFC 02/32] introduce and use find_target_at Tom Tromey
2014-01-14 11:48 ` Pedro Alves [this message]
2014-01-14 15:30 ` [PATCH] Fix "is a record target open" checks Tom Tromey
2014-01-14 18:27 ` Pedro Alves
2014-01-15 16:22 ` Tom Tromey
2014-01-13 19:13 ` [RFC 10/32] Add target_ops argument to to_terminal_init Tom Tromey
2014-01-14 12:51 ` Pedro Alves
2014-01-13 19:13 ` [RFC 04/32] add make-target-delegates Tom Tromey
2014-01-14 10:52 ` Pedro Alves
2014-01-14 14:46 ` Tom Tromey
2014-01-13 19:13 ` [RFC 32/32] minor cleanups to update_current_target Tom Tromey
2014-01-14 20:10 ` Pedro Alves
2014-01-13 19:13 ` [RFC 26/32] convert to_static_tracepoint_markers_by_strid Tom Tromey
2014-01-14 18:57 ` Pedro Alves
2014-01-13 19:13 ` [RFC 31/32] change delegation for to_read_description Tom Tromey
2014-01-14 20:07 ` Pedro Alves
2014-01-14 20:22 ` Tom Tromey
2014-01-13 19:13 ` [RFC 08/32] remove extended_remote_create_inferior_1 Tom Tromey
2014-01-14 12:41 ` Pedro Alves
2014-01-16 19:20 ` Tom Tromey
2014-01-13 19:13 ` [RFC 25/32] convert to_upload_trace_state_variables Tom Tromey
2014-01-14 19:38 ` Pedro Alves
2014-01-13 19:13 ` [RFC 11/32] Add target_ops argument to to_insert_vfork_catchpoint Tom Tromey
2014-01-14 12:52 ` Pedro Alves
2014-01-13 19:13 ` [RFC 09/32] Add target_ops argument to to_close Tom Tromey
2014-01-14 12:48 ` Pedro Alves
2014-01-13 19:13 ` [RFC 24/32] convert to_disable_tracepoint Tom Tromey
2014-01-14 18:49 ` Pedro Alves
2014-01-13 19:13 ` [RFC 12/32] Add target_ops argument to to_thread_name Tom Tromey
2014-01-14 13:03 ` Pedro Alves
2014-01-15 16:45 ` Tom Tromey
2014-01-16 17:50 ` Pedro Alves
2014-01-13 19:13 ` [RFC 19/32] convert to_detach Tom Tromey
2014-01-14 13:32 ` Pedro Alves
2014-01-13 19:13 ` [RFC 27/32] convert to_insert_mask_watchpoint Tom Tromey
2014-01-14 19:15 ` Pedro Alves
2014-01-14 19:23 ` Tom Tromey
2014-01-13 19:23 ` [RFC 13/32] Add target_ops argument to to_get_ada_task_ptid Tom Tromey
2014-01-14 13:21 ` Pedro Alves
2014-01-13 19:23 ` [RFC 07/32] introduce remote_load Tom Tromey
2014-01-14 12:39 ` Pedro Alves
2014-01-13 19:23 ` [RFC 17/32] Add target_ops argument to to_static_tracepoint_markers_by_strid Tom Tromey
2014-01-14 13:25 ` Pedro Alves
2014-01-13 19:23 ` [RFC 20/32] convert to_remove_watchpoint Tom Tromey
2014-01-14 18:39 ` Pedro Alves
2014-01-14 18:55 ` Tom Tromey
2014-01-14 19:07 ` Tom Tromey
2014-01-14 20:38 ` Pedro Alves
2014-01-14 21:47 ` Tom Tromey
2014-01-13 19:24 ` [RFC 06/32] convert to_supports_btrace Tom Tromey
2014-01-14 12:37 ` Pedro Alves
2014-01-15 16:55 ` Tom Tromey
2014-01-13 19:24 ` [RFC 16/32] Add target_ops argument to to_upload_trace_state_variables Tom Tromey
2014-01-14 13:24 ` Pedro Alves
2014-01-13 19:24 ` [RFC 30/32] convert to_search_memory Tom Tromey
2014-01-14 19:45 ` Pedro Alves
2014-01-14 20:20 ` Tom Tromey
2014-01-13 19:37 ` [RFC 21/32] convert to_load Tom Tromey
2014-01-14 18:41 ` Pedro Alves
2014-01-13 19:38 ` [RFC 05/32] add target method delegation Tom Tromey
2014-01-14 12:32 ` Pedro Alves
2014-01-20 22:00 ` Tom Tromey
2014-01-13 19:38 ` [RFC 22/32] convert to_extra_thread_info Tom Tromey
2014-01-14 18:43 ` Pedro Alves
2014-01-13 19:38 ` [RFC 28/32] convert to_get_section_table Tom Tromey
2014-01-14 19:23 ` Pedro Alves
2014-01-14 19:29 ` Tom Tromey
2014-01-14 19:30 ` Pedro Alves
2014-01-15 16:43 ` Tom Tromey
2014-01-16 17:51 ` Pedro Alves
2014-01-13 19:38 ` [RFC 18/32] Add target_ops argument to to_save_record Tom Tromey
2014-01-14 13:26 ` Pedro Alves
2014-01-13 19:38 ` [RFC 23/32] convert to_thread_architecture Tom Tromey
2014-01-14 18:46 ` Pedro Alves
2014-01-13 19:40 ` [RFC 29/32] convert to_insn_history Tom Tromey
2014-01-14 19:29 ` Pedro Alves
2014-01-13 19:57 ` [RFC 14/32] Add target_ops argument to to_fileio_pwrite Tom Tromey
2014-01-14 13:22 ` Pedro Alves
2014-01-13 19:57 ` [RFC 15/32] Add target_ops argument to to_disable_tracepoint Tom Tromey
2014-01-14 13:23 ` Pedro Alves
2014-01-14 20:31 ` go32 fix Pedro Alves
2014-01-14 21:58 ` Tom Tromey
2014-01-15 12:55 ` [RFC 00/32] clean up target delegation Pedro Alves
2014-01-15 16:11 ` Tom Tromey
2014-01-15 20:05 ` Tom Tromey
2014-01-16 17:33 ` Pedro Alves
2014-01-16 19:09 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52D523FD.8060205@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).