Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [patch] libiberty: demangle_component for `global  {constructors,destructors} keyed to'
@ 2009-07-11 23:29 Jan Kratochvil
  2009-07-14 14:58 ` Ian Lance Taylor
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kratochvil @ 2009-07-11 23:29 UTC (permalink / raw)
  To: gcc-patches; +Cc: binutils, gdb-patches

Hi,

asking if this patch gets accepted to be able to clean up gdb/cp-name-parser.y.
GDB has now a gcc-4.5 enum comparison warning:
	http://sourceware.org/ml/gdb-patches/2009-07/msg00323.html

GDB would benefit only from the include/ and d_print_comp part of the patch.
The d_demangle_callback part just tries to use it, it can be safely dropped.

There still remains s similiar but more complicated _GLOBAL_$[ID]$ demangler
in libiberty/cplus-dem.c.

Regression tested gcc, binutils and gdb on x86_64-fedora11-linux-gnu.
(I do not have the gcc svn check-in technical rights.)


Thanks,
Jan


include/
2009-07-11  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* demangle.h
	(enum demangle_component_type <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
	(enum demangle_component_type <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS>):
	New.

libiberty/
2009-07-11  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* cp-demangle.c (d_print_comp <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
	(d_print_comp <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS): New.
	(d_make_comp <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
	(d_make_comp <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS): New.
	(d_demangle_callback): The variable type is now declared as enum.
	Replace parser of _GLOBAL_ symbols by a d_make_comp call.

--- a/include/demangle.h
+++ b/include/demangle.h
@@ -377,6 +377,10 @@ enum demangle_component_type
   DEMANGLE_COMPONENT_CHARACTER,
   /* A decltype type.  */
   DEMANGLE_COMPONENT_DECLTYPE,
+  /* Global constructors keyed to name.  */
+  DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS,
+  /* Global destructors keyed to name.  */
+  DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS,
   /* A pack expansion.  */
   DEMANGLE_COMPONENT_PACK_EXPANSION
 };
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -819,6 +819,8 @@ d_make_comp (struct d_info *di, enum demangle_component_type type,
     case DEMANGLE_COMPONENT_JAVA_RESOURCE:
     case DEMANGLE_COMPONENT_DECLTYPE:
     case DEMANGLE_COMPONENT_PACK_EXPANSION:
+    case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
+    case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
       if (left == NULL)
 	return NULL;
       break;
@@ -4054,6 +4056,16 @@ d_print_comp (struct d_print_info *dpi,
 	return;
       }
 
+    case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
+      d_append_string (dpi, "global constructors keyed to ");
+      d_print_comp (dpi, dc->u.s_binary.left);
+      return;
+
+    case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
+      d_append_string (dpi, "global destructors keyed to ");
+      d_print_comp (dpi, dc->u.s_binary.left);
+      return;
+
     default:
       d_print_error (dpi);
       return;
@@ -4484,33 +4496,30 @@ static int
 d_demangle_callback (const char *mangled, int options,
                      demangle_callbackref callback, void *opaque)
 {
-  int type;
+  enum
+    {
+      DCT_TYPE,
+      DCT_MANGLED,
+      DCT_GLOBAL_CTORS,
+      DCT_GLOBAL_DTORS
+    }
+  type;
   struct d_info di;
   struct demangle_component *dc;
   int status;
 
   if (mangled[0] == '_' && mangled[1] == 'Z')
-    type = 0;
+    type = DCT_MANGLED;
   else if (strncmp (mangled, "_GLOBAL_", 8) == 0
 	   && (mangled[8] == '.' || mangled[8] == '_' || mangled[8] == '$')
 	   && (mangled[9] == 'D' || mangled[9] == 'I')
 	   && mangled[10] == '_')
-    {
-      const char *intro;
-
-      intro = (mangled[9] == 'I')
-              ? "global constructors keyed to "
-              : "global destructors keyed to ";
-
-      callback (intro, strlen (intro), opaque);
-      callback (mangled + 11, strlen (mangled + 11), opaque);
-      return 1;
-    }
+    type = mangled[9] == 'I' ? DCT_GLOBAL_CTORS : DCT_GLOBAL_DTORS;
   else
     {
       if ((options & DMGL_TYPES) == 0)
 	return 0;
-      type = 1;
+      type = DCT_TYPE;
     }
 
   cplus_demangle_init_info (mangled, options, strlen (mangled), &di);
@@ -4527,10 +4536,25 @@ d_demangle_callback (const char *mangled, int options,
     di.subs = alloca (di.num_subs * sizeof (*di.subs));
 #endif
 
-    if (type)
-      dc = cplus_demangle_type (&di);
-    else
-      dc = cplus_demangle_mangled_name (&di, 1);
+    switch (type)
+      {
+      case DCT_TYPE:
+	dc = cplus_demangle_type (&di);
+	break;
+      case DCT_MANGLED:
+	dc = cplus_demangle_mangled_name (&di, 1);
+	break;
+      case DCT_GLOBAL_CTORS:
+      case DCT_GLOBAL_DTORS:
+	d_advance (&di, 11);
+	dc = d_make_comp (&di, type == DCT_GLOBAL_CTORS
+		               ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
+			       : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS,
+			  d_make_name (&di, d_str (&di), strlen (d_str (&di))),
+			  NULL);
+	d_advance (&di, strlen (d_str (&di)));
+	break;
+      }
 
     /* If DMGL_PARAMS is set, then if we didn't consume the entire
        mangled string, then we didn't successfully demangle it.  If


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] libiberty: demangle_component for `global  {constructors,destructors} keyed to'
  2009-07-11 23:29 [patch] libiberty: demangle_component for `global {constructors,destructors} keyed to' Jan Kratochvil
@ 2009-07-14 14:58 ` Ian Lance Taylor
  2009-07-18 13:50   ` Jan Kratochvil
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2009-07-14 14:58 UTC (permalink / raw)
  To: Jan Kratochvil; +Cc: gcc-patches, binutils, gdb-patches

Jan Kratochvil <jan.kratochvil@redhat.com> writes:

> include/
> 2009-07-11  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
> 	* demangle.h
> 	(enum demangle_component_type <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
> 	(enum demangle_component_type <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS>):
> 	New.
>
> libiberty/
> 2009-07-11  Jan Kratochvil  <jan.kratochvil@redhat.com>
>
> 	* cp-demangle.c (d_print_comp <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
> 	(d_print_comp <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS): New.
> 	(d_make_comp <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
> 	(d_make_comp <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS): New.
> 	(d_demangle_callback): The variable type is now declared as enum.
> 	Replace parser of _GLOBAL_ symbols by a d_make_comp call.
> +	dc = d_make_comp (&di, type == DCT_GLOBAL_CTORS
> +		               ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
> +			       : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS,
> +			  d_make_name (&di, d_str (&di), strlen (d_str (&di))),
> +			  NULL);

Format as

	dc = d_make_comp (&di,
			  (type == DCT_GLOBAL_CTORS
		           ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
			   : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS),
			  d_make_name (&di, d_str (&di), strlen (d_str (&di))),
			  NULL);

This is OK with that change.

I assume you ran the libiberty testsuite.

Thanks.

Ian


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] libiberty: demangle_component for `global  {constructors,destructors} keyed to'
  2009-07-14 14:58 ` Ian Lance Taylor
@ 2009-07-18 13:50   ` Jan Kratochvil
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kratochvil @ 2009-07-18 13:50 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gcc-patches, binutils, gdb-patches, Tom Tromey

On Tue, 14 Jul 2009 16:34:01 +0200, Ian Lance Taylor wrote:
> Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> 
> > include/
> > 2009-07-11  Jan Kratochvil  <jan.kratochvil@redhat.com>
> >
> > 	* demangle.h
> > 	(enum demangle_component_type <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
> > 	(enum demangle_component_type <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS>):
> > 	New.
> >
> > libiberty/
> > 2009-07-11  Jan Kratochvil  <jan.kratochvil@redhat.com>
> >
> > 	* cp-demangle.c (d_print_comp <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
> > 	(d_print_comp <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS): New.
> > 	(d_make_comp <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
> > 	(d_make_comp <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS): New.
> > 	(d_demangle_callback): The variable type is now declared as enum.
> > 	Replace parser of _GLOBAL_ symbols by a d_make_comp call.
> > +	dc = d_make_comp (&di, type == DCT_GLOBAL_CTORS
> > +		               ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
> > +			       : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS,
> > +			  d_make_name (&di, d_str (&di), strlen (d_str (&di))),
> > +			  NULL);
> 
> Format as
[...]
> This is OK with that change.

Checked in with this change by Tom Tromey.

(I will post the GDB change based on it next week.)


> I assume you ran the libiberty testsuite.

Yes, ran, no regressions.


Thanks,
Jan


http://gcc.gnu.org/ml/gcc-cvs/2009-07/msg00638.html
http://gcc.gnu.org/viewcvs?view=rev&revision=149756

--- trunk/include/ChangeLog	2009/07/17 18:49:03	149755
+++ trunk/include/ChangeLog	2009/07/17 19:09:54	149756
@@ -1,3 +1,10 @@
+2009-07-17  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* demangle.h
+	(enum demangle_component_type <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
+	(enum demangle_component_type <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS>):
+	New.
+
 2009-07-09  Jakub Jelinek  <jakub@redhat.com>
 
 	* dwarf2.h (enum dwarf_location_atom): Add DW_OP_implicit_value
--- trunk/include/demangle.h	2009/07/17 18:49:03	149755
+++ trunk/include/demangle.h	2009/07/17 19:09:54	149756
@@ -377,6 +377,10 @@
   DEMANGLE_COMPONENT_CHARACTER,
   /* A decltype type.  */
   DEMANGLE_COMPONENT_DECLTYPE,
+  /* Global constructors keyed to name.  */
+  DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS,
+  /* Global destructors keyed to name.  */
+  DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS,
   /* A pack expansion.  */
   DEMANGLE_COMPONENT_PACK_EXPANSION
 };
--- trunk/libiberty/ChangeLog	2009/07/17 18:49:03	149755
+++ trunk/libiberty/ChangeLog	2009/07/17 19:09:54	149756
@@ -1,3 +1,12 @@
+2009-07-17  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	* cp-demangle.c (d_print_comp <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
+	(d_print_comp <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS): New.
+	(d_make_comp <DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS>)
+	(d_make_comp <DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS): New.
+	(d_demangle_callback): The variable type is now declared as enum.
+	Replace parser of _GLOBAL_ symbols by a d_make_comp call.
+
 2009-06-21  Jakub Jelinek  <jakub@redhat.com>
 
 	* hashtab.c (htab_traverse): Don't call htab_expand for
--- trunk/libiberty/cp-demangle.c	2009/07/17 18:49:03	149755
+++ trunk/libiberty/cp-demangle.c	2009/07/17 19:09:54	149756
@@ -819,6 +819,8 @@
     case DEMANGLE_COMPONENT_JAVA_RESOURCE:
     case DEMANGLE_COMPONENT_DECLTYPE:
     case DEMANGLE_COMPONENT_PACK_EXPANSION:
+    case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
+    case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
       if (left == NULL)
 	return NULL;
       break;
@@ -4054,6 +4056,16 @@
 	return;
       }
 
+    case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS:
+      d_append_string (dpi, "global constructors keyed to ");
+      d_print_comp (dpi, dc->u.s_binary.left);
+      return;
+
+    case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS:
+      d_append_string (dpi, "global destructors keyed to ");
+      d_print_comp (dpi, dc->u.s_binary.left);
+      return;
+
     default:
       d_print_error (dpi);
       return;
@@ -4484,33 +4496,30 @@
 d_demangle_callback (const char *mangled, int options,
                      demangle_callbackref callback, void *opaque)
 {
-  int type;
+  enum
+    {
+      DCT_TYPE,
+      DCT_MANGLED,
+      DCT_GLOBAL_CTORS,
+      DCT_GLOBAL_DTORS
+    }
+  type;
   struct d_info di;
   struct demangle_component *dc;
   int status;
 
   if (mangled[0] == '_' && mangled[1] == 'Z')
-    type = 0;
+    type = DCT_MANGLED;
   else if (strncmp (mangled, "_GLOBAL_", 8) == 0
 	   && (mangled[8] == '.' || mangled[8] == '_' || mangled[8] == '$')
 	   && (mangled[9] == 'D' || mangled[9] == 'I')
 	   && mangled[10] == '_')
-    {
-      const char *intro;
-
-      intro = (mangled[9] == 'I')
-              ? "global constructors keyed to "
-              : "global destructors keyed to ";
-
-      callback (intro, strlen (intro), opaque);
-      callback (mangled + 11, strlen (mangled + 11), opaque);
-      return 1;
-    }
+    type = mangled[9] == 'I' ? DCT_GLOBAL_CTORS : DCT_GLOBAL_DTORS;
   else
     {
       if ((options & DMGL_TYPES) == 0)
 	return 0;
-      type = 1;
+      type = DCT_TYPE;
     }
 
   cplus_demangle_init_info (mangled, options, strlen (mangled), &di);
@@ -4527,10 +4536,26 @@
     di.subs = alloca (di.num_subs * sizeof (*di.subs));
 #endif
 
-    if (type)
-      dc = cplus_demangle_type (&di);
-    else
-      dc = cplus_demangle_mangled_name (&di, 1);
+    switch (type)
+      {
+      case DCT_TYPE:
+	dc = cplus_demangle_type (&di);
+	break;
+      case DCT_MANGLED:
+	dc = cplus_demangle_mangled_name (&di, 1);
+	break;
+      case DCT_GLOBAL_CTORS:
+      case DCT_GLOBAL_DTORS:
+	d_advance (&di, 11);
+	dc = d_make_comp (&di,
+			  (type == DCT_GLOBAL_CTORS
+			   ? DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS
+			   : DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS),
+			  d_make_name (&di, d_str (&di), strlen (d_str (&di))),
+			  NULL);
+	d_advance (&di, strlen (d_str (&di)));
+	break;
+      }
 
     /* If DMGL_PARAMS is set, then if we didn't consume the entire
        mangled string, then we didn't successfully demangle it.  If


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-07-18  5:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-11 23:29 [patch] libiberty: demangle_component for `global {constructors,destructors} keyed to' Jan Kratochvil
2009-07-14 14:58 ` Ian Lance Taylor
2009-07-18 13:50   ` Jan Kratochvil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox