Demangling broken (was: Re: [PATCH] Demangler woes with current CVS and type names)

H . J . Lu hjl@lucon.org
Thu Jan 31 17:20:00 GMT 2002


On Thu, Jan 31, 2002 at 07:32:10PM -0500, Andrew Cagney wrote:
> > 
> > Can we add
> > 
> > /* V3 ABI demangling entry points, defined in cp-demangle.c. Also
> >    demagle types. */
> > extern char*
> > cplus_demangle_v3_type PARAMS ((const char* mangled));
> > 
> > and only call cplus_demangle_v3_type from c++filt?
> 
> 
> Yes.  I think that was also Daniel's point.  Certainly play with a new 
> interface.  Just remember to preserve the semantics on the existing one.
> 

Here is a patch against my Linux binutils. It seems to work for me. I
can adapt it for the binutils in CVS.


H.J.
----
2002-01-31  H.J. Lu  (hjl@gnu.org)

	* demangle.h (cplus_demangle_v3_type): New prototype.

2002-01-31  H.J. Lu  (hjl@gnu.org)

	* cp-demangle.c (cplus_demangle_v3_all): New.
	(cplus_demangle_v3): Call cplus_demangle_v3_all.
	(cplus_demangle_v3_type): Call cplus_demangle_v3_all.

	* cplus-dem.c (cplus_demangle_v3_p): New function pointer.
	Initialized to cplus_demangle_v3.
	(cplus_demangle_with_style): Call cplus_demangle_v3_p instead
	of cplus_demangle_v3.
	(main): Set cplus_demangle_v3_p to cplus_demangle_v3_type for
	gnu_v3_demangling:

--- binutils/include/demangle.h.v3	Fri Dec  7 11:08:35 2001
+++ binutils/include/demangle.h	Thu Jan 31 16:24:59 2002
@@ -143,6 +143,11 @@ cplus_demangle_name_to_style PARAMS ((co
 extern char*
 cplus_demangle_v3 PARAMS ((const char* mangled));
 
+/* V3 ABI demangling entry points, defined in cp-demangle.c. Also
+   demagle types. */
+extern char*
+cplus_demangle_v3_type PARAMS ((const char* mangled));
+
 extern char*
 java_demangle_v3 PARAMS ((const char* mangled));
 
--- binutils/libiberty/cp-demangle.c.v3	Wed Jan 30 23:41:41 2002
+++ binutils/libiberty/cp-demangle.c	Thu Jan 31 16:45:44 2002
@@ -940,6 +940,8 @@ static status_t cp_demangle
   PARAMS ((const char *, dyn_string_t, int));
 static status_t cp_demangle_type
   PARAMS ((const char*, dyn_string_t));
+static char* cplus_demangle_v3_all
+  PARAMS ((const char*, int));
 
 /* When passed to demangle_bare_function_type, indicates that the
    function's return type is not encoded before its parameter types.  */
@@ -3688,13 +3690,38 @@ char *
 cplus_demangle_v3 (mangled)
      const char* mangled;
 {
+  return cplus_demangle_v3_all (mangled, 0);
+}
+
+char *
+cplus_demangle_v3_type (mangled)
+     const char* mangled;
+{
+  return cplus_demangle_v3_all (mangled, 1);
+}
+
+static char *
+cplus_demangle_v3_all (mangled, type)
+     const char* mangled;
+     int type;
+{
   dyn_string_t demangled;
   status_t status;
 
+  if (mangled[0] == '_' && mangled[1] == 'Z')
+    /* It is not a type.  */
+    type = 0;
+  else
+    {
+      /* It is a type. Stop if we don't want to demangle types. */
+      if (!type)
+	return NULL;
+    }
+
   /* Create a dyn_string to hold the demangled name.  */
   demangled = dyn_string_new (0);
   /* Attempt the demangling.  */
-  if (mangled[0] == '_' && mangled[1] == 'Z')
+  if (!type)
     /* Appears to be a function or variable name.  */
     status = cp_demangle (mangled, demangled, 0);
   else
--- binutils/libiberty/cplus-dem.c.v3	Thu Jan 31 16:14:49 2002
+++ binutils/libiberty/cplus-dem.c	Thu Jan 31 16:48:36 2002
@@ -512,6 +512,9 @@ do_hpacc_template_literal PARAMS ((struc
 static int
 snarf_numeric_literal PARAMS ((const char **, string *));
 
+static char* (*cplus_demangle_v3_p) PARAMS ((const char* mangled))
+  = cplus_demangle_v3;
+
 /* There is a TYPE_QUAL value for each type qualifier.  They can be
    combined by bitwise-or to form the complete set of qualifiers for a
    type.  */
@@ -946,7 +949,7 @@ cplus_demangle_with_style (mangled, styl
   if (libiberty_demanglers [style].demangling_style
       & (DMGL_GNU_V3 | DMGL_AUTO))
     {
-      ret = cplus_demangle_v3 (mangled);
+      ret = cplus_demangle_v3_p (mangled);
       if (ret || (libiberty_demanglers [style].demangling_style
 		  & DMGL_GNU_V3))
 	return ret;
@@ -5354,6 +5357,7 @@ main (argc, argv)
 	  break;
 	case gnu_v3_demangling:
 	  valid_symbols = gnu_v3_symbol_characters ();
+	  cplus_demangle_v3_p = cplus_demangle_v3_type;
 	  break;
 	default:
 	  /* Folks should explicitly indicate the appropriate alphabet for



More information about the Binutils mailing list