From 094461465547a7d67d4566bec771f16402b42e44 Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Mon, 11 Nov 2013 21:18:02 +0000 Subject: [PATCH] cxxfilt: small changes from Apple's developer tools From Apple's Developer Tools 4.0 [1]: demangle.patch 2007-05-05 Geoffrey Keating (d_name): Detect local-source-name. (d_prefix): Likewise. (d_unqualified_name): Implement local-source-name. libiberty-printf.patch MFC after: 1 month [1] http://opensource.apple.com/source/cxxfilt/cxxfilt-9/patches/ --- contrib/binutils/binutils/cxxfilt.c | 4 +- contrib/gcclibs/libiberty/cp-demangle.c | 30 ++++++++++++- .../libiberty/testsuite/demangle-expected | 44 +++++++++++++++++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/contrib/binutils/binutils/cxxfilt.c b/contrib/binutils/binutils/cxxfilt.c index bed0537e477e..a5200264711d 100644 --- a/contrib/binutils/binutils/cxxfilt.c +++ b/contrib/binutils/binutils/cxxfilt.c @@ -63,12 +63,12 @@ demangle_it (char *mangled_name) result = cplus_demangle (mangled_name + skip_first, flags); if (result == NULL) - printf (mangled_name); + printf ("%s",mangled_name); else { if (mangled_name[0] == '.') putchar ('.'); - printf (result); + printf ("%s",result); free (result); } } diff --git a/contrib/gcclibs/libiberty/cp-demangle.c b/contrib/gcclibs/libiberty/cp-demangle.c index 2fa59785f2fb..3f11967bc0d8 100644 --- a/contrib/gcclibs/libiberty/cp-demangle.c +++ b/contrib/gcclibs/libiberty/cp-demangle.c @@ -1054,6 +1054,11 @@ d_name (struct d_info *di) case 'Z': return d_local_name (di); +/* APPLE LOCAL begin mainline 2007-05-09 5173149 */ \ + case 'L': + return d_unqualified_name (di); + +/* APPLE LOCAL end mainline 2007-05-09 5173149 */ \ case 'S': { int subst; @@ -1174,7 +1179,10 @@ d_prefix (struct d_info *di) if (IS_DIGIT (peek) || IS_LOWER (peek) || peek == 'C' - || peek == 'D') +/* APPLE LOCAL begin mainline 2007-05-09 5173149 */ \ + || peek == 'D' + || peek == 'L') +/* APPLE LOCAL end mainline 2007-05-09 5173149 */ \ dc = d_unqualified_name (di); else if (peek == 'S') dc = d_substitution (di, 1); @@ -1208,6 +1216,11 @@ d_prefix (struct d_info *di) /* ::= ::= ::= + APPLE LOCAL begin mainline 2007-05-09 5173149 + ::= + + ::= L + APPLE LOCAL end mainline 2007-05-09 5173149 */ static struct demangle_component * @@ -1229,6 +1242,21 @@ d_unqualified_name (struct d_info *di) } else if (peek == 'C' || peek == 'D') return d_ctor_dtor_name (di); +/* APPLE LOCAL begin mainline 2007-05-09 5173149 */ \ + else if (peek == 'L') + { + struct demangle_component * ret; + + d_advance (di, 1); + + ret = d_source_name (di); + if (ret == NULL) + return NULL; + if (! d_discriminator (di)) + return NULL; + return ret; + } +/* APPLE LOCAL end mainline 2007-05-09 5173149 */ \ else return NULL; } diff --git a/contrib/gcclibs/libiberty/testsuite/demangle-expected b/contrib/gcclibs/libiberty/testsuite/demangle-expected index 3f5622f79b75..4666e3f8c482 100644 --- a/contrib/gcclibs/libiberty/testsuite/demangle-expected +++ b/contrib/gcclibs/libiberty/testsuite/demangle-expected @@ -3816,3 +3816,47 @@ f SASDASDFASDF_sdfsdf SASDASDFASDF_sdfsdf SASDASDFASDF_sdfsdf +# APPLE LOCAL begin mainline 2007-05-09 5173149 +# These are all cases of invalid manglings where the demangler would read +# past the end of the string. +# d_name wasn't honouring a NULL from d_substitution +--format=gnu-v3 +_ZSA +_ZSA +# d_expr_primary wasn't honouring NULL from cplus_demangle_mangled_name +--format=gnu-v3 +_ZN1fIL_ +_ZN1fIL_ +# d_operator_name was taking two characters in a row +--format=gnu-v3 +_Za +_Za +# d_prefix wasn't honouring NULL from d_substitution +--format=gnu-v3 +_ZNSA +_ZNSA +# d_prefix wasn't honouring NULL from d_template_param +--format=gnu-v3 +_ZNT +_ZNT +# Dereferencing NULL in d_pointer_to_member_type +--format=gnu-v3 +_Z1aMark +_Z1aMark +# test 1 +--format=gnu-v3 +_ZL3foo_2 +foo +# test 2 +--format=gnu-v3 +_ZZL3foo_2vE4var1 +foo()::var1 +# test 3 +--format=gnu-v3 +_ZZL3foo_2vE4var1_0 +foo()::var1 +# test 4 +--format=gnu-v3 +_ZZN7myspaceL3foo_1EvEN11localstruct1fEZNS_3fooEvE16otherlocalstruct +myspace::foo()::localstruct::f(myspace::foo()::otherlocalstruct) +# APPLE LOCAL end mainline 2007-05-09 5173149