This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Demangling broken (was: Re: [PATCH] Demangler woes with current CVS and type names)
- From: "H . J . Lu" <hjl at lucon dot org>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Phil Edwards <phil at jaj dot com>, Andrew Cagney <ac131313 at cygnus dot com>,Hans-Peter Nilsson <hans-peter dot nilsson at axis dot com>,gcc-patches at gcc dot gnu dot org, binutils at sources dot redhat dot com
- Date: Fri, 1 Feb 2002 16:37:35 -0800
- Subject: Re: Demangling broken (was: Re: [PATCH] Demangler woes with current CVS and type names)
- References: <200201311828.TAA12642@ignucius.axis.se> <20020131163600.A11943@disaster.basement.lan> <20020131182231.A5727@nevyn.them.org> <20020131185227.A12592@disaster.basement.lan> <20020131162415.A26740@lucon.org> <3C59E20A.7000100@cygnus.com> <20020131165555.A27351@lucon.org> <wvladut7zil.fsf@prospero.cambridge.redhat.com> <20020201164949.B17061@disaster.basement.lan> <wvl4rl095it.fsf@prospero.cambridge.redhat.com>
On Fri, Feb 01, 2002 at 10:55:06PM +0000, Jason Merrill wrote:
> >>>>> "Phil" == Phil Edwards <phil@jaj.com> writes:
>
> > On Fri, Feb 01, 2002 at 07:50:10PM +0000, Jason Merrill wrote:
> >> >>>>> "H" == H J Lu <hjl@lucon.org> writes:
> >>
> >> > (main): Set cplus_demangle_v3_p to cplus_demangle_v3_type for
> >> > gnu_v3_demangling:
> >>
> >> Not OK. This will wreak the same havoc that Phil's original change did,
> >> just only with -s gnu-v3. The type-handling behavior should be limited to
> >> command line arguments, it should never be active in filter mode.
>
> > What if HJ's patch were to turn on type demangling by default only when
> > the standalone c++filt were being built, and leave the current semantics
> > stand for the library? (Is that what you're saying?)
>
> No. I'm saying that it's OK for 'c++filt d' to say 'double', because
> giving a name on the command line makes it explicit that we think it's a
> mangled name, so it's appropriate to try hard to demangle it.
>
> However, 'echo d|c++filt' should always say 'd', or you get very strange
> results from trying to read assembly output with c++filt.
>
> With HJ's patch, 'echo d|c++filt -s gnu-v3' would say 'double', which is
> undesirable.
>
How about this patch?
H.J.
----
2002-02-01 H.J. Lu (hjl@gnu.org)
* demangle.h (cplus_demangle_v3_type): New prototype.
2002-02-01 H.J. Lu (hjl@gnu.org)
* cp-demangle.c (cp_demangle_type): Do not protect with
IN_LIBGCC2.
(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.
(demangle_v3_type): New.
(main): Set cplus_demangle_v3_p to cplus_demangle_v3_type for
command line symbol or if demangle_v3_type is not zero.
* testsuite/Makefile.in (test-filter): Set demangle_v3_type to
1 in test-us.c.
--- binutils/include/demangle.h.v3 Fri Dec 7 11:08:35 2001
+++ binutils/include/demangle.h Fri Feb 1 16:15:15 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 Fri Feb 1 00:10:51 2002
+++ binutils/libiberty/cp-demangle.c Fri Feb 1 16:15:15 2002
@@ -938,10 +938,10 @@ static status_t demangle_discriminator
PARAMS ((demangling_t, int));
static status_t cp_demangle
PARAMS ((const char *, dyn_string_t, int));
-#ifdef IN_LIBGCC2
static status_t cp_demangle_type
PARAMS ((const char*, dyn_string_t));
-#endif
+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. */
@@ -3533,7 +3533,6 @@ cp_demangle (name, result, style)
dyn_string_t. On success, returns STATUS_OK. On failiure, returns
an error message, and the contents of RESULT are unchanged. */
-#ifdef IN_LIBGCC2
static status_t
cp_demangle_type (type_name, result)
const char* type_name;
@@ -3571,6 +3570,7 @@ cp_demangle_type (type_name, result)
return status;
}
+#ifdef IN_LIBGCC2
extern char *__cxa_demangle PARAMS ((const char *, char *, size_t *, int *));
/* ia64 ABI-mandated entry point in the C++ runtime library for performing
@@ -3690,17 +3690,43 @@ 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 this isn't a mangled name, don't pretend to demangle it. */
- if (strncmp (mangled, "_Z", 2) != 0)
- return NULL;
+ 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. */
- status = cp_demangle ((char *) mangled, demangled, 0);
+ if (!type)
+ /* Appears to be a function or variable name. */
+ status = cp_demangle (mangled, demangled, 0);
+ else
+ /* Try to demangle it as the name of a type. */
+ status = cp_demangle_type (mangled, demangled);
if (STATUS_NO_ERROR (status))
/* Demangling succeeded. */
--- binutils/libiberty/cplus-dem.c.v3 Thu Jan 31 16:14:49 2002
+++ binutils/libiberty/cplus-dem.c Fri Feb 1 16:31:17 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;
@@ -5277,6 +5280,8 @@ gnu_v3_symbol_characters ()
extern int main PARAMS ((int, char **));
+int demangle_v3_type;
+
int
main (argc, argv)
int argc;
@@ -5330,6 +5335,7 @@ main (argc, argv)
if (optind < argc)
{
+ cplus_demangle_v3_p = cplus_demangle_v3_type;
for ( ; optind < argc; optind++)
{
demangle_it (argv[optind]);
@@ -5337,6 +5343,9 @@ main (argc, argv)
}
else
{
+ if (demangle_v3_type)
+ cplus_demangle_v3_p = cplus_demangle_v3_type;
+
switch (current_demangling_style)
{
case gnu_demangling:
--- binutils/libiberty/testsuite/Makefile.in.v3 Fri Feb 25 16:36:51 2000
+++ binutils/libiberty/testsuite/Makefile.in Fri Feb 1 16:31:15 2002
@@ -54,6 +54,7 @@ check-cplus-dem: test-filter $(srcdir)/d
TEST_COMPILE = $(CC) @DEFS@ $(LIBCFLAGS) -I.. -I$(INCDIR) $(HDEFINES)
test-filter: $(srcdir)/../cplus-dem.c
echo 'int prepends_underscore = 0;' > test-us.c
+ echo 'int demangle_v3_type = 1;' >> test-us.c
$(TEST_COMPILE) -o test-filter -DMAIN -DVERSION='"none"' @DEFS@ \
$(srcdir)/../cplus-dem.c test-us.c -L.. -liberty $(LOADLIBES)