This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

Patch to add trivial run-time demangler insertion


The motivation for this is to be able to add Borland style demangling, 
which is "rare", to gdb. Because the Borland style demangling is 
significantly different to the other demangling styles currently supported 
by libiberty, it is written as its own standalone module.

The combination of this format being rare and a separate module (as opposed 
to some conditions in the existing demangler) leads me to believe the 
Borland stuff probably should not be referenced directly by symbols in 
libiberty unless it is made explicitly target dependent (which seems to me 
to be inapproprite for libiberty).

The obvious alternative is a runtime hook mechanism, which is what is given 
below. I have also added Borland style demangling to the relevent defines 
and data structures.

include/ChangeLog:

2001-01-20  Troy Rollo <troy@rollo.com>

	* demangle.h: Add Borland style demangling entries,
	and prototypes for adding demangling styles at runtime.

libiberty/ChangeLog:

2001-01-20  Troy Rollo <troy@rollo.com>

	* cplus-dem.c (libiberty_demang): Add entry for Borland style
	demangling.

	* cplus-dem.c (cplus_demangle_add_demangler, find_runtime_demangler,
	cplus_demangle_opname, cplus_mangle_opname, cplus_demangle): Add
	functions for adding demangling styles at runtime.
Index: include/demangle.h
===================================================================
RCS file: /cvs/src/src/include/demangle.h,v
retrieving revision 1.4
diff -c -3 -p -r1.4 demangle.h
*** demangle.h	2000/12/05 16:49:47	1.4
--- demangle.h	2001/01/19 21:09:58
***************
*** 40,47 ****
   #define DMGL_GNU_V3	(1 << 14)
   #define DMGL_GNAT	(1 << 15)

   /* If none of these are set, use 'current_demangling_style' as the 
default. */
! #define DMGL_STYLE_MASK 
(DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT)

   /* Enumeration of possible demangling styles.

--- 40,49 ----
   #define DMGL_GNU_V3	(1 << 14)
   #define DMGL_GNAT	(1 << 15)

+ #define DMGL_BORLAND	(1 << 16)
+
   /* If none of these are set, use 'current_demangling_style' as the 
default. */
! #define DMGL_STYLE_MASK 
(DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_BORLAND)

   /* Enumeration of possible demangling styles.

*************** extern enum demangling_styles
*** 62,68 ****
     edg_demangling = DMGL_EDG,
     gnu_v3_demangling = DMGL_GNU_V3,
     java_demangling = DMGL_JAVA,
!   gnat_demangling = DMGL_GNAT
   } current_demangling_style;

   /* Define string names for the various demangling styles. */
--- 64,71 ----
     edg_demangling = DMGL_EDG,
     gnu_v3_demangling = DMGL_GNU_V3,
     java_demangling = DMGL_JAVA,
!   gnat_demangling = DMGL_GNAT,
!   borland_demangling = DMGL_BORLAND
   } current_demangling_style;

   /* Define string names for the various demangling styles. */
*************** extern enum demangling_styles
*** 76,81 ****
--- 79,85 ----
   #define GNU_V3_DEMANGLING_STYLE_STRING        "gnu-v3"
   #define JAVA_DEMANGLING_STYLE_STRING          "java"
   #define GNAT_DEMANGLING_STYLE_STRING          "gnat"
+ #define BORLAND_DEMANGLING_STYLE_STRING       "borland"

   /* Some macros to test what demangling style is active. */

*************** extern enum demangling_styles
*** 89,94 ****
--- 93,99 ----
   #define GNU_V3_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNU_V3)
   #define JAVA_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_JAVA)
   #define GNAT_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_GNAT)
+ #define BORLAND_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_BORLAND)

   /* Provide information about the available demangle styles. This code is
      pulled from gdb into libiberty because it is useful to binutils also.  */
*************** extern struct demangler_engine
*** 100,105 ****
--- 105,122 ----
     const char *demangling_style_doc;
   } libiberty_demanglers[];

+ /* Structure for adding a demangler to cplus_demangle at runtime */
+
+ struct runtime_demangler
+ {
+   enum demangling_styles demangling_style;
+   struct runtime_demangler *next;
+
+   char *(*demangle) PARAMS ((const char *mangled, int options));
+   int (*demangle_opname) PARAMS ((const char *opname, char *result, int 
options));
+   const char *(*mangle_opname) PARAMS ((const char *opname, int options));
+ };
+
   extern char *
   cplus_demangle PARAMS ((const char *mangled, int options));

*************** cplus_demangle_name_to_style PARAMS ((co
*** 123,127 ****
--- 140,147 ----
   /* V3 ABI demangling entry point, defined in cp-demangle.c.  */
   extern char*
   cplus_demangle_v3 PARAMS ((const char* mangled));
+
+ extern void
+ cplus_demangle_add_demangler PARAMS((struct runtime_demangler *demangler));

   #endif	/* DEMANGLE_H */
Index: libiberty/cplus-dem.c
===================================================================
RCS file: /cvs/src/src/libiberty/cplus-dem.c,v
retrieving revision 1.17
diff -c -3 -p -r1.17 cplus-dem.c
*** cplus-dem.c	2000/12/08 16:37:01	1.17
--- cplus-dem.c	2001/01/19 21:10:11
*************** struct demangler_engine libiberty_demang
*** 313,322 ****
--- 313,330 ----
     }
     ,
     {
+     BORLAND_DEMANGLING_STYLE_STRING,
+     borland_demangling,
+     "Borland style demangling"
+   }
+   ,
+   {
       NULL, unknown_demangling, NULL
     }
   };

+ static struct runtime_demangler *runtime_demangler_list = 0;
+
   #define STRING_EMPTY(str)	((str) -> b == (str) -> p)
   #define PREPEND_BLANK(str)	{if (!STRING_EMPTY(str)) \
       string_prepend(str, " ");}
*************** recursively_demangle PARAMS ((struct wor
*** 531,536 ****
--- 539,569 ----
   static void
   grow_vect PARAMS ((void **, size_t *, size_t, int));

+ /* Provide for applications to add in a rare demangler at runtime
+    without it adding bulk to libiberty */
+
+ void
+ cplus_demangle_add_demangler (demangler)
+      struct runtime_demangler *demangler;
+ {
+   demangler->next = runtime_demangler_list;
+   runtime_demangler_list = demangler;
+ }
+
+ static struct runtime_demangler *
+ find_runtime_demangler (demtype, olddem)
+      int demtype;
+      struct runtime_demangler *olddem;
+ {
+   struct runtime_demangler *demangler;
+
+   for (demangler = olddem ? olddem->next : runtime_demangler_list;
+        demangler && !(demtype & (int) demangler->demangling_style);
+        demangler = demangler->next);
+   return demangler;
+ }
+
+
   /* Translate count to integer, consuming tokens in the process.
      Conversion terminates on the first non-digit character.

*************** cplus_demangle_opname (opname, result, o
*** 695,700 ****
--- 728,734 ----
     string type;
     struct work_stuff work[1];
     const char *tem;
+   struct runtime_demangler *rtdem = 0;

     len = strlen(opname);
     result[0] = '\0';
*************** cplus_demangle_opname (opname, result, o
*** 702,707 ****
--- 736,754 ----
     memset ((char *) work, 0, sizeof (work));
     work->options = options;

+   while ((rtdem = find_runtime_demangler (((int) current_demangling_style 
| options)
+ 					  & DMGL_STYLE_MASK, rtdem)) != 0)
+     {
+       if (rtdem && rtdem->demangle_opname)
+ 	{
+ 	  ret = (*rtdem->demangle_opname)(opname, result, options);
+
+ 	  if (ret || ((((int) current_demangling_style | options)
+ 		       & DMGL_STYLE_MASK) == (int) rtdem->demangling_style))
+ 	    return ret;
+ 	}
+     }
+
     if (opname[0] == '_' && opname[1] == '_'
         && opname[2] == 'o' && opname[3] == 'p')
       {
*************** cplus_mangle_opname (opname, options)
*** 828,833 ****
--- 875,893 ----
   {
     size_t i;
     int len;
+   struct runtime_demangler *rtdem = 0;
+
+   while ((rtdem = find_runtime_demangler (((int) current_demangling_style 
| options) & DMGL_STYLE_MASK, rtdem)) != 0)
+     {
+       if (rtdem && rtdem->mangle_opname)
+ 	{
+ 	  const char *ret = (*rtdem->mangle_opname)(opname, options);
+
+ 	  if (ret || ((((int) current_demangling_style | options)
+ 	               & DMGL_STYLE_MASK) == (int) rtdem->demangling_style))
+ 	    return ret;
+ 	}
+     }

     len = strlen (opname);
     for (i = 0; i < ARRAY_SIZE (optable); i++)
*************** cplus_demangle (mangled, options)
*** 908,919 ****
--- 968,990 ----
        int options;
   {
     char *ret;
+   struct runtime_demangler *rtdem = 0;
+
     struct work_stuff work[1];
     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;

+   while ((rtdem = find_runtime_demangler (work->options & 
DMGL_STYLE_MASK, rtdem)) != 0)
+     {
+       if (rtdem && rtdem->demangle)
+ 	{
+ 	  ret = (*rtdem->demangle)(mangled, work->options);
+ 	  if (ret || ((work->options & DMGL_STYLE_MASK) == (int) 
rtdem->demangling_style))
+ 	    return ret;
+ 	}
+     }
     /* The V3 ABI demangling is implemented elsewhere.  */
     if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
       {


______________________________________________________________________________
troy@rollo.com				         Troy Rollo, Sydney, Australia
       Fight spam in Australia - Join CAUBE.AU - http://www.caube.org.au/



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