[PATCH] automated demangling styles list.

H . J . Lu hjl@lucon.org
Wed Jun 12 16:03:00 GMT 2002


On Wed, Jun 12, 2002 at 04:30:21PM -0400, DJ Delorie wrote:
> 
> > If anyone is interested, I can provide a patch without the dlopen
> > change.
> 
> If you're trying to get your changes into the master repository, that
> would be a requirement.  Splitting it up into independent changes
> would help us review them - send the smallest and most likely to be
> approved first, so we can reduce the divergence until we get a chance
> to work through the more complicated ones.
> 

Here is the first patch. I have build gdb, binutils and gcc with it.
I added a few new demangle functions. I can take some of them out if
people don't like them.

I have some follow up patches which will fix the binutils for things
like

# nm -help
...
  -C, --demangle[=STYLE] Decode low-level symbol names into user-level names
                          The STYLE, if specified, can be `auto' (the default),
                          `gnu', 'lucid', 'arm', 'hp', 'edg' or 'gnu-new-abi'

There is no such a thing of "gnu-new-abi" and it misses "java", "gnat".
My patch uses the new function, get_demangler_list ().


H.J.
-------------- next part --------------
2002-06-12  H.J. Lu  (hjl@gnu.org)

	* demangle.h (demangling_styles): Renumbered.
	(demangle_function): New type.
	(demangler_engine): Restructured.
	(cplus_demangle_with_style): New prototype.
	(demangle_symbol): Likewise.
	(demangle_symbol_with_style): Likewise.
	(demangle_symbol_with_options): Likewise.
	(demangle_symbol_with_style_options): Likewise.
	(init_demangler): Likewise.
	(get_demangler_list): Likewise.

2002-06-12  H.J. Lu  (hjl@gnu.org)

	* cplus-dem.c (cplus_demangle_name_to_mnemonic): New prototype.
	(libiberty_demanglers): Restructured.
	(cplus_demangle_set_style): Likewise.
	(cplus_demangle_name_to_style): Likewise.
	(cplus_demangle_with_style): New function.
	(cplus_demangle_name_to_mnemonic): Likewise.
	(init_demangler): Likewise.
	(demangle_symbol): Likewise.
	(demangle_symbol_with_style): Likewise.
	(demangle_symbol_with_options): Likewise.
	(demangle_symbol_with_style_options): Likewise.
	(get_demangler_list): Likewise.
	(cplus_demangle): Call cplus_demangle_with_style with
	current_demangling_style.
	(flags): Removed.
	(print_demangler_list): Likewise.
	(usage): Use get_demangler_list ().
	(long_options): Add demangler.
	(main): Handle 'd'. Use o_style () for setting
	current_demangling_style. Call init_demangler ().

2002-06-12  H.J. Lu  (hjl@gnu.org)

	* demangle.c (set_demangling_command): Updated.
	(_initialize_demangler): Likewise.

--- binutils/include/demangle.h.demangle	Wed Feb  6 22:43:01 2002
+++ binutils/include/demangle.h	Wed Jun 12 14:46:06 2002
@@ -56,17 +56,18 @@
 
 extern enum demangling_styles
 {
-  no_demangling = -1,
-  unknown_demangling = 0,
-  auto_demangling = DMGL_AUTO,
-  gnu_demangling = DMGL_GNU,
-  lucid_demangling = DMGL_LUCID,
-  arm_demangling = DMGL_ARM,
-  hp_demangling = DMGL_HP,
-  edg_demangling = DMGL_EDG,
-  gnu_v3_demangling = DMGL_GNU_V3,
-  java_demangling = DMGL_JAVA,
-  gnat_demangling = DMGL_GNAT
+  first_demangling = 0,
+  no_demangling = 0,
+  auto_demangling,
+  gnu_demangling,
+  lucid_demangling,
+  arm_demangling,
+  hp_demangling,
+  edg_demangling,
+  gnu_v3_demangling,
+  java_demangling,
+  gnat_demangling,
+  unknown_demangling
 } current_demangling_style;
 
 /* Define string names for the various demangling styles. */
@@ -95,19 +96,30 @@ extern enum demangling_styles
 #define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
 #define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
 
+typedef char * (*demangle_function) PARAMS ((const char *,
+					     enum demangling_styles,
+					     int));
+
 /* Provide information about the available demangle styles. This code is
    pulled from gdb into libiberty because it is useful to binutils also.  */
 
-extern const struct demangler_engine
+extern struct demangler_engine
 {
   const char *const demangling_style_name;
-  const enum demangling_styles demangling_style;
+  const int demangling_style;
+  int demangling_options;
   const char *const demangling_style_doc;
+  demangle_function df;
 } libiberty_demanglers[];
 
 extern char *
 cplus_demangle PARAMS ((const char *mangled, int options));
 
+extern char *
+cplus_demangle_with_style PARAMS ((const char *mangled,
+				   enum demangling_styles style,
+				   int options));
+
 extern int
 cplus_demangle_opname PARAMS ((const char *opname, char *result, int options));
 
@@ -160,4 +172,27 @@ enum gnu_v3_dtor_kinds {
 extern enum gnu_v3_dtor_kinds
 	is_gnu_v3_mangled_dtor PARAMS ((const char *name));
 
+extern char *
+demangle_symbol PARAMS ((const char *mangled));
+
+extern char *
+demangle_symbol_with_style PARAMS ((const char *mangled,
+				    enum demangling_styles style));
+
+extern char *
+demangle_symbol_with_options PARAMS ((const char *mangled,
+				      int options));
+
+extern char *
+demangle_symbol_with_style_options PARAMS ((const char *mangled,
+					    enum demangling_styles style,
+					    int options));
+
+extern int
+init_demangler PARAMS ((const char *style, const char *options,
+			const char *demangler));
+
+extern const char *
+get_demangler_list PARAMS ((void));
+
 #endif	/* DEMANGLE_H */
--- binutils/libiberty/cplus-dem.c.demangle	Fri Mar  8 09:48:28 2002
+++ binutils/libiberty/cplus-dem.c	Wed Jun 12 15:54:27 2002
@@ -54,6 +54,8 @@ char * realloc ();
 #include "libiberty.h"
 
 static char *ada_demangle  PARAMS ((const char *, int));
+static int cplus_demangle_name_to_mnemonic
+  PARAMS ((const char *mnemonic));
 
 #define min(X,Y) (((X) < (Y)) ? (X) : (Y))
 
@@ -237,70 +239,86 @@ typedef enum type_kind_t
   tk_real
 } type_kind_t;
 
-const struct demangler_engine libiberty_demanglers[] =
+struct demangler_engine libiberty_demanglers[] =
 {
   {
     NO_DEMANGLING_STYLE_STRING,
-    no_demangling,
-    "Demangling disabled"
+    DMGL_NO_OPTS,
+    DMGL_NO_OPTS,
+    "Demangling disabled",
+    cplus_demangle_with_style
   }
   ,
   {
     AUTO_DEMANGLING_STYLE_STRING,
-      auto_demangling,
-      "Automatic selection based on executable"
+    DMGL_AUTO,
+    DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE,
+    "Automatic selection based on executable",
+    cplus_demangle_with_style
   }
   ,
   {
     GNU_DEMANGLING_STYLE_STRING,
-      gnu_demangling,
-      "GNU (g++) style demangling"
+    DMGL_GNU,
+    DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE,
+    "GNU (g++) style demangling",
+    cplus_demangle_with_style
   }
   ,
   {
     LUCID_DEMANGLING_STYLE_STRING,
-      lucid_demangling,
-      "Lucid (lcc) style demangling"
+    DMGL_LUCID,
+    DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE,
+    "Lucid (lcc) style demangling",
+    cplus_demangle_with_style
   }
   ,
   {
     ARM_DEMANGLING_STYLE_STRING,
-      arm_demangling,
-      "ARM style demangling"
+    DMGL_ARM,
+    DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE,
+    "ANSI style demangling",
+    cplus_demangle_with_style
   }
   ,
   {
     HP_DEMANGLING_STYLE_STRING,
-      hp_demangling,
-      "HP (aCC) style demangling"
+    DMGL_HP,
+    DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE,
+    "HP (aCC) style demangling",
+    cplus_demangle_with_style
   }
   ,
   {
     EDG_DEMANGLING_STYLE_STRING,
-      edg_demangling,
-      "EDG style demangling"
+    DMGL_EDG,
+    DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE,
+    "EDG style demangling",
+    cplus_demangle_with_style
   }
   ,
   {
     GNU_V3_DEMANGLING_STYLE_STRING,
-    gnu_v3_demangling,
-    "GNU (g++) V3 ABI-style demangling"
+    DMGL_GNU_V3,
+    DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE,
+    "GNU (g++) V3 ABI-style demangling",
+    cplus_demangle_with_style
   }
   ,
   {
     JAVA_DEMANGLING_STYLE_STRING,
-    java_demangling,
-    "Java style demangling"
+    DMGL_JAVA,
+    DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE,
+    "Java style demangling",
+    cplus_demangle_with_style
   }
   ,
   {
     GNAT_DEMANGLING_STYLE_STRING,
-    gnat_demangling,
-    "GNAT style demangling"
-  }
-  ,
-  {
-    NULL, unknown_demangling, NULL
+    DMGL_GNAT,
+    DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE,
+    "GNAT (ada) style demangling",
+    cplus_demangle_with_style,
   }
 };
 
@@ -837,14 +855,11 @@ enum demangling_styles
 cplus_demangle_set_style (style)
      enum demangling_styles style;
 {
-  const struct demangler_engine *demangler = libiberty_demanglers; 
-
-  for (; demangler->demangling_style != unknown_demangling; ++demangler)
-    if (style == demangler->demangling_style)
-      {
-	current_demangling_style = style;
-	return current_demangling_style;
-      }
+  if (style < unknown_demangling)
+    {
+      current_demangling_style = style;
+      return current_demangling_style;
+    }
 
   return unknown_demangling;
 }
@@ -855,13 +870,14 @@ enum demangling_styles
 cplus_demangle_name_to_style (name)
      const char *name;
 {
-  const struct demangler_engine *demangler = libiberty_demanglers; 
+  enum demangling_styles i;
 
-  for (; demangler->demangling_style != unknown_demangling; ++demangler)
-    if (strcmp (name, demangler->demangling_style_name) == 0)
-      return demangler->demangling_style;
+  for (i = 0; i < unknown_demangling; i++)
+    if (strcasecmp (libiberty_demanglers [i].demangling_style_name,
+		    name) == 0)
+      break;
 
-  return unknown_demangling;
+  return i;
 }
 
 /* char *cplus_demangle (const char *mangled, int options)
@@ -893,38 +909,42 @@ cplus_demangle_name_to_style (name)
    MANGLED.  */
 
 char *
-cplus_demangle (mangled, options)
+cplus_demangle_with_style (mangled, style, options)
      const char *mangled;
+     enum demangling_styles style;
      int options;
 {
   char *ret;
   struct work_stuff work[1];
 
-  if (current_demangling_style == no_demangling)
+  if (style == no_demangling)
     return xstrdup (mangled);
 
   memset ((char *) work, 0, sizeof (work));
   work->options = options;
   if ((work->options & DMGL_STYLE_MASK) == 0)
-    work->options |= (int) current_demangling_style & DMGL_STYLE_MASK;
+    work->options |= libiberty_demanglers [style].demangling_style
+		     & DMGL_STYLE_MASK;
 
   /* The V3 ABI demangling is implemented elsewhere.  */
-  if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
+  if (libiberty_demanglers [style].demangling_style
+      & (DMGL_GNU_V3 | DMGL_AUTO))
     {
       ret = cplus_demangle_v3 (mangled, work->options);
-      if (ret || GNU_V3_DEMANGLING)
+      if (ret || (libiberty_demanglers [style].demangling_style
+		  & DMGL_GNU_V3))
 	return ret;
     }
 
-  if (JAVA_DEMANGLING)
+  if (libiberty_demanglers [style].demangling_style & DMGL_JAVA)
     {
       ret = java_demangle_v3 (mangled);
       if (ret)
-        return ret;
+	return ret;
     }
 
-  if (GNAT_DEMANGLING)
-    return ada_demangle(mangled,options);
+  if (libiberty_demanglers [style].demangling_style & DMGL_GNAT)
+    return ada_demangle (mangled, options);
 
   ret = internal_cplus_demangle (work, mangled);
   squangle_mop_up (work);
@@ -1065,6 +1085,114 @@ ada_demangle (mangled, option)
   return demangled;
 }
 
+char *
+cplus_demangle (mangled, options)
+     const char *mangled;
+     int options;
+{
+  return cplus_demangle_with_style (mangled, current_demangling_style,
+  				    options);
+}
+
+static int
+cplus_demangle_name_to_mnemonic (mnemonic)
+     const char *mnemonic;
+{
+  enum demangling_styles i;
+
+  for (i = 0; i < unknown_demangling; i++)
+    if (strcasecmp (libiberty_demanglers [i].demangling_style_name,
+		    mnemonic) == 0)
+      break;
+
+  if (i != unknown_demangling)
+    return libiberty_demanglers [i].demangling_style;
+  else
+    {
+      if (strncasecmp (mnemonic, "PARAMS", sizeof ("PARAMS") - 1) == 0)
+	return DMGL_PARAMS;
+      else 
+	return DMGL_NO_OPTS;
+    }
+}
+
+int
+init_demangler (style, options, demangler)
+     const char *style;
+     const char *options;
+     const char *demangler ATTRIBUTE_UNUSED;
+{
+  /* Initialize demangler_list_buffer. */
+  (void) get_demangler_list ();
+
+  if (style != NULL)
+    {
+      current_demangling_style = cplus_demangle_name_to_style (style);
+      if (current_demangling_style == unknown_demangling)
+	{
+	  fprintf (stderr, "init_demangler: unknown demangling style `%s'\n",
+		   style);
+	  exit (1);
+	}
+    }
+
+  if (options != NULL)
+    {
+      const char *cp;
+      int demangler_options = 0;
+
+      for (cp = options; *cp; )
+	{
+	  if (*cp == ';')
+	    cp++;
+	  demangler_options |= cplus_demangle_name_to_mnemonic (cp);
+	  while (*cp && *cp != ':')
+	    cp++;
+	}
+
+      libiberty_demanglers [current_demangling_style].demangling_options
+	= demangler_options;
+    }
+
+  return 0;
+}
+
+char *
+demangle_symbol (mangled)
+     const char *mangled;
+{
+  return demangle_symbol_with_style (mangled,
+  				     current_demangling_style);
+}
+
+char *
+demangle_symbol_with_style (mangled, style)
+     const char *mangled;
+     enum demangling_styles style;
+{
+  return demangle_symbol_with_style_options
+	  (mangled, style,
+	   libiberty_demanglers [style].demangling_options);
+}
+
+char *
+demangle_symbol_with_options (mangled, options)
+     const char *mangled;
+     int options;
+{
+  return demangle_symbol_with_style_options
+	  (mangled, current_demangling_style, options);
+}
+
+char *
+demangle_symbol_with_style_options (mangled, style, options)
+     const char *mangled;
+     enum demangling_styles style;
+     int options;
+{
+  return (*libiberty_demanglers [style].df) (mangled, style, options);
+}
+
 /* This function performs most of what cplus_demangle use to do, but
    to be able to demangle a name with a B, K or n code, we need to
    have a longer term memory of what types have been seen. The original
@@ -4881,6 +5009,48 @@ string_append_template_idx (s, idx)
   string_append (s, buf);
 }
 
+static const char * demangler_list = NULL;
+
+/* The buffer should be big enough to hold the list. */
+static char demangler_list_buffer [128];
+
+const char *
+get_demangler_list ()
+{
+  enum demangling_styles i;
+  int start, len, left;
+
+  if (!demangler_list)
+    {
+      demangler_list = demangler_list_buffer;
+      demangler_list_buffer [0] = '{';
+
+      start = 1;
+      left = sizeof (demangler_list_buffer) - start;
+  
+      for (i = 0; i < unknown_demangling && left > 0; i++)
+	{
+	  strncpy (&demangler_list_buffer [start],
+		   libiberty_demanglers [i].demangling_style_name, left);
+	  len = strlen (libiberty_demanglers [i].demangling_style_name);
+	  start += len;
+    	  if (left > 0)
+	    {
+	      demangler_list_buffer [start] = ',';
+	      start++;
+	      left -= len + 1;
+	    }
+	}
+
+      if (left >= 0)
+	{
+	  demangler_list_buffer [--start] = '}';  
+	}
+    }
+
+  return demangler_list;
+}
+
 /* To generate a standalone demangler program for testing purposes,
    just compile and link this file with -DMAIN and libiberty.a.  When
    run, it demangles each command line arg, or each stdin string, and
@@ -4892,12 +5062,10 @@ string_append_template_idx (s, idx)
 
 static const char *program_name;
 static const char *program_version = VERSION;
-static int flags = DMGL_PARAMS | DMGL_ANSI | DMGL_VERBOSE;
 
 static void demangle_it PARAMS ((char *));
 static void usage PARAMS ((FILE *, int)) ATTRIBUTE_NORETURN;
 static void fatal PARAMS ((const char *)) ATTRIBUTE_NORETURN;
-static void print_demangler_list PARAMS ((FILE *));
 
 static void
 demangle_it (mangled_name)
@@ -4906,7 +5074,9 @@ demangle_it (mangled_name)
   char *result;
 
   /* For command line args, also try to demangle type encodings.  */
-  result = cplus_demangle (mangled_name, flags | DMGL_TYPES);
+  libiberty_demanglers [current_demangling_style].demangling_options
+    |= DMGL_TYPES;
+  result = demangle_symbol (mangled_name);
   if (result == NULL)
     {
       printf ("%s\n", mangled_name);
@@ -4918,22 +5088,6 @@ demangle_it (mangled_name)
     }
 }
 
-static void 
-print_demangler_list (stream)
-     FILE *stream;
-{
-  const struct demangler_engine *demangler; 
-
-  fprintf (stream, "{%s", libiberty_demanglers->demangling_style_name);
-  
-  for (demangler = libiberty_demanglers + 1;
-       demangler->demangling_style != unknown_demangling;
-       ++demangler)
-    fprintf (stream, ",%s", demangler->demangling_style_name);
-
-  fprintf (stream, "}");
-}
-
 static void
 usage (stream, status)
      FILE *stream;
@@ -4944,14 +5098,10 @@ Usage: %s [-_] [-n] [--strip-underscores
 	   program_name);
 
   fprintf (stream, "\
-       [-s ");
-  print_demangler_list (stream);
-  fprintf (stream, "]\n");
+       [-s %s]\n", get_demangler_list ());
 
   fprintf (stream, "\
-       [--format ");
-  print_demangler_list (stream);
-  fprintf (stream, "]\n");
+       [--format %s]\n", get_demangler_list ());
 
   fprintf (stream, "\
        [--help] [--version] [arg...]\n");
@@ -4969,6 +5119,7 @@ int strip_underscore = 0;
 static const struct option long_options[] = {
   {"strip-underscores", no_argument, 0, '_'},
   {"format", required_argument, 0, 's'},
+  {"demangler", required_argument, 0, 'd'},
   {"help", no_argument, 0, 'h'},
   {"no-strip-underscores", no_argument, 0, 'n'},
   {"version", no_argument, 0, 'v'},
@@ -5063,13 +5214,14 @@ main (argc, argv)
   char *result;
   int c;
   const char *valid_symbols;
-  enum demangling_styles style = auto_demangling;
+  const char *demangler = NULL;
+  const char *options = NULL;
 
   program_name = argv[0];
 
   strip_underscore = prepends_underscore;
 
-  while ((c = getopt_long (argc, argv, "_ns:", long_options, (int *) 0)) != EOF)
+  while ((c = getopt_long (argc, argv, "_ns:d:", long_options, (int *) 0)) != EOF)
     {
       switch (c)
 	{
@@ -5087,22 +5239,24 @@ main (argc, argv)
 	case '_':
 	  strip_underscore = 1;
 	  break;
+	case 'd':
+  	  demangler = optarg;
+	  break;
 	case 's':
-	  {
-	    style = cplus_demangle_name_to_style (optarg);
-	    if (style == unknown_demangling)
-	      {
-		fprintf (stderr, "%s: unknown demangling style `%s'\n",
-			 program_name, optarg);
-		return (1);
-	      }
-	    else
-	      cplus_demangle_set_style (style);
-	  }
+	  current_demangling_style
+	    = cplus_demangle_name_to_style (optarg);
+	  if (current_demangling_style == unknown_demangling)
+	    {
+	      fprintf (stderr, "%s: unknown demangling style `%s'\n",
+		       program_name, optarg);
+	      return (1);
+	    }
 	  break;
 	}
     }
 
+  init_demangler (NULL, options, demangler);
+
   if (optind < argc)
     {
       for ( ; optind < argc; optind++)
@@ -5161,8 +5315,7 @@ main (argc, argv)
 		skip_first = i;
 
 	      mbuffer[i] = 0;
-	      flags |= (int) style;
-	      result = cplus_demangle (mbuffer + skip_first, flags);
+	      result = demangle_symbol (mbuffer + skip_first);
 	      if (result)
 		{
 		  if (mbuffer[0] == '.')
--- src/gdb/demangle.c.linux	Fri Jul 13 21:41:58 2001
+++ src/gdb/demangle.c	Fri Jul 13 22:33:21 2001
@@ -76,21 +76,19 @@ static void set_demangling_command (char
 static void
 set_demangling_command (char *ignore, int from_tty, struct cmd_list_element *c)
 {
-  const struct demangler_engine *dem;
+  enum demangling_styles i;
 
   /*  First just try to match whatever style name the user supplied with
      one of the known ones.  Don't bother special casing for an empty
      name, we just treat it as any other style name that doesn't match.
      If we match, update the current demangling style enum. */
 
-  for (dem = libiberty_demanglers; 
-       dem->demangling_style != unknown_demangling; 
-       dem++)
+  for (i = 0; i < unknown_demangling; i++)
     {
       if (STREQ (current_demangling_style_string,
-		 dem->demangling_style_name))
+		 libiberty_demanglers [i].demangling_style_name))
 	{
-	  current_demangling_style = dem->demangling_style;
+	  current_demangling_style = i;
 	  break;
 	}
     }
@@ -99,7 +97,7 @@ set_demangling_command (char *ignore, in
      style name and supply a list of valid ones.  FIXME:  This should
      probably be done with some sort of completion and with help. */
 
-  if (dem->demangling_style == unknown_demangling)
+  if (i == unknown_demangling)
     {
       if (*current_demangling_style_string != '\0')
 	{
@@ -107,18 +105,17 @@ set_demangling_command (char *ignore, in
 			     current_demangling_style_string);
 	}
       printf_unfiltered ("The currently understood settings are:\n\n");
-      for (dem = libiberty_demanglers; 
-	   dem->demangling_style != unknown_demangling; 
-	   dem++)
+      for (i = 0; i < unknown_demangling; i++)
 	{
-	  printf_unfiltered ("%-10s %s\n", dem->demangling_style_name,
-			     dem->demangling_style_doc);
-	  if (dem->demangling_style == current_demangling_style)
+	  printf_unfiltered ("%-10s %s\n",
+			     libiberty_demanglers [i].demangling_style_name,
+			     libiberty_demanglers [i].demangling_style_doc);
+	  if (i == current_demangling_style)
 	    {
 	      xfree (current_demangling_style_string);
 	      current_demangling_style_string =
-		savestring (dem->demangling_style_name,
-			    strlen (dem->demangling_style_name));
+		savestring (libiberty_demanglers [i].demangling_style_name,
+			    strlen (libiberty_demanglers [i].demangling_style_name));
 	    }
 	}
       if (current_demangling_style == unknown_demangling)
@@ -126,7 +123,7 @@ set_demangling_command (char *ignore, in
 	  /* This can happen during initialization if gdb is compiled with
 	     a DEMANGLING_STYLE value that is unknown, so pick the first
 	     one as the default. */
-	  current_demangling_style = libiberty_demanglers[0].demangling_style;
+	  current_demangling_style = 0;
 	  current_demangling_style_string =
 	    savestring (
               libiberty_demanglers[0].demangling_style_name,
@@ -179,17 +176,10 @@ void
 _initialize_demangler (void)
 {
   struct cmd_list_element *set, *show;
-  int i, ndems;
+  enum demangling_styles i;
 
-  /* Fill the demangling_style_names[] array.  */
-  for (ndems = 0;
-       libiberty_demanglers[ndems].demangling_style != unknown_demangling; 
-       ndems++)
-    ;
-  demangling_style_names = xcalloc (ndems + 1, sizeof (char *));
-  for (i = 0;
-       libiberty_demanglers[i].demangling_style != unknown_demangling; 
-       i++)
+  demangling_style_names = xcalloc (unknown_demangling + 1, sizeof (char *));
+  for (i = 0; i < unknown_demangling; i++)
     demangling_style_names[i] =
       xstrdup (libiberty_demanglers[i].demangling_style_name);
 


More information about the Binutils mailing list