]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
libiberty: Invoke D demangler when --format=auto
authorTom Tromey <tom@tromey.com>
Sat, 30 Mar 2024 19:48:30 +0000 (13:48 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 2 Apr 2024 19:53:13 +0000 (13:53 -0600)
Investigating GDB PR d/31580 showed that the libiberty demangler
doesn't automatically demangle D mangled names.  However, I think it
should -- like C++ and Rust (new-style), D mangled names are readily
distinguished by the leading "_D", and so the likelihood of confusion
is low.  The other non-"auto" cases in this code are Ada (where the
encoded form could more easily be confused by ordinary programs) and
Java (which is long gone, but which also shared the C++ mangling and
thus was just an output style preference).

This patch also fixed another GDB bug, though of course that part
won't apply to the GCC repository.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31580
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30276

libiberty
* cplus-dem.c (cplus_demangle): Try the D demangler with
"auto" format.
* testsuite/d-demangle-expected: Add --format=auto test.

gdb/testsuite/gdb.dlang/dlang-start-2.exp
libiberty/cplus-dem.c
libiberty/testsuite/d-demangle-expected

index 4b3163ec97dac62b65b3beedbeff6edfa112eec3..284f841b54a05fa0e4ec759ef15c14353455790d 100644 (file)
@@ -79,10 +79,8 @@ if {[gdb_start_cmd] < 0} {
     return -1
 }
 
-# We should probably have "D main" instead of "_Dmain" here, filed PR30276
-# '[gdb/symtab] function name is _Dmain instead of "D main"' about that.
 gdb_test "" \
-    "in _Dmain \\(\\)" \
+    "in main \\(\\)" \
     "start"
 
 gdb_test "show language" {"auto; currently d".}
index 8b92946981fd7941c485ad675075f44ba31cad03..ee9e84f5d6b139927b1b0ca30f7d049526a28fd5 100644 (file)
@@ -186,7 +186,7 @@ cplus_demangle (const char *mangled, int options)
   if (GNAT_DEMANGLING)
     return ada_demangle (mangled, options);
 
-  if (DLANG_DEMANGLING)
+  if (DLANG_DEMANGLING || AUTO_DEMANGLING)
     {
       ret = dlang_demangle (mangled, options);
       if (ret)
index 47b059c4298c89557e6c45a7c1b535382e9f0dba..cfbdf2a52cb205e75e62f9d3e4d0c78c37519f2f 100644 (file)
@@ -1470,3 +1470,8 @@ demangle.anonymous
 --format=dlang
 _D8demangle9anonymous03fooZ
 demangle.anonymous.foo
+#
+# Test that 'auto' works.
+--format=auto
+_D8demangle9anonymous03fooZ
+demangle.anonymous.foo