This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC 02/32] introduce and use find_target_at
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Cc: Tom Tromey <tromey at redhat dot com>
- Date: Mon, 13 Jan 2014 12:12:17 -0700
- Subject: [RFC 02/32] introduce and use find_target_at
- Authentication-results: sourceware.org; auth=none
- References: <1389640367-5571-1-git-send-email-tromey at redhat dot com>
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.
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.
2014-01-08 Tom Tromey <tromey@redhat.com>
* record.c (find_record_target): Use find_target_at.
* record.h (RECORD_IS_REPLAY): Use find_target_at.
* target.c (find_target_at): New function.
* target.h (find_target_at): Declare.
---
gdb/ChangeLog | 7 +++++++
gdb/record.c | 8 +-------
gdb/record.h | 2 +-
gdb/target.c | 14 ++++++++++++++
gdb/target.h | 5 +++++
5 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/gdb/record.c b/gdb/record.c
index ec2a042..0fd8756 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -62,13 +62,7 @@ struct cmd_list_element *info_record_cmdlist = NULL;
static struct target_ops *
find_record_target (void)
{
- struct target_ops *t;
-
- for (t = current_target.beneath; t != NULL; t = t->beneath)
- if (t->to_stratum == record_stratum)
- return t;
-
- return NULL;
+ return find_target_at (record_stratum);
}
/* Check that recording is active. Throw an error, if it isn't. */
diff --git a/gdb/record.h b/gdb/record.h
index 124c32b..05a17a9 100644
--- a/gdb/record.h
+++ b/gdb/record.h
@@ -22,7 +22,7 @@
struct cmd_list_element;
-#define RECORD_IS_USED (current_target.to_stratum == record_stratum)
+#define RECORD_IS_USED (find_target_at (record_stratum) != NULL)
extern unsigned int record_debug;
diff --git a/gdb/target.c b/gdb/target.c
index 092d50c..d2a40ee 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -3648,6 +3648,20 @@ find_target_beneath (struct target_ops *t)
return t->beneath;
}
+/* See target.h. */
+
+struct target_ops *
+find_target_at (enum strata stratum)
+{
+ struct target_ops *t;
+
+ for (t = current_target.beneath; t != NULL; t = t->beneath)
+ if (t->to_stratum == stratum)
+ return t;
+
+ return NULL;
+}
+
/* The inferior process has died. Long live the inferior! */
diff --git a/gdb/target.h b/gdb/target.h
index e00e38c..b219cff 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -1903,6 +1903,11 @@ extern void find_default_create_inferior (struct target_ops *,
extern struct target_ops *find_target_beneath (struct target_ops *);
+/* Find the target at STRATUM. If no target is at that stratum,
+ return NULL. */
+
+struct target_ops *find_target_at (enum strata stratum);
+
/* Read OS data object of type TYPE from the target, and return it in
XML format. The result is NUL-terminated and returned as a string,
allocated using xmalloc. If an error occurs or the transfer is
--
1.8.1.4