Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: [RFC/WIP PATCH 08/14] Add support for the '@' core operator
Date: Mon, 28 Nov 2011 15:40:00 -0000	[thread overview]
Message-ID: <20111128153937.17761.6716.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20111128153742.17761.21459.stgit@localhost6.localdomain6>

This adds support for the '@' operator as described in the series
description.  I've left this split into a separate patch, as I have
tend to think the syntax for filtering per core will end up different.
In any case, this adds support for set intersection, so I went ahead
with it anyway.
---
 gdb/itset.c |  298 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 291 insertions(+), 7 deletions(-)

diff --git a/gdb/itset.c b/gdb/itset.c
index 81a4911..bd2c74a 100644
--- a/gdb/itset.c
+++ b/gdb/itset.c
@@ -439,6 +439,213 @@ create_range_itset (int inf_first, int inf_last, int thr_first, int thr_last)
 
 \f
 
+/* An I/T set element representing a range of cores.  */
+
+struct itset_elt_core_range
+{
+  struct itset_elt base;
+
+  /* The first and last cores in this range.  If CORE_FIRST is
+     WILDCARD, then CORE_LAST is unused.  */
+  int core_first, core_last;
+};
+
+/* Implementation of `contains_inferior' method.  */
+
+static int
+core_range_contains_thread (struct itset_elt *base, struct thread_info *thr)
+{
+  struct itset_elt_core_range *core_range = (struct itset_elt_core_range *) base;
+  int core;
+
+  if (core_range->core_first == WILDCARD)
+    return 1;
+
+  core = target_core_of_thread (thr->ptid);
+  if (core_range->core_first <= core && core <= core_range->core_last)
+    return 1;
+
+  return 0;
+}
+
+/* Implementation of `contains_inferior' method.  */
+
+static int
+core_range_contains_inferior (struct itset_elt *base, struct inferior *inf)
+{
+  struct itset_elt_core_range *core_range = (struct itset_elt_core_range *) base;
+  struct thread_info *thr;
+
+  /* True if we find a thread of this inferior that is running on our
+     core range.  */
+  ALL_THREADS(thr)
+    {
+      /* It's cheaper to check the core range first, because looking
+	 up the a thread's inferior is O(n).  */
+      if (core_range_contains_thread (base, thr))
+	{
+	  struct inferior *thr_inf;
+
+	  thr_inf = get_thread_inferior (thr);
+	  if (thr_inf == inf)
+	    return 1;
+	}
+    }
+
+  return 0;
+}
+
+/* Implementation of `is_empty' method.  */
+
+static int
+core_range_is_empty (struct itset_elt *base)
+{
+  struct itset_elt_core_range *core_range = (struct itset_elt_core_range *) base;
+  struct inferior *inf;
+  struct thread_info *thr;
+
+  ALL_THREADS(thr)
+    {
+      if (core_range_contains_thread (base, thr))
+	return 0;
+    }
+
+  return 1;
+}
+
+static const struct itset_elt_vtable core_range_vtable =
+{
+  NULL,
+  core_range_contains_inferior,
+  core_range_contains_thread,
+  core_range_is_empty
+};
+
+/* Create a new `core_range' I/T set element.  */
+
+static struct itset_elt *
+create_core_range_itset (int core_first, int core_last)
+{
+  struct itset_elt_core_range *elt;
+
+  elt = XNEW (struct itset_elt_core_range);
+  elt->base.vtable = &core_range_vtable;
+  elt->core_first = core_first;
+  elt->core_last = core_last;
+
+  return (struct itset_elt *) elt;
+}
+
+\f
+
+/* An I/T set element representing an intersection of sets.  */
+
+struct itset_elt_intersect
+{
+  struct itset_elt base;
+
+  /* The elements that will be intersected.  */
+  VEC (itset_elt_ptr) *elements;
+};
+
+/* Implementation of `destroy' method.  */
+
+static void
+intersect_destroy (struct itset_elt *base)
+{
+  struct itset_elt_intersect *set = (struct itset_elt_intersect *) base;
+
+  VEC_free (itset_elt_ptr, set->elements);
+}
+
+/* Implementation of `contains_inferior' method.  */
+
+static int
+intersect_contains_inferior (struct itset_elt *base, struct inferior *inf)
+{
+  struct itset_elt_intersect *intersect = (struct itset_elt_intersect *) base;
+  struct itset_elt *elt;
+  int ix;
+
+  gdb_assert (!VEC_empty (itset_elt_ptr, intersect->elements));
+
+  for (ix = 0; VEC_iterate (itset_elt_ptr, intersect->elements, ix, elt); ++ix)
+    {
+      if (!elt->vtable->contains_inferior (elt, inf))
+	return 0;
+    }
+
+  return 1;
+}
+
+/* Implementation of `contains_inferior' method.  */
+
+static int
+intersect_contains_thread (struct itset_elt *base, struct thread_info *thr)
+{
+  struct itset_elt_intersect *intersect = (struct itset_elt_intersect *) base;
+  struct itset_elt *elt;
+  int ix;
+
+  gdb_assert (!VEC_empty (itset_elt_ptr, intersect->elements));
+
+  for (ix = 0; VEC_iterate (itset_elt_ptr, intersect->elements, ix, elt); ++ix)
+    {
+      if (!elt->vtable->contains_thread (elt, thr))
+	return 0;
+    }
+
+  return 1;
+}
+
+/* Implementation of `is_empty' method.  */
+
+static int
+intersect_is_empty (struct itset_elt *base)
+{
+  struct itset_elt_intersect *intersect = (struct itset_elt_intersect *) base;
+  struct inferior *inf;
+  struct thread_info *thr;
+
+  ALL_INFERIORS(inf)
+    {
+      if (intersect_contains_inferior (base, inf))
+	return 0;
+    }
+
+  ALL_THREADS(thr)
+    {
+      if (intersect_contains_thread (base, thr))
+	return 0;
+    }
+
+  return 1;
+}
+
+static const struct itset_elt_vtable intersect_vtable =
+{
+  intersect_destroy,
+  intersect_contains_inferior,
+  intersect_contains_thread,
+  intersect_is_empty
+};
+
+/* Create a new `intersect' I/T set element.  */
+
+static struct itset_elt_intersect *
+create_intersect_itset (void)
+{
+  struct itset_elt_intersect *elt;
+
+  elt = XNEW (struct itset_elt_intersect);
+  elt->base.vtable = &intersect_vtable;
+  elt->elements = NULL;
+
+  return elt;
+}
+
+\f
+
 /* An I/T set element representing all inferiors.  */
 
 struct itset_elt_all
@@ -655,19 +862,38 @@ struct itset_elt_state
 /* Implementation of `contains_inferior' method.  */
 
 static int
-state_contains_inferior (struct itset_elt *base, struct inferior *inf)
+state_contains_thread (struct itset_elt *base, struct thread_info *thr)
 {
-  return 1;
+  struct itset_elt_state *state = (struct itset_elt_state *) base;
+
+  return thr->state == state->state;
 }
 
 /* Implementation of `contains_inferior' method.  */
 
 static int
-state_contains_thread (struct itset_elt *base, struct thread_info *thr)
+state_contains_inferior (struct itset_elt *base, struct inferior *inf)
 {
   struct itset_elt_state *state = (struct itset_elt_state *) base;
+  struct thread_info *thr;
 
-  return thr->state == state->state;
+  /* True if we find a thread of this inferior that is in the state
+     we're interested in.  */
+  ALL_THREADS(thr)
+    {
+      /* It's cheaper to check the state first, because looking up the
+	 a thread's inferior is O(n).  */
+      if (state_contains_thread (base, thr))
+	{
+	  struct inferior *thr_inf;
+
+	  thr_inf = get_thread_inferior (thr);
+	  if (thr_inf == inf)
+	    return 1;
+	}
+    }
+
+  return 0;
 }
 
 /* Implementation of `is_empty' method.  */
@@ -991,6 +1217,46 @@ parse_range (char **textp)
   return elt;
 }
 
+\f
+/* Parse an I/T set range.  A range has the form F[:L][.T], where F is
+   the starting inferior, L is the ending inferior, and T is the
+   thread.  Updates RESULT with the new I/T set elements, and returns
+   an updated pointer into the spec.  Throws an exception on
+   error.  */
+
+struct itset_elt *
+parse_core_range (char **textp)
+{
+  int core_first, core_last;
+  char *text = *textp;
+
+  if (*text == '@')
+    ++text;
+
+  if (*text == '*')
+    {
+      core_first = WILDCARD;
+      core_last = WILDCARD;
+      ++text;
+    }
+  else
+    {
+      core_first = strtol (text, &text, 10);
+      if (*text == ':')
+	{
+	  ++text;
+	  if (!isdigit (*text))
+	    error (_("Expected digit in I/T set, at `%s'"), text);
+	  core_last = strtol (text, &text, 10);
+	}
+      else
+	core_last = core_first;
+    }
+
+  *textp = text;
+  return create_core_range_itset (core_first, core_last);
+}
+
 /* Parse a named I/T set.  Currently the only named sets which are
    recognized are `exec (NAME)', and `current'.  Updates RESULT with
    the new I/T set elements, and returns an updated pointer into the
@@ -1089,16 +1355,34 @@ make_cleanup_itset_free (struct itset *itset)
 static struct itset_elt *
 parse_one_element (char **spec)
 {
+  struct itset_elt *elt;
+
   *spec = skip_spaces (*spec);
 
   if (isdigit (**spec) || **spec == '*' || **spec == '.')
-    return parse_range (spec);
+    elt = parse_range (spec);
   else if (isalpha (**spec))
-    return parse_named (spec);
+    elt = parse_named (spec);
   else if (**spec == '~')
-    return parse_negated (spec);
+    elt = parse_negated (spec);
   else
     error (_("Invalid I/T syntax at `%s'"), *spec);
+
+  if (**spec == '@')
+    {
+      struct itset_elt_intersect *intersect;
+      struct itset_elt *core_range;
+
+      core_range = parse_core_range (spec);
+
+      intersect = create_intersect_itset ();
+      VEC_safe_push (itset_elt_ptr, intersect->elements, elt);
+      VEC_safe_push (itset_elt_ptr, intersect->elements, core_range);
+
+      return (struct itset_elt *) intersect;
+    }
+
+  return elt;
 }
 
 /* Parse an I/T set specification and return a new I/T set.  Throws an


  parent reply	other threads:[~2011-11-28 15:40 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-28 15:39 [RFC/WIP PATCH 00/14] I/T sets Pedro Alves
2011-11-28 15:39 ` [RFC/WIP PATCH 02/14] Mask software breakpoints from memory writes too Pedro Alves
2011-12-06 20:40   ` Pedro Alves
2011-12-13 21:26     ` Andreas Schwab
2011-12-13 21:38       ` Pedro Alves
2011-12-14  2:08         ` Andreas Schwab
2011-12-14 12:53           ` Pedro Alves
2011-12-14 12:53             ` Andreas Schwab
2011-12-14 15:06               ` Pedro Alves
2011-12-14 15:38                 ` Joel Brobecker
2011-11-28 15:39 ` [RFC/WIP PATCH 05/14] Add a small helper to get at a thread's inferior Pedro Alves
2011-11-29 21:19   ` Tom Tromey
2011-11-28 15:39 ` [RFC/WIP PATCH 01/14] Breakpoints always-inserted and the record target Pedro Alves
2011-11-29 21:09   ` Tom Tromey
2011-12-05 17:04     ` Pedro Alves
2011-11-28 15:39 ` [RFC/WIP PATCH 03/14] Flip to set target-async on by default Pedro Alves
2011-11-29 21:18   ` Tom Tromey
2011-12-02 19:16   ` Marc Khouzam
2011-11-28 15:40 ` [RFC/WIP PATCH 09/14] I/T set support for breakpoints - trigger set, and stop set Pedro Alves
2011-11-29 22:02   ` Tom Tromey
2011-11-30 19:38     ` Tom Tromey
2011-12-16 19:29     ` Pedro Alves
2011-11-28 15:40 ` [RFC/WIP PATCH 10/14] Comment out new info breakpoints output, in order to not break the test suite Pedro Alves
2011-11-28 15:40 ` [RFC/WIP PATCH 07/14] Expand %ITSET% in the prompt to the current I/T set Pedro Alves
2011-11-29 21:22   ` Tom Tromey
2011-12-16 19:07     ` Pedro Alves
2011-12-16 19:09       ` Tom Tromey
2011-12-16 19:38         ` Pedro Alves
2011-11-28 15:40 ` [RFC/WIP PATCH 04/14] Implement all-stop on top of a target running non-stop mode Pedro Alves
2011-11-28 15:40 ` [RFC/WIP PATCH 12/14] Fix deref of stale pointer Pedro Alves
2011-11-28 15:40 ` [RFC/WIP PATCH 13/14] Make "thread apply all" only loop over threads in the current set Pedro Alves
2011-11-28 18:40   ` Eli Zaretskii
2011-11-28 18:56     ` Pedro Alves
2011-11-29 21:47   ` Tom Tromey
2011-12-16 18:47     ` Pedro Alves
2011-11-28 15:40 ` Pedro Alves [this message]
2011-11-30 17:29   ` [RFC/WIP PATCH 08/14] Add support for the '@' core operator Tom Tromey
2011-11-28 15:45 ` [RFC/WIP PATCH 14/14] Fix manythreads.exp test Pedro Alves
2011-11-28 15:45 ` [RFC/WIP PATCH 06/14] Add base itsets support Pedro Alves
2011-11-28 18:47   ` Eli Zaretskii
2011-11-28 18:56     ` Pedro Alves
2011-11-29 22:07   ` Tom Tromey
2011-11-30 18:54   ` Tom Tromey
2011-12-16 17:26     ` Pedro Alves
2011-11-28 15:46 ` [RFC/WIP PATCH 11/14] Add I/T set support to most execution commands Pedro Alves
2011-11-30 19:27   ` Tom Tromey
2011-11-28 18:10 ` [RFC/WIP PATCH 00/14] I/T sets Pedro Alves
2011-11-30 19:35 ` Tom Tromey
2011-12-16 19:40   ` Pedro Alves
2012-02-09  7:51 ` Tomas Östlund
2012-02-09  8:19 ` [RFC/WIP PATCH 00/14] I/T sets (resend) Tomas Östlund
2012-02-09 14:36   ` Pedro Alves
2012-02-15  9:48     ` Tomas Östlund

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=20111128153937.17761.6716.stgit@localhost6.localdomain6 \
    --to=pedro@codesourcery.com \
    --cc=gdb-patches@sourceware.org \
    /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