Re: [PATCH] Add D demangling support to libiberty

2014-10-14 Thread Joel Brobecker
Hello Ian,

 libiberty/ChangeLog
 2014-08-05  Iain Buclaw  ibuc...@gdcproject.org
 
 * Makefile.in (CFILES): Add d-demangle.c.
 (REQUIRED_OFILES): Add d-demangle.o.
 * cplus-dem.c (libiberty_demanglers): Add dlang_demangling case.
 (cplus_demangle): Likewise.
 * d-demangle.c: New file.
 * testsuite/Makefile.in (really-check): Add check-d-demangle.
 * testsuite/d-demangle-expected: New file.

As hinted on gdb-patches, this patch causes a GDB build failure
on Solaris 2.9, because it uses strtold which is not available.
According to gnulib's documentation, it should also break on
the following systems:

NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, IRIX 6.5, OSF/1 4.0,
Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.

This patch attempts to fix the issue by adding a configure check
for strtold and adjusts the code to use strtod if strtold does not
exist.

Does this look OK to you? If yes, can one of the GCC maintainers
please review?

libiberty/ChangeLog:

* configure.ac: Add check for strtold's availability.
* configure, config.in: Regenerate.
* d-demangle.c [!HAVE_STRTOLD]: #define strtold to strtod.

Thank you!

-- 
Joel
From 9e4d74607075ef857dfa4e118f43641494aaff90 Mon Sep 17 00:00:00 2001
From: Joel Brobecker brobec...@adacore.com
Date: Tue, 14 Oct 2014 09:54:05 -0400
Subject: [PATCH] libiberty: fallback on strtod if strtold is not available.

This patch fixes a build failurer on Solaris 2.9, and all other
systems that do not provide strtold.

libiberty/ChangeLog:

* configure.ac: Add check for strtold's availability.
* configure, config.in: Regenerate.
* d-demangle.c [!HAVE_STRTOLD]: #define strtold to strtod.
---
 libiberty/config.in| 3 +++
 libiberty/configure| 2 +-
 libiberty/configure.ac | 2 +-
 libiberty/d-demangle.c | 3 +++
 4 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/libiberty/configure.ac b/libiberty/configure.ac
index 3380819..da20a5f 100644
--- a/libiberty/configure.ac
+++ b/libiberty/configure.ac
@@ -401,7 +401,7 @@ if test x = y; then
 sbrk setenv setproctitle setrlimit sigsetmask snprintf spawnve spawnvpe \
  stpcpy stpncpy strcasecmp strchr strdup \
  strerror strncasecmp strndup strnlen strrchr strsignal strstr strtod \
- strtol strtoul strverscmp sysconf sysctl sysmp \
+ strtol strtold strtoul strverscmp sysconf sysctl sysmp \
 table times tmpnam \
 vasprintf vfprintf vprintf vsprintf \
 wait3 wait4 waitpid)
diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index d31bf94..59de083 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -46,6 +46,9 @@ If not, see http://www.gnu.org/licenses/.  */
 extern long strtol (const char *nptr, char **endptr, int base);
 extern long double strtold (const char *nptr, char **endptr);
 #endif
+#if !defined(HAVE_STRTOLD)
+#define strtold strtod
+#endif
 
 #include demangle.h
 #include libiberty.h
diff --git a/libiberty/config.in b/libiberty/config.in
index 1cf9c11..8c5f0b6 100644
--- a/libiberty/config.in
+++ b/libiberty/config.in
@@ -280,6 +280,9 @@
 /* Define to 1 if you have the `strtol' function. */
 #undef HAVE_STRTOL
 
+/* Define to 1 if you have the `strtold' function. */
+#undef HAVE_STRTOLD
+
 /* Define to 1 if you have the `strtoul' function. */
 #undef HAVE_STRTOUL
 
diff --git a/libiberty/configure b/libiberty/configure
index 96feaed..072b03b 100755
--- a/libiberty/configure
+++ b/libiberty/configure
@@ -5423,7 +5423,7 @@ if test x = y; then
 sbrk setenv setproctitle setrlimit sigsetmask snprintf spawnve spawnvpe \
  stpcpy stpncpy strcasecmp strchr strdup \
  strerror strncasecmp strndup strnlen strrchr strsignal strstr strtod \
- strtol strtoul strverscmp sysconf sysctl sysmp \
+ strtol strtold strtoul strverscmp sysconf sysctl sysmp \
 table times tmpnam \
 vasprintf vfprintf vprintf vsprintf \
 wait3 wait4 waitpid
-- 
1.9.1



Re: [PATCH] Add D demangling support to libiberty

2014-10-14 Thread Ian Lance Taylor
On Tue, Oct 14, 2014 at 7:12 AM, Joel Brobecker brobec...@adacore.com wrote:

 libiberty/ChangeLog
 2014-08-05  Iain Buclaw  ibuc...@gdcproject.org

 * Makefile.in (CFILES): Add d-demangle.c.
 (REQUIRED_OFILES): Add d-demangle.o.
 * cplus-dem.c (libiberty_demanglers): Add dlang_demangling case.
 (cplus_demangle): Likewise.
 * d-demangle.c: New file.
 * testsuite/Makefile.in (really-check): Add check-d-demangle.
 * testsuite/d-demangle-expected: New file.

 As hinted on gdb-patches, this patch causes a GDB build failure
 on Solaris 2.9, because it uses strtold which is not available.
 According to gnulib's documentation, it should also break on
 the following systems:

 NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, IRIX 6.5, OSF/1 4.0,
 Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.

 This patch attempts to fix the issue by adding a configure check
 for strtold and adjusts the code to use strtod if strtold does not
 exist.

 Does this look OK to you? If yes, can one of the GCC maintainers
 please review?

It doesn't make sense to me to use strtod if strtold is required.  And
if strtold is not required, then it seems to me that we should always
use strtod.  It seems to me that the right options are either 1) use
strtod unconditionally; 2) add strtold to libiberty

Since option 1 is simpler, what bad things would happen if we use
strtod unconditionally?

Ian


Re: [PATCH] Add D demangling support to libiberty

2014-10-14 Thread Iain Buclaw
On 14 October 2014 15:28, Ian Lance Taylor i...@google.com wrote:
 On Tue, Oct 14, 2014 at 7:12 AM, Joel Brobecker brobec...@adacore.com wrote:

 libiberty/ChangeLog
 2014-08-05  Iain Buclaw  ibuc...@gdcproject.org

 * Makefile.in (CFILES): Add d-demangle.c.
 (REQUIRED_OFILES): Add d-demangle.o.
 * cplus-dem.c (libiberty_demanglers): Add dlang_demangling case.
 (cplus_demangle): Likewise.
 * d-demangle.c: New file.
 * testsuite/Makefile.in (really-check): Add check-d-demangle.
 * testsuite/d-demangle-expected: New file.

 As hinted on gdb-patches, this patch causes a GDB build failure
 on Solaris 2.9, because it uses strtold which is not available.
 According to gnulib's documentation, it should also break on
 the following systems:

 NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, IRIX 6.5, OSF/1 4.0,
 Solaris 9, Cygwin, MSVC 9, Interix 3.5, BeOS.

 This patch attempts to fix the issue by adding a configure check
 for strtold and adjusts the code to use strtod if strtold does not
 exist.

 Does this look OK to you? If yes, can one of the GCC maintainers
 please review?

 It doesn't make sense to me to use strtod if strtold is required.  And
 if strtold is not required, then it seems to me that we should always
 use strtod.  It seems to me that the right options are either 1) use
 strtod unconditionally; 2) add strtold to libiberty

 Since option 1 is simpler, what bad things would happen if we use
 strtod unconditionally?

 Ian

I've just seen this, so I'll repeat what I've said in gdb patches too.

The call to strtold is only needed to decode templates which have a
floating point value encoded inside. This value may or may not have a
greater than double precision.

Replacing long double with double will be fine with me.  I'll accept
that I didn't consider legacy in hindsight, and in reality it would be
rather rare to stumble upon the need for strtold.

Regards
Iain


Re: [PATCH] Add D demangling support to libiberty

2014-10-14 Thread Joel Brobecker
 I've just seen this, so I'll repeat what I've said in gdb patches too.
 
 The call to strtold is only needed to decode templates which have a
 floating point value encoded inside. This value may or may not have a
 greater than double precision.
 
 Replacing long double with double will be fine with me.  I'll accept
 that I didn't consider legacy in hindsight, and in reality it would be
 rather rare to stumble upon the need for strtold.

Attached is a patch that switches it to strtod. Do you have any
test that could quickly verify it? That seems to be the best
approach, at least short-term. Later on, if we do want to use
higher precision, we can indeed add strtold in libiberty.

libiberty/ChangeLog:

* d-demangle.c: Replace strtold with strtod in global comment.
(strtold): Remove declaration.
(strtod): New declaration.
(dlang_parse_real): Declare value as double instead of long
double.  Replace call to strtold by call to strtod.
Update format in call to snprintf.

I verified that the patch allows GDB to build on both sparc-solaris
and x86_64-linux.

Thanks,
-- 
Joel
From 99f9794c6d2f4dabed0bbcf2cf362b1eb25ee2a7 Mon Sep 17 00:00:00 2001
From: Joel Brobecker brobec...@adacore.com
Date: Tue, 14 Oct 2014 12:47:43 -0400
Subject: [PATCH] Use strtod instead of strtold in libiberty/d-demangle.c

strtold is currently used to decode templates which have a floating-point
value encoded inside; but this routine is not available on some systems,
such as Solaris 2.9 for instance.

This patch fixes the issue by replace the use of strtold by strtod.
It reduces a bit the precision, but it should still remain acceptable
in most cases.

libiberty/ChangeLog:

* d-demangle.c: Replace strtold with strtod in global comment.
(strtold): Remove declaration.
(strtod): New declaration.
(dlang_parse_real): Declare value as double instead of long
double.  Replace call to strtold by call to strtod.
Update format in call to snprintf.
---
 libiberty/d-demangle.c |   10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index d31bf94..bb481c0 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -28,7 +28,7 @@ If not, see http://www.gnu.org/licenses/.  */
 
 /* This file exports one function; dlang_demangle.
 
-   This file imports strtol and strtold for decoding mangled literals.  */
+   This file imports strtol and strtod for decoding mangled literals.  */
 
 #ifdef HAVE_CONFIG_H
 #include config.h
@@ -44,7 +44,7 @@ If not, see http://www.gnu.org/licenses/.  */
 #include stdlib.h
 #else
 extern long strtol (const char *nptr, char **endptr, int base);
-extern long double strtold (const char *nptr, char **endptr);
+extern double strtod (const char *nptr, char **endptr);
 #endif
 
 #include demangle.h
@@ -810,7 +810,7 @@ dlang_parse_real (string *decl, const char *mangled)
 {
   char buffer[64];
   int len = 0;
-  long double value;
+  double value;
   char *endptr;
 
   /* Handle NAN and +-INF.  */
@@ -877,12 +877,12 @@ dlang_parse_real (string *decl, const char *mangled)
 
   /* Convert buffer from hexadecimal to floating-point.  */
   buffer[len] = '\0';
-  value = strtold (buffer, endptr);
+  value = strtod (buffer, endptr);
 
   if (endptr == NULL || endptr != (buffer + len))
 return NULL;
 
-  len = snprintf (buffer, sizeof(buffer), %#Lg, value);
+  len = snprintf (buffer, sizeof(buffer), %#g, value);
   string_appendn (decl, buffer, len);
   return mangled;
 }
-- 
1.7.9.5



Re: [PATCH] Add D demangling support to libiberty

2014-10-14 Thread Ian Lance Taylor
On Tue, Oct 14, 2014 at 10:07 AM, Joel Brobecker brobec...@adacore.com wrote:

 libiberty/ChangeLog:

 * d-demangle.c: Replace strtold with strtod in global comment.
 (strtold): Remove declaration.
 (strtod): New declaration.
 (dlang_parse_real): Declare value as double instead of long
 double.  Replace call to strtold by call to strtod.
 Update format in call to snprintf.

This is OK.

Thanks.

Ian


Re: [PATCH] Add D demangling support to libiberty

2014-10-14 Thread Iain Buclaw
On 14 October 2014 18:07, Joel Brobecker brobec...@adacore.com wrote:
 I've just seen this, so I'll repeat what I've said in gdb patches too.

 The call to strtold is only needed to decode templates which have a
 floating point value encoded inside. This value may or may not have a
 greater than double precision.

 Replacing long double with double will be fine with me.  I'll accept
 that I didn't consider legacy in hindsight, and in reality it would be
 rather rare to stumble upon the need for strtold.

 Attached is a patch that switches it to strtod. Do you have any
 test that could quickly verify it? That seems to be the best
 approach, at least short-term. Later on, if we do want to use
 higher precision, we can indeed add strtold in libiberty.


See d-demangle-expected in the libiberty testsuite, in particular:

_D8demangle17__T4testVde0A8P6Zv
demangle.test!(42.)

_D8demangle16__T4testVdeA8P2Zv
demangle.test!(42.)

_D8demangle18__T4testVdeN0A8P6Zv
demangle.test!(-42.)

_D8demangle31__T4testVde0F6E978D4FDF3B646P7Zv
demangle.test!(123.456)


I doubt they would need adjusting.

Regards
Iain


Re: [PATCH] Add D demangling support to libiberty

2014-10-14 Thread Joel Brobecker
  libiberty/ChangeLog:
 
  * d-demangle.c: Replace strtold with strtod in global comment.
  (strtold): Remove declaration.
  (strtod): New declaration.
  (dlang_parse_real): Declare value as double instead of long
  double.  Replace call to strtold by call to strtod.
  Update format in call to snprintf.
 
 This is OK.

Thanks, Ian. As suggested by Iain, I re-ran the libiberty
testsuite on x86_64-linux before committing the patch.

Thank you both!
-- 
Joel


Re: [PATCH] Add D demangling support to libiberty

2014-09-23 Thread Iain Buclaw
On 19 September 2014 08:51, Iain Buclaw ibuc...@gdcproject.org wrote:
 On 4 August 2014 16:52, Ian Lance Taylor i...@google.com wrote:
 On Sun, Aug 3, 2014 at 11:12 AM, Iain Buclaw ibuc...@gdcproject.org wrote:

 - I haven't signed any copyright assignments to GCC.  But I have
 papers from Donald ready to send across.

 Definitely necessary before we can consider this.  Please get this
 squared away before proceeding with this patch.  Let us know if you
 need any help with this.


 I've been informed by FSF assignments that this has now been
 processed.  Is there anything left for me to address technically about
 this change?


Thought I might just ping on this, incase I have missed any response
from anyone.

Iain.


Re: [PATCH] Add D demangling support to libiberty

2014-09-23 Thread Ian Lance Taylor
On Fri, Sep 19, 2014 at 12:51 AM, Iain Buclaw ibuc...@gdcproject.org wrote:
 On 4 August 2014 16:52, Ian Lance Taylor i...@google.com wrote:
 On Sun, Aug 3, 2014 at 11:12 AM, Iain Buclaw ibuc...@gdcproject.org wrote:

 - I haven't signed any copyright assignments to GCC.  But I have
 papers from Donald ready to send across.

 Definitely necessary before we can consider this.  Please get this
 squared away before proceeding with this patch.  Let us know if you
 need any help with this.


 I've been informed by FSF assignments that this has now been
 processed.  Is there anything left for me to address technically about
 this change?

No.  Reviewed, tested, approved, and committed to mainline.

Ian


Re: [PATCH] Add D demangling support to libiberty

2014-09-19 Thread Iain Buclaw
On 4 August 2014 16:52, Ian Lance Taylor i...@google.com wrote:
 On Sun, Aug 3, 2014 at 11:12 AM, Iain Buclaw ibuc...@gdcproject.org wrote:

 - I haven't signed any copyright assignments to GCC.  But I have
 papers from Donald ready to send across.

 Definitely necessary before we can consider this.  Please get this
 squared away before proceeding with this patch.  Let us know if you
 need any help with this.


I've been informed by FSF assignments that this has now been
processed.  Is there anything left for me to address technically about
this change?

Iain.


Re: [PATCH] Add D demangling support to libiberty

2014-08-05 Thread Iain Buclaw
Attached revision #2 of the patch.

---
Add D demangling support for version 2 of the ABI.

include/ChangeLog
2014-08-05  Iain Buclaw  ibuc...@gdcproject.org

* demangle.h (DMGL_DLANG): New macro.
(DMGL_STYLE_MASK): Add DMGL_DLANG.
(demangling_styles): Add dlang_demangling.
(DLANG_DEMANGLING_STYLE_STRING): New macro.
(DLANG_DEMANGLING): New macro.
(dlang_demangle): New prototype.

libiberty/ChangeLog
2014-08-05  Iain Buclaw  ibuc...@gdcproject.org

* Makefile.in (CFILES): Add d-demangle.c.
(REQUIRED_OFILES): Add d-demangle.o.
* cplus-dem.c (libiberty_demanglers): Add dlang_demangling case.
(cplus_demangle): Likewise.
* d-demangle.c: New file.
* testsuite/Makefile.in (really-check): Add check-d-demangle.
* testsuite/d-demangle-expected: New file.
---
diff --git a/include/demangle.h b/include/demangle.h
index bbad71b..d2a6731 100644
--- a/include/demangle.h
+++ b/include/demangle.h
@@ -63,9 +63,10 @@ extern C {
 #define DMGL_EDG	 (1  13)
 #define DMGL_GNU_V3	 (1  14)
 #define DMGL_GNAT	 (1  15)
+#define DMGL_DLANG	 (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)
+#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_DLANG)
 
 /* Enumeration of possible demangling styles.
 
@@ -87,7 +88,8 @@ extern enum demangling_styles
   edg_demangling = DMGL_EDG,
   gnu_v3_demangling = DMGL_GNU_V3,
   java_demangling = DMGL_JAVA,
-  gnat_demangling = DMGL_GNAT
+  gnat_demangling = DMGL_GNAT,
+  dlang_demangling = DMGL_DLANG
 } current_demangling_style;
 
 /* Define string names for the various demangling styles. */
@@ -102,6 +104,7 @@ extern enum demangling_styles
 #define GNU_V3_DEMANGLING_STYLE_STRINGgnu-v3
 #define JAVA_DEMANGLING_STYLE_STRING  java
 #define GNAT_DEMANGLING_STYLE_STRING  gnat
+#define DLANG_DEMANGLING_STYLE_STRING dlang
 
 /* Some macros to test what demangling style is active. */
 
@@ -115,6 +118,7 @@ extern enum demangling_styles
 #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 DLANG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE)  DMGL_DLANG)
 
 /* Provide information about the available demangle styles. This code is
pulled from gdb into libiberty because it is useful to binutils also.  */
@@ -169,6 +173,9 @@ java_demangle_v3 (const char *mangled);
 char *
 ada_demangle (const char *mangled, int options);
 
+extern char *
+dlang_demangle (const char *mangled, int options);
+
 enum gnu_v3_ctor_kinds {
   gnu_v3_complete_object_ctor = 1,
   gnu_v3_base_object_ctor,
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index 44e340f..9b87720 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -127,7 +127,7 @@ CFILES = alloca.c argv.c asprintf.c atexit.c\
 	basename.c bcmp.c bcopy.c bsearch.c bzero.c			\
 	calloc.c choose-temp.c clock.c concat.c cp-demangle.c		\
 	 cp-demint.c cplus-dem.c crc32.c\
-	dwarfnames.c dyn-string.c	\
+	d-demangle.c dwarfnames.c dyn-string.c\
 	fdmatch.c ffs.c fibheap.c filename_cmp.c floatformat.c		\
 	fnmatch.c fopen_unlocked.c	\
 	getcwd.c getopt.c getopt1.c getpagesize.c getpwd.c getruntime.c	\
@@ -167,7 +167,7 @@ REQUIRED_OFILES =			\
 	./md5.$(objext) ./sha1.$(objext) ./alloca.$(objext)		\
 	./argv.$(objext)		\
 	./choose-temp.$(objext) ./concat.$(objext)			\
-	./cp-demint.$(objext) ./crc32.$(objext)\
+	./cp-demint.$(objext) ./crc32.$(objext) ./d-demangle.$(objext)	\
 	./dwarfnames.$(objext) ./dyn-string.$(objext)			\
 	./fdmatch.$(objext) ./fibheap.$(objext)\
 	./filename_cmp.$(objext) ./floatformat.$(objext)		\
@@ -714,6 +714,14 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir
 	else true; fi
 	$(COMPILE.c) $(srcdir)/dyn-string.c $(OUTPUT_OPTION)
 
+./d-demangle.$(objext): $(srcdir)/d-demangle.c config.h $(INCDIR)/ansidecl.h \
+	$(srcdir)/cp-demangle.h $(INCDIR)/demangle.h \
+	$(INCDIR)/dyn-string.h $(INCDIR)/getopt.h $(INCDIR)/libiberty.h
+	if [ x$(PICFLAG) != x ]; then \
+	  $(COMPILE.c) $(PICFLAG) $(srcdir)/d-demangle.c -o pic/$@; \
+	else true; fi
+	$(COMPILE.c) $(srcdir)/d-demangle.c $(OUTPUT_OPTION)
+
 ./fdmatch.$(objext): $(srcdir)/fdmatch.c config.h $(INCDIR)/ansidecl.h \
 	$(INCDIR)/libiberty.h
 	if [ x$(PICFLAG) != x ]; then \
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c
index 52767cc..c68b981 100644
--- a/libiberty/cplus-dem.c
+++ b/libiberty/cplus-dem.c
@@ -306,6 +306,12 @@ const struct demangler_engine libiberty_demanglers[] =
   }
   ,
   {
+DLANG_DEMANGLING_STYLE_STRING,
+dlang_demangling,
+DLANG style demangling
+  }
+  ,
+  {
 NULL, unknown_demangling, NULL
   }
 };
@@ -870,6 +876,13 @@ 

Re: [PATCH] Add D demangling support to libiberty

2014-08-04 Thread Ian Lance Taylor
On Sun, Aug 3, 2014 at 11:12 AM, Iain Buclaw ibuc...@gdcproject.org wrote:

 This adds a demangler for the D programming language to libiberty,
 intended to be used in GDB and Binutils.  GDB already has a trimmed
 down implementation of this, but have been advised that here would be
 a better location to house it.

 Notes that I think are of interest / questions I have about how I've done 
 this.

 - The implementation is some 1200 SLOC (and may grow), so I've put it
 in a new file, as opposed included cplus-dem.c.  Is this reasonable?

Yes.


 - This borrows and extends the mini string package in cplus-dem.c,
 because it was the simplest to use when writing this.  The GDB
 implementation uses obstack, and I'm aware of dyn_string, but I can't
 say I'm a fan of using either.

One thing we discovered for the C++ demangler is that sometimes it's
nice to be able to invoke it from locations where the memory allocator
is not available, such as when the program is crashing.  That is why
the C++ demangler has a cplus_demangle_v3_callback entry point.  For
ordinary demangling the code uses growable_string and
d_growable_string_callback_adapter.  It's not important for now but
you may want to consider doing something like that in the future.

If you do choose to follow that path, because of namespace
considerations I think the right approach would be to move the
growable_string code and the adapter into a .h file in libiberty that
defines the functions as static.  Then both demanglers could #include
that file.  That would let them share the code without adding
unacceptable new symbols to libstdc++.


 - GDB has a testsuite that provides most of the coverage for what this
 code should be doing.

That is nice but we need a small testsuite in libiberty too--see
libiberty/testsuite/test-demangle.c and demangle-expected.  Ideally
you should be able to just add some entries to demangle-expected.


 - List of functions in d-demangle.c can be added to the ChangeLog upon 
 request.

Not necessary.


 - I haven't signed any copyright assignments to GCC.  But I have
 papers from Donald ready to send across.

Definitely necessary before we can consider this.  Please get this
squared away before proceeding with this patch.  Let us know if you
need any help with this.


 +#ifdef HAVE_STDLIB_H
 +#include stdlib.h
 +#else
 +long strtol (const char *nptr, char **endptr, int base);
 +long double strtold (const char *nptr, char **endptr);

Use an explicit extern.

 +#define ASCII2HEX(c) \
 +  (('a' = (c)  (c) = 'f') ? \
 +   ((c) - 'a' + 10) \
 +   : (('A' = (c)  (c) = 'F') ? \
 +  ((c) - 'A' + 10) \
 +  : (('0' = (c)  (c) = '9') ? \
 +  ((c) - '0') \
 +  : 0 \
 +) \
 + ) \
 +  )

Use a function, not a macro that multiple-evaluates its argument.


 +/* Prototypes for D demangling functions */

Current style is to only forward declare functions when necessary.


 +const char *
 +dlang_call_convention (string *decl, const char *mangled)

This should be explicitly static.  Same applies to many of the
functions below.

Ian


Re: [PATCH] Add D demangling support to libiberty

2014-08-04 Thread Tom Tromey
 Iain == Iain Buclaw ibuc...@gdcproject.org writes:

Iain This adds a demangler for the D programming language to libiberty,
Iain intended to be used in GDB and Binutils.  GDB already has a trimmed
Iain down implementation of this, but have been advised that here would be
Iain a better location to house it.

Iain - GDB has a testsuite that provides most of the coverage for what this
Iain code should be doing.

I think it's better to put the tests into libiberty.  That way they are
right next to the code.  This shouldn't be hard, as there's already a
demangler test suite there.

Tom


Re: [PATCH] Add D demangling support to libiberty

2014-08-04 Thread Iain Buclaw
On 4 August 2014 16:52, Ian Lance Taylor i...@google.com wrote:
 On Sun, Aug 3, 2014 at 11:12 AM, Iain Buclaw ibuc...@gdcproject.org wrote:

 This adds a demangler for the D programming language to libiberty,
 intended to be used in GDB and Binutils.  GDB already has a trimmed
 down implementation of this, but have been advised that here would be
 a better location to house it.

 Notes that I think are of interest / questions I have about how I've done 
 this.

 - The implementation is some 1200 SLOC (and may grow), so I've put it
 in a new file, as opposed included cplus-dem.c.  Is this reasonable?

 Yes.


 - This borrows and extends the mini string package in cplus-dem.c,
 because it was the simplest to use when writing this.  The GDB
 implementation uses obstack, and I'm aware of dyn_string, but I can't
 say I'm a fan of using either.

 One thing we discovered for the C++ demangler is that sometimes it's
 nice to be able to invoke it from locations where the memory allocator
 is not available, such as when the program is crashing.  That is why
 the C++ demangler has a cplus_demangle_v3_callback entry point.  For
 ordinary demangling the code uses growable_string and
 d_growable_string_callback_adapter.  It's not important for now but
 you may want to consider doing something like that in the future.

 If you do choose to follow that path, because of namespace
 considerations I think the right approach would be to move the
 growable_string code and the adapter into a .h file in libiberty that
 defines the functions as static.  Then both demanglers could #include
 that file.  That would let them share the code without adding
 unacceptable new symbols to libstdc++.


 - GDB has a testsuite that provides most of the coverage for what this
 code should be doing.

 That is nice but we need a small testsuite in libiberty too--see
 libiberty/testsuite/test-demangle.c and demangle-expected.  Ideally
 you should be able to just add some entries to demangle-expected.



OK, I'll examine this.



 - List of functions in d-demangle.c can be added to the ChangeLog upon 
 request.

 Not necessary.


 - I haven't signed any copyright assignments to GCC.  But I have
 papers from Donald ready to send across.

 Definitely necessary before we can consider this.  Please get this
 squared away before proceeding with this patch.  Let us know if you
 need any help with this.



I'll let you know when it's been processed.  Last time they had a fast
turnaround.


 +#ifdef HAVE_STDLIB_H
 +#include stdlib.h
 +#else
 +long strtol (const char *nptr, char **endptr, int base);
 +long double strtold (const char *nptr, char **endptr);

 Use an explicit extern.

 +#define ASCII2HEX(c) \
 +  (('a' = (c)  (c) = 'f') ? \
 +   ((c) - 'a' + 10) \
 +   : (('A' = (c)  (c) = 'F') ? \
 +  ((c) - 'A' + 10) \
 +  : (('0' = (c)  (c) = '9') ? \
 +  ((c) - '0') \
 +  : 0 \
 +) \
 + ) \
 +  )

 Use a function, not a macro that multiple-evaluates its argument.


 +/* Prototypes for D demangling functions */

 Current style is to only forward declare functions when necessary.


 +const char *
 +dlang_call_convention (string *decl, const char *mangled)

 This should be explicitly static.  Same applies to many of the
 functions below.


I've dealt with the above, but I'll re-submit the patch when I've
added in the testsuite items.

Regards
Iain


Re: [PATCH] Add D demangling support to libiberty

2014-08-04 Thread Iain Buclaw
On 4 August 2014 17:06, Tom Tromey tro...@redhat.com wrote:
 Iain == Iain Buclaw ibuc...@gdcproject.org writes:

 Iain This adds a demangler for the D programming language to libiberty,
 Iain intended to be used in GDB and Binutils.  GDB already has a trimmed
 Iain down implementation of this, but have been advised that here would be
 Iain a better location to house it.

 Iain - GDB has a testsuite that provides most of the coverage for what this
 Iain code should be doing.

 I think it's better to put the tests into libiberty.  That way they are
 right next to the code.  This shouldn't be hard, as there's already a
 demangler test suite there.

 Tom

I've found it, thanks.


[PATCH] Add D demangling support to libiberty

2014-08-03 Thread Iain Buclaw
Hi,

This adds a demangler for the D programming language to libiberty,
intended to be used in GDB and Binutils.  GDB already has a trimmed
down implementation of this, but have been advised that here would be
a better location to house it.

Notes that I think are of interest / questions I have about how I've done this.

- The implementation is some 1200 SLOC (and may grow), so I've put it
in a new file, as opposed included cplus-dem.c.  Is this reasonable?

- This borrows and extends the mini string package in cplus-dem.c,
because it was the simplest to use when writing this.  The GDB
implementation uses obstack, and I'm aware of dyn_string, but I can't
say I'm a fan of using either.

- GDB has a testsuite that provides most of the coverage for what this
code should be doing.

- List of functions in d-demangle.c can be added to the ChangeLog upon request.

- I haven't signed any copyright assignments to GCC.  But I have
papers from Donald ready to send across.

Regards
Iain

---
Add D demangling support for version 2 of the ABI.

include/ChangeLog
2014-08-03  Iain Buclaw  ibuc...@gdcproject.org

* demangle.h (DMGL_DLANG): New macro.
(DMGL_STYLE_MASK): Add DMGL_DLANG.
(demangling_styles): Add dlang_demangling.
(DLANG_DEMANGLING_STYLE_STRING): New macro.
(DLANG_DEMANGLING): New macro.
(dlang_demangle): New prototype.

libibery/ChangeLog
2014-08-03  Iain Buclaw  ibuc...@gdcproject.org

* Makefile.in (CFILES): Add d-demangle.c.
(REQUIRED_OFILES): Add d-demangle.o.
* cplus-dem.c (libiberty_demanglers): Add dlang_demangling case.
(cplus_demangle): Likewise.
* d-demangle.c: New file.

---
diff --git a/include/demangle.h b/include/demangle.h
index bbad71b..d2a6731 100644
--- a/include/demangle.h
+++ b/include/demangle.h
@@ -63,9 +63,10 @@ extern C {
 #define DMGL_EDG	 (1  13)
 #define DMGL_GNU_V3	 (1  14)
 #define DMGL_GNAT	 (1  15)
+#define DMGL_DLANG	 (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)
+#define DMGL_STYLE_MASK (DMGL_AUTO|DMGL_GNU|DMGL_LUCID|DMGL_ARM|DMGL_HP|DMGL_EDG|DMGL_GNU_V3|DMGL_JAVA|DMGL_GNAT|DMGL_DLANG)
 
 /* Enumeration of possible demangling styles.
 
@@ -87,7 +88,8 @@ extern enum demangling_styles
   edg_demangling = DMGL_EDG,
   gnu_v3_demangling = DMGL_GNU_V3,
   java_demangling = DMGL_JAVA,
-  gnat_demangling = DMGL_GNAT
+  gnat_demangling = DMGL_GNAT,
+  dlang_demangling = DMGL_DLANG
 } current_demangling_style;
 
 /* Define string names for the various demangling styles. */
@@ -102,6 +104,7 @@ extern enum demangling_styles
 #define GNU_V3_DEMANGLING_STYLE_STRINGgnu-v3
 #define JAVA_DEMANGLING_STYLE_STRING  java
 #define GNAT_DEMANGLING_STYLE_STRING  gnat
+#define DLANG_DEMANGLING_STYLE_STRING dlang
 
 /* Some macros to test what demangling style is active. */
 
@@ -115,6 +118,7 @@ extern enum demangling_styles
 #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 DLANG_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE)  DMGL_DLANG)
 
 /* Provide information about the available demangle styles. This code is
pulled from gdb into libiberty because it is useful to binutils also.  */
@@ -169,6 +173,9 @@ java_demangle_v3 (const char *mangled);
 char *
 ada_demangle (const char *mangled, int options);
 
+extern char *
+dlang_demangle (const char *mangled, int options);
+
 enum gnu_v3_ctor_kinds {
   gnu_v3_complete_object_ctor = 1,
   gnu_v3_base_object_ctor,
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index 44e340f..9b87720 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -127,7 +127,7 @@ CFILES = alloca.c argv.c asprintf.c atexit.c\
 	basename.c bcmp.c bcopy.c bsearch.c bzero.c			\
 	calloc.c choose-temp.c clock.c concat.c cp-demangle.c		\
 	 cp-demint.c cplus-dem.c crc32.c\
-	dwarfnames.c dyn-string.c	\
+	d-demangle.c dwarfnames.c dyn-string.c\
 	fdmatch.c ffs.c fibheap.c filename_cmp.c floatformat.c		\
 	fnmatch.c fopen_unlocked.c	\
 	getcwd.c getopt.c getopt1.c getpagesize.c getpwd.c getruntime.c	\
@@ -167,7 +167,7 @@ REQUIRED_OFILES =			\
 	./md5.$(objext) ./sha1.$(objext) ./alloca.$(objext)		\
 	./argv.$(objext)		\
 	./choose-temp.$(objext) ./concat.$(objext)			\
-	./cp-demint.$(objext) ./crc32.$(objext)\
+	./cp-demint.$(objext) ./crc32.$(objext) ./d-demangle.$(objext)	\
 	./dwarfnames.$(objext) ./dyn-string.$(objext)			\
 	./fdmatch.$(objext) ./fibheap.$(objext)\
 	./filename_cmp.$(objext) ./floatformat.$(objext)		\
@@ -714,6 +714,14 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir
 	else true; fi
 	$(COMPILE.c) $(srcdir)/dyn-string.c $(OUTPUT_OPTION)