public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-multi-inferior: itset bug- and error checking- fixes; add reference counting
@ 2010-09-09  1:47 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2010-09-09  1:47 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-multi-inferior has been updated
       via  34e20644151f6b9b37e1f9cc20756f3470d292bd (commit)
       via  2685066ab84702d8573c66c4680bf54edfc62286 (commit)
       via  5c22e372575132477c49db399170dc3b68eef933 (commit)
      from  c49bae564edecb93ef9f0c031f6f9b94fea66efa (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 34e20644151f6b9b37e1f9cc20756f3470d292bd
Author: Tom Tromey <tromey@redhat.com>
Date:   Wed Sep 8 13:05:23 2010 -0600

    itset bug- and error checking- fixes; add reference counting

commit 2685066ab84702d8573c66c4680bf54edfc62286
Author: Tom Tromey <tromey@redhat.com>
Date:   Wed Sep 8 11:53:07 2010 -0600

    small breakpoint exception-handling cleanup

commit 5c22e372575132477c49db399170dc3b68eef933
Author: Tom Tromey <tromey@redhat.com>
Date:   Wed Sep 8 11:52:40 2010 -0600

    minor API change for itset creation

-----------------------------------------------------------------------

Summary of changes:
 gdb/breakpoint.c |   31 ++-----------
 gdb/itset.c      |  129 +++++++++++++++++++++++++++++++++++++++++++++---------
 gdb/itset.h      |   34 +++++++++++++--
 3 files changed, 143 insertions(+), 51 deletions(-)

First 500 lines of diff:
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index aa18bdf..773e49e 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5671,14 +5671,6 @@ remove_thread_event_breakpoints (void)
       delete_breakpoint (b);
 }
 
-struct captured_parse_breakpoint_args
-  {
-    char **arg_p;
-    struct symtabs_and_lines *sals_p;
-    char ***addr_string_p;
-    int *not_found_ptr;
-  };
-
 struct lang_and_radix
   {
     enum language lang;
@@ -7301,15 +7293,6 @@ check_fast_tracepoint_sals (struct gdbarch *gdbarch,
     }
 }
 
-static void
-do_captured_parse_breakpoint (struct ui_out *ui, void *data)
-{
-  struct captured_parse_breakpoint_args *args = data;
-  
-  parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, 
-		         args->not_found_ptr);
-}
-
 /* Given TOK, a string specification of condition and thread, as
    accepted by the 'break' command, extract the condition
    string and thread number and set *COND_STRING and *THREAD.
@@ -7451,7 +7434,7 @@ create_breakpoint (struct gdbarch *gdbarch,
 		   int from_tty,
 		   int enabled)
 {
-  struct gdb_exception e;
+  volatile struct gdb_exception e;
   struct symtabs_and_lines sals;
   struct symtab_and_line pending_sal;
   char *copy_arg;
@@ -7459,7 +7442,6 @@ create_breakpoint (struct gdbarch *gdbarch,
   char **addr_string;
   struct cleanup *old_chain;
   struct cleanup *bkpt_chain = NULL;
-  struct captured_parse_breakpoint_args parse_args;
   int i;
   int pending = 0;
   int not_found = 0;
@@ -7470,11 +7452,6 @@ create_breakpoint (struct gdbarch *gdbarch,
   sals.nelts = 0;
   addr_string = NULL;
 
-  parse_args.arg_p = &arg;
-  parse_args.sals_p = &sals;
-  parse_args.addr_string_p = &addr_string;
-  parse_args.not_found_ptr = &not_found;
-
   if (type_wanted == bp_static_tracepoint && is_marker_spec (arg))
     {
       int i;
@@ -7488,8 +7465,10 @@ create_breakpoint (struct gdbarch *gdbarch,
       goto done;
     }
 
-  e = catch_exception (uiout, do_captured_parse_breakpoint, 
-		       &parse_args, RETURN_MASK_ALL);
+  TRY_CATCH (e, RETURN_MASK_ALL)
+    {
+      parse_breakpoint_sals (&arg, &sals, &addr_string, &not_found);
+    }
 
   /* If caller is interested in rc value from parse, set value.  */
   switch (e.reason)
diff --git a/gdb/itset.c b/gdb/itset.c
index 4b00d30..c35374c 100644
--- a/gdb/itset.c
+++ b/gdb/itset.c
@@ -63,6 +63,9 @@ struct itset
   /* The original specification of the set.  */
   const char *spec;
 
+  /* The reference count.  */
+  int refc;
+
   /* The elements making up the set.  */
   VEC (itset_base_ptr) *elements;
 };
@@ -390,6 +393,8 @@ parse_range (struct itset *result, const char *text)
       if (*text == ':')
 	{
 	  ++text;
+	  if (!isdigit (*text))
+	    error (_("Expected digit in I/T set, at `%s'"), text);
 	  inf_last = strtol (text, (char **) &text, 10);
 	}
       else
@@ -400,7 +405,12 @@ parse_range (struct itset *result, const char *text)
     {
       ++text;
       if (*text == '*')
-	thread = WILDCARD;
+	{
+	  thread = WILDCARD;
+	  ++text;
+	}
+      else if (!isdigit (*text))
+	error (_("Expected digit in I/T set, at `%s'"), text);
       else
 	thread = strtol (text, (char **) &text, 10);
     }
@@ -434,14 +444,14 @@ parse_named (struct itset *result, const char *text)
 
       text = skip_whitespace (text);
       if (*text != '(')
-	error ("'(' expected in I/T set after `exec'");
+	error (_("'(' expected in I/T set after `exec'"));
       text = skip_whitespace (text + 1);
       tem = strchr (text, ')');
       if (!tem)
-	error ("no closing ')' in I/T set for `exec'");
-      arg = xmalloc (tem - text + 1);
-      memcpy (arg, text, tem - text);
-      arg[tem - text] = '\0';
+	error (_("No closing ')' in I/T set for `exec'"));
+      if (tem - text == 0)
+	error (_("Empty argument to `exec' in I/T set"));
+      arg = xstrndup (text, tem - text);
       text = tem + 1;
       elt = create_exec_itset (arg);
     }
@@ -449,9 +459,9 @@ parse_named (struct itset *result, const char *text)
     {
       char *tem = alloca (text - name + 1);
 
-      memcpy (tem, text, text - name);
+      memcpy (tem, name, text - name);
       tem[text - name] = '\0';
-      error (_("unknown named I/T set: `%s'"), tem);
+      error (_("Unknown named I/T set: `%s'"), tem);
     }
 
   VEC_safe_push (itset_base_ptr, result->elements, elt);
@@ -461,7 +471,7 @@ parse_named (struct itset *result, const char *text)
 
 /* A cleanup function that calls itset_free.  */
 
-static void
+void
 itset_cleanup (void *d)
 {
   itset_free (d);
@@ -471,18 +481,18 @@ itset_cleanup (void *d)
    exception on error.  */
 
 struct itset *
-itset_create (const char *spec)
+itset_create (const char **specp)
 {
   int is_static = 0;
   struct itset *result;
   struct cleanup *cleanups;
+  const char *spec = *specp;
 
   if (*spec != '[')
-    error ("I/T set must start with `['");
+    error (_("I/T set must start with `['"));
 
-  result = XNEW (struct itset);
-  result->spec = xstrdup (spec);
-  result->elements = NULL;
+  result = XCNEW (struct itset);
+  result->refc = 1;
 
   cleanups = make_cleanup (itset_cleanup, result);
 
@@ -505,29 +515,49 @@ itset_create (const char *spec)
       else if (isalpha (*spec))
 	spec = parse_named (result, spec);
       else
-	error ("invalid I/T syntax at `%s'", spec);
+	error (_("Invalid I/T syntax at `%s'"), spec);
 
       spec = skip_whitespace (spec);
       if (*spec == ',')
 	++spec;
-      else
+      else if (*spec == ']')
 	break;
+      else
+	error (_("',' or ']' expected in I/T set, at `%s'"), spec);
     }
 
-  if (*spec != ']')
-    error ("I/T set must end with `]'");
+  /* Skip the ']'.  */
+  ++spec;
+
+  result->spec = xstrndup (*specp, spec - *specp);
+
+  *specp = skip_whitespace (spec);
 
   if (is_static)
     {
       struct itset_base *st = create_static_itset (result->elements);
 
       set_free (result->elements);
+      result->elements = NULL;
       VEC_safe_push (itset_base_ptr, result->elements, st);
     }
 
+  discard_cleanups (cleanups);
+
   return result;
 }
 
+/* Create a new I/T set which represents the current inferior, at the
+   time that this call is made.  */
+
+struct itset *
+itset_create_current (void)
+{
+  const char *spec = "[!current]";
+
+  return itset_create (&spec);
+}
+
 /* Return 1 if SET contains INF, 0 otherwise.  */
 
 int
@@ -536,12 +566,69 @@ itset_contains_inferior (struct itset *set, struct inferior *inf)
   return set_contains_inferior (set->elements, inf);
 }
 
+/* Acquire a new reference to an I/T set.  */
+
+struct itset *
+itset_reference (struct itset *itset)
+{
+  ++itset->refc;
+  return itset;
+}
+
 /* Destroy SET.  */
 
 void
 itset_free (struct itset *set)
 {
-  set_free (set->elements);
-  xfree ((char *) set->spec);
-  xfree (set);
+  if (--set->refc == 0)
+    {
+      set_free (set->elements);
+      xfree ((char *) set->spec);
+      xfree (set);
+    }
+}
+
+/* Helper struct for iterate_over_itset.  */
+
+struct iterate_data
+{
+  /* The I/T set we are using.  */
+  struct itset *itset;
+
+  /* The original callback  */
+  int (*callback) (struct inferior *, void *);
+
+  /* The data passed in to iterate_over_itset.  */
+  void *client_data;
+};
+
+/* Callback function for iterate_over_inferiors, used by
+   iterate_over_itset.  */
+
+static int
+iter_callback (struct inferior *inf, void *d)
+{
+  struct iterate_data *data = d;
+
+  if (itset_contains_inferior (data->itset, inf))
+    return data->callback (inf, data->client_data);
+
+  /* Keep going.  */
+  return 0;
+}
+
+/* Like iterate_over_inferiors, but iterate over only those inferiors
+   in ITSET.  */
+
+struct inferior *
+iterate_over_itset (struct itset *itset,
+		    int (*callback) (struct inferior *, void *), void *datum)
+{
+  struct iterate_data data;
+
+  data.itset = itset;
+  data.callback = callback;
+  data.client_data = datum;
+
+  return iterate_over_inferiors (iter_callback, &data);
 }
diff --git a/gdb/itset.h b/gdb/itset.h
index dfd283b..21d99b7 100644
--- a/gdb/itset.h
+++ b/gdb/itset.h
@@ -25,20 +25,46 @@ struct inferior;
    simply a set of inferiors and/or threads.  A set may be dynamic
    (the members are enumerated at the time of use) or static (the
    members are enumerated at the time of construction); but this
-   distinction is hidden from the callers.  */
+   distinction is hidden from the callers.  An I/T set object is
+   reference counted.  */
 
 struct itset;
 
 /* Create a new I/T set from a user specification.  The valid forms of
-   a specification are documented in the manual.  */
+   a specification are documented in the manual.  *SPEC is the input
+   specification, and it is updated to point to the first non-space
+   character after the end of the specification.  */
 
-struct itset *itset_create (const char *spec);
+struct itset *itset_create (const char **spec);
+
+/* Create a new I/T set which represents the current inferior, at the
+   time that this call is made.  */
+
+struct itset *itset_create_current (void);
 
 /* Return true if the inferior is contained in the I/T set.  */
+
 int itset_contains_inferior (struct itset *itset, struct inferior *inf);
 
-/* Free the I/T set.  */
+/* Acquire a new reference to an I/T set.  Returns the I/T set, for
+   convenience.  */
+
+struct itset *itset_reference (struct itset *itset);
+
+/* Release a reference to an I/T set.  */
 
 void itset_free (struct itset *itset);
 
+/* A cleanup function that calls itset_free.  */
+
+void itset_cleanup (void *itset);
+
+/* Like iterate_over_inferiors, but iterate over only those inferiors
+   in ITSET.  */
+
+struct inferior *iterate_over_itset (struct itset *itset,
+				     int (*callback) (struct inferior *,
+						      void *),
+				     void *data);
+
 #endif /* ITSET_H */


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-09-09  1:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-09  1:47 [SCM] archer-tromey-multi-inferior: itset bug- and error checking- fixes; add reference counting tromey

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).