public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Dave MacLachlan <dmaclach@google.com>
To: binutils@sourceware.org, gcc-patches@gcc.gnu.org
Cc: DJ Delorie <dj@delorie.com>, Daniel Berlin <dannyb@google.com>,
	        Mike Stump <mrs@apple.com>
Subject: binutils/libiberty patch for c++filt to demangle ObjC++ symbols
Date: Fri, 13 Apr 2007 17:07:00 -0000	[thread overview]
Message-ID: <31CDB327-F3DB-4884-95EF-98C247D70A2F@google.com> (raw)
In-Reply-To: <200704130412.l3D4CbdI024712@localhost.localdomain>

[-- Attachment #1: Type: text/plain, Size: 826 bytes --]

Hey all..

This is a patch for c++filt so it can demangle ObjC++ symbols. Turns  
out that if you have an Objective C++ file (.mm) with a static var  
inside of a method it will get mangled in such a fashion that the  
current c++filt can't unmangle it:

@implementation Foo
+ (void)bar:(id)sender {
	static int baz = 1;
}
@end

gets mangled to

_ZZ11+[Foo bar:]E3baz

In it's standard mode, c++filt doesn't like any of the characters in  
the set "+[ :]" and causes it not to demangle the symbol.

The patch adds a new mode (-s objc++) that recognizes those  
characters correctly.

Mike: This would fix up 5129938 c++filt does not deal with ObjC++  
symbols

Cheers,
Dave

---------------------------------------------------------------
Dave MacLachlan                   Binary Composer
dmaclach@google.com         Google



[-- Attachment #2: binutils.patch --]
[-- Type: application/octet-stream, Size: 6950 bytes --]

Index: src/binutils/ChangeLog
===================================================================
RCS file: /cvs/src/src/binutils/ChangeLog,v
retrieving revision 1.1159
diff -u -p -r1.1159 ChangeLog
--- src/binutils/ChangeLog	10 Apr 2007 08:01:13 -0000	1.1159
+++ src/binutils/ChangeLog	12 Apr 2007 21:25:23 -0000
@@ -1,3 +1,11 @@
+2007-04-12  Dave MacLachlan  <dmaclach@google.com>
+
+  * cxxfilt.c Added support for objc++ demangling
+    (objcpp_symbol_characters): list of valid symbols for objc++ symbols
+    (main): added objcpp_demangling option
+  * demangle.h Added DMGL_OBJCPP, OBJCPP_DEMANGLING_STYLE_STRING, 
+    OBJCPP_DEMANGLING
+
 2007-04-10  Vladimir Prus  <vladimir@codesourcery.com>
 
 	* NEWS: Mention disjoint histograms support in
Index: src/binutils/cxxfilt.c
===================================================================
RCS file: /cvs/src/src/binutils/cxxfilt.c,v
retrieving revision 1.12
diff -u -p -r1.12 cxxfilt.c
--- src/binutils/cxxfilt.c	17 Feb 2007 13:33:54 -0000	1.12
+++ src/binutils/cxxfilt.c	12 Apr 2007 21:25:23 -0000
@@ -4,6 +4,7 @@
    Written by James Clark (jjc@jclark.uucp)
    Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
    Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
+   Modified by Dave MacLachlan (dmaclach@google.com) for ObjC++ demangling
 
    This file is part of GCC.
 
@@ -166,6 +167,32 @@ hp_symbol_characters (void)
   return "_$.<>#,*&[]:(){}";
 }
 
+/*  
+Return the string of non-alnum characters that may occur
+as a valid symbol name component in an Objective C++ object file.
+
+statics in Objective C methods get C++ mangled names, however the
+mangling includes the name of the Objective C method in it. So
+@implementation foo
+-(void)bar:(id)a {
+  static int baz;
+}
+gets mangled to
+__ZZ11-[foo bar:]E3baz
+
+So for objc++ symbols are composed of uppercase and lowercase letters,
+decimal digits, dollar symbol, period (.), minus (-), plus (+), open square
+bracket ([), close square bracket (]), color (:), space ( ), and
+underscore (_). A symbol can begin with a letter, underscore, minus,
+plus or dollar sign. If a symbol begins with a digit, it must contain a 
+non-digit character.
+*/
+static const char *
+objcpp_symbol_characters (void)
+{
+  return "_$.-+[]: ";
+}
+
 extern int main (int, char **);
 
 int
@@ -246,6 +273,9 @@ main (int argc, char **argv)
     case hp_demangling:
       valid_symbols = hp_symbol_characters ();
       break;
+    case objcpp_demangling:
+      valid_symbols = objcpp_symbol_characters ();
+      break;
     default:
       /* Folks should explicitly indicate the appropriate alphabet for
 	 each demangling.  Providing a default would allow the
Index: src/include/demangle.h
===================================================================
RCS file: /cvs/src/src/include/demangle.h,v
retrieving revision 1.23
diff -u -p -r1.23 demangle.h
--- src/include/demangle.h	30 Jan 2007 23:16:53 -0000	1.23
+++ src/include/demangle.h	12 Apr 2007 21:25:28 -0000
@@ -48,9 +48,10 @@ extern "C" {
 #define DMGL_EDG	 (1 << 13)
 #define DMGL_GNU_V3	 (1 << 14)
 #define DMGL_GNAT	 (1 << 15)
+#define DMGL_OBJCPP	 (1 << 16) /* Knows about some objcpp types */
 
 /* 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_OBJCPP)
 
 /* Enumeration of possible demangling styles.
 
@@ -72,7 +73,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,
+  objcpp_demangling = DMGL_OBJCPP
 } current_demangling_style;
 
 /* Define string names for the various demangling styles. */
@@ -87,6 +89,7 @@ extern enum demangling_styles
 #define GNU_V3_DEMANGLING_STYLE_STRING        "gnu-v3"
 #define JAVA_DEMANGLING_STYLE_STRING          "java"
 #define GNAT_DEMANGLING_STYLE_STRING          "gnat"
+#define OBJCPP_DEMANGLING_STYLE_STRING          "objc++"
 
 /* Some macros to test what demangling style is active. */
 
@@ -100,6 +103,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 OBJCPP_DEMANGLING (((int) CURRENT_DEMANGLING_STYLE) & DMGL_OBJCPP)
 
 /* Provide information about the available demangle styles. This code is
    pulled from gdb into libiberty because it is useful to binutils also.  */
Index: src/libiberty/ChangeLog
===================================================================
RCS file: /cvs/src/src/libiberty/ChangeLog,v
retrieving revision 1.421
diff -u -p -r1.421 ChangeLog
--- src/libiberty/ChangeLog	11 Apr 2007 20:01:26 -0000	1.421
+++ src/libiberty/ChangeLog	12 Apr 2007 21:25:28 -0000
@@ -1,3 +1,9 @@
+2007-04-12  Dave MacLachlan  <dmaclach@google.com>
+
+  * cplus-dem.c Added support for objc++ demangling style
+    (cplus_demangle): added OBJCPP_DEMANGLING to types that use 
+    cplus_demangle_v3
+
 2007-04-11  Thomas Neumann  tneumann@users.sourceforge.net
 
 	* argv.c: Use ANSI C declarations.
Index: src/libiberty/cplus-dem.c
===================================================================
RCS file: /cvs/src/src/libiberty/cplus-dem.c,v
retrieving revision 1.46
diff -u -p -r1.46 cplus-dem.c
--- src/libiberty/cplus-dem.c	12 May 2006 20:00:37 -0000	1.46
+++ src/libiberty/cplus-dem.c	12 Apr 2007 21:25:28 -0000
@@ -1,9 +1,10 @@
 /* Demangler for GNU C++
    Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   2000, 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
    Written by James Clark (jjc@jclark.uucp)
    Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling
    Modified by Satish Pai (pai@apollo.hp.com) for HP demangling
+   Modified by Dave MacLachlan (dmaclach@google.com) for ObjC++ demangling
 
 This file is part of the libiberty library.
 Libiberty is free software; you can redistribute it and/or
@@ -308,6 +309,12 @@ const struct demangler_engine libiberty_
   }
   ,
   {
+    OBJCPP_DEMANGLING_STYLE_STRING,
+    objcpp_demangling,
+    "ObjC++ style demangling"
+  }
+  ,
+  {
     NULL, unknown_demangling, NULL
   }
 };
@@ -857,7 +864,7 @@ cplus_demangle (const char *mangled, int
     work->options |= (int) current_demangling_style & DMGL_STYLE_MASK;
 
   /* The V3 ABI demangling is implemented elsewhere.  */
-  if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
+  if (GNU_V3_DEMANGLING || AUTO_DEMANGLING || OBJCPP_DEMANGLING)
     {
       ret = cplus_demangle_v3 (mangled, work->options);
       if (ret || GNU_V3_DEMANGLING)

[-- Attachment #3: Type: text/plain, Size: 4 bytes --]






       reply	other threads:[~2007-04-13 17:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <27E8A691-807E-4CB5-A7EE-6A3FAC4013A1@google.com>
     [not found] ` <200704130412.l3D4CbdI024712@localhost.localdomain>
2007-04-13 17:07   ` Dave MacLachlan [this message]
2007-04-13 17:27     ` Andrew Pinski
2007-04-20  0:02       ` Dave MacLachlan
2007-04-26  6:12         ` Eric Christopher
2007-04-26  6:13           ` Andrew Pinski
2007-04-26  7:01             ` Eric Christopher
2007-04-26 19:19           ` Dave MacLachlan
2007-04-27  0:33             ` Eric Christopher
2007-04-27  3:35               ` Dave MacLachlan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=31CDB327-F3DB-4884-95EF-98C247D70A2F@google.com \
    --to=dmaclach@google.com \
    --cc=binutils@sourceware.org \
    --cc=dannyb@google.com \
    --cc=dj@delorie.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mrs@apple.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).