This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/4] create named itset.


Hi,
This patch refactors adding new named itset a little bit, and adding a
new command to set the preference to resolve the duplicated itset when
adding new.

gdb:

2012-08-30  Yao Qi  <yao@codesourcery.com>

	* itset.c (duplicate_style_overwrite, duplicate_style_query): New.
	(duplicate_style): New.
	(defset_command): Move some code to ...
	(named_itset_create): ... here.  New.
	(_initialize_itset): Call add_setshow_enum_cmd to register
	"duplicate" command.

gdb/doc:

2012-08-30  Yao Qi  <yao@codesourcery.com>

	* gdb.texinfo (ITSET): Document on command 'set resolve-duplicate'.
---
 gdb/doc/gdb.texinfo |   12 ++++++++
 gdb/itset.c         |   79 ++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 72 insertions(+), 19 deletions(-)

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 0419e3c..5573e0d 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -5215,6 +5215,18 @@ specific numbers, such as 1, 3, but also can be range, like 4-8.
 (@value{GDBP}) info itsets 1 3 4-8
 @end smallexample
 
+@kindex set resolve-duplicate
+@kindex show resolve-duplicate
+@item set resolve-duplicate query
+When a new named itset is defined, which has already been defined before,
+@value{GDBN} will query whether to overwrite the existing named itset
+or dicard the new definition.
+
+@item set resolve-duplicate overwrite
+When a new named itset is defined, which has already been defined before,
+@value{GDBN} will overwrite the existing named itset with the new
+definition.
+
 @item @ref{maint info itsets}
 
 @end table
diff --git a/gdb/itset.c b/gdb/itset.c
index 5b3098e..6c14e6c 100644
--- a/gdb/itset.c
+++ b/gdb/itset.c
@@ -1998,15 +1998,63 @@ itset_is_static (struct itset *itset)
   return 1;
 }
 
+static const char duplicate_style_overwrite[] = "overwrite";
+static const char duplicate_style_query[] = "query";
+static const char *const duplicate_style_enums[] =
+{
+  duplicate_style_overwrite,
+  duplicate_style_query,
+  NULL,
+};
+static const char *duplicate_style = duplicate_style_overwrite;
+
+static void
+named_itset_create (char *set_name, char *spec)
+{
+  struct itset *itset;
+  struct named_itset *named_itset;
+  char *name = xstrdup (set_name);
+  struct cleanup *old_chain = make_cleanup (xfree, name);
+  int found = 0;
+
+  named_itset = get_named_itset (name);
+  found = (named_itset != NULL);
+  if (found && duplicate_style == duplicate_style_query)
+    {
+      if (query (_("Overwrite '%s' from '%s' to '%s'?"), name,
+		 itset_spec (named_itset->set), spec))
+	return;
+    }
+
+  itset = itset_create (&spec);
+  make_cleanup_itset_free (itset);
+
+  if (itset_is_static (itset) && itset_is_empty (itset))
+    warning (_("static itset is empty"));
+
+  if (found)
+    {
+      itset_free (named_itset->set);
+      itset_reference (itset);
+      named_itset->set = itset;
+      itset->name = name;
+    }
+  else
+    named_itset = make_itset_named_itset (itset, name, 0);
+
+  itset_free (itset);
+  discard_cleanups (old_chain);
+
+  if (!found)
+    add_to_named_itset_chain (named_itset);
+}
+
 static void
 defset_command (char *arg, int from_tty)
 {
   char *endp;
   char *name;
   char *spec;
-  struct itset *itset;
-  struct named_itset *named_itset;
-  struct cleanup *old_chain;
 
   if (arg == NULL || *arg == '\0')
     error_no_arg (_("no args"));
@@ -2017,24 +2065,9 @@ defset_command (char *arg, int from_tty)
   spec = endp;
 
   name = xstrndup (arg, endp - arg);
-  old_chain = make_cleanup (xfree, name);
-
-  named_itset = get_named_itset (name);
-  if (named_itset != NULL)
-    error (_("itset %s already exists"), name);
-
   spec = skip_spaces (spec);
 
-  itset = itset_create (&spec);
-  make_cleanup_itset_free (itset);
-
-  if (itset_is_static (itset) && itset_is_empty (itset))
-    warning (_("static itset is empty"));
-
-  named_itset = make_itset_named_itset (itset, name, 0);
-  itset_free (itset);
-  discard_cleanups (old_chain);
-  add_to_named_itset_chain (named_itset);
+  named_itset_create (name, spec);
 }
 
 static void
@@ -2377,4 +2410,12 @@ Usage: info itsets [NUMBERS AND/OR RANGES]\n"));
   add_cmd ("itsets", class_maintenance, maintenance_info_itsets_command, _("\
 Display the list of all defined named itsets, user-defined and built-in.\n"),
   &maintenanceinfolist);
+
+  add_setshow_enum_cmd ("resolve-duplicate", class_support,
+			duplicate_style_enums, &duplicate_style, _("\
+Set the style of resolving adding duplicated itset."), _("\
+Show the style of resolving adding duplicated itset."), _("\
+This setting chooses how GDB will resolve duplicated itset."),
+			NULL, NULL,
+			&setlist, &showlist);
 }
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]