Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Demangle ObjC symbols in symtab.c [4/5]
@ 2003-01-03 23:03 Adam Fedor
  2003-01-04  1:25 ` Michael Snyder
  2003-01-06 21:42 ` Elena Zannoni
  0 siblings, 2 replies; 10+ messages in thread
From: Adam Fedor @ 2003-01-03 23:03 UTC (permalink / raw)
  To: GDB Patches

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



[-- Attachment #2: objc22.patch --]
[-- Type: text/plain, Size: 8901 bytes --]

2003-01-03  Adam Fedor  <fedor@gnu.org>

	* symtab.c (symbol_init_demangled_name): Check for and demangle
	ObjC symbols.
	(make_symbol_completion_list): Look for ObjC symbols

Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.84
diff -u -p -r1.84 symtab.c
--- symtab.c	2 Jan 2003 14:27:26 -0000	1.84
+++ symtab.c	3 Jan 2003 03:20:14 -0000
@@ -440,8 +440,18 @@ void
 symbol_init_demangled_name (struct general_symbol_info *gsymbol,
                             struct obstack *obstack)
 {
-  char *mangled = gsymbol->name;
-  char *demangled = NULL;
-
   if (gsymbol->language == language_unknown)
     gsymbol->language = language_auto;
+
+  if (gsymbol->language == language_objc
+      || gsymbol->language == language_auto)
+    {
+      char *demangled =
+	objc_demangle (gsymbol->name);
+      if (demangled != NULL)
+	{
+	  gsymbol->language = language_objc;
+	  gsymbol->language_specific.objc_specific.demangled_name =
+	    obsavestring (demangled, strlen (demangled), (obstack));
+	  xfree (demangled);
+	}+

+      else
+	{
+	  gsymbol->language_specific.objc_specific.demangled_name = NULL;
+	}
+    }
+  
   if (gsymbol->language == language_cplus
       || gsymbol->language == language_auto)
     {
-      demangled =
+      char *demangled =
         cplus_demangle (gsymbol->name, DMGL_PARAMS | DMGL_ANSI);
       if (demangled != NULL)
         {
@@ -462,9 +478,10 @@ symbol_init_demangled_name (struct gener
           gsymbol->language_specific.cplus_specific.demangled_name = NULL;
         }
     }
+
   if (gsymbol->language == language_java)
     {
-      demangled =
+      char *demangled =
         cplus_demangle (gsymbol->name,
                         DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
       if (demangled != NULL)
@@ -479,6 +496,9 @@ symbol_init_demangled_name (struct gener
           gsymbol->language_specific.cplus_specific.demangled_name = NULL;
         }
     }
+
+  if (gsymbol->language == language_auto)
+    gsymbol->language = language_unknown;
 }
 
 /* Return the demangled name for a symbol based on the language for
@@ -831,7 +851,7 @@ lookup_symbol_aux (const char *name, con
     }
 #endif /* 0 */
 
-  /* C++: If requested to do so by the caller, 
+  /* C++/Java/Objective-C: If requested to do so by the caller, 
      check to see if NAME is a field of `this'. */
   if (is_a_field_of_this)
     {
@@ -1483,9 +1503,9 @@ find_main_psymtab (void)
    for now we don't worry about the slight inefficiency of looking for
    a match we'll never find, since it will go pretty quick.  Once the
    binary search terminates, we drop through and do a straight linear
-   search on the symbols.  Each symbol which is marked as being a C++
-   symbol (language_cplus set) has both the encoded and non-encoded names
-   tested for a match.
+   search on the symbols.  Each symbol which is marked as being a ObjC/C++
+   symbol (language_cplus or language_objc set) has both the encoded and 
+   non-encoded names tested for a match.
 
    If MANGLED_NAME is non-NULL, verify that any symbol we find has this
    particular mangled name.
@@ -3346,8 +3366,6 @@ make_symbol_completion_list (char *text,
       }
   }
 
-  sym_text_len = strlen (sym_text);
-
   return_val_size = 100;
   return_val_index = 0;
   return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
@@ -3356,6 +3374,8 @@ make_symbol_completion_list (char *text,
   /* Look through the partial symtabs for all symbols which begin
      by matching SYM_TEXT.  Add each one that you find to the list.  */
 
+  sym_text_len = strlen (sym_text);
+
   ALL_PSYMTABS (objfile, ps)
   {
     /* If the psymtab's been read in we'll get it when we search
@@ -3388,11 +3408,72 @@ make_symbol_completion_list (char *text,
      anything that isn't a text symbol (everything else will be
      handled by the psymtab code above).  */
 
-  ALL_MSYMBOLS (objfile, msymbol)
-  {
-    QUIT;
-    COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
-  }
+  /* ObjC: In case we are completing on a selector, look thru the msymbols
+     again and feed all the selectors into the mill. */
+
+  ALL_OBJFILES (objfile)
+    {
+      /*objfile_demangle_msymbols (objfile);*/
+      ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
+	{
+	  static char *tmp = NULL;
+	  static unsigned int tmplen = 0;
+	  
+	  char *method, *category, *selector;
+	  char *tmp2 = NULL;
+	  
+	  QUIT;
+	  
+	  method = SYMBOL_DEMANGLED_NAME (msymbol);
+	  if (method == NULL)
+	    method = SYMBOL_NAME (msymbol);
+	  if (method == NULL)
+	    continue;
+
+	  /* add the minimal symbol no matter what */
+	  completion_list_add_name (method, sym_text, sym_text_len, text, word);
+      
+	  /* is it a method? */
+	  if ((method[0] != '-') && (method[0] != '+'))
+	    continue;
+	  if (sym_text[0] == '[')
+	    /* complete on shortened method method */
+	    completion_list_add_name (method + 1, sym_text, sym_text_len, text, word);
+
+	  while ((strlen (method) + 1) >= tmplen)
+	    {
+	      tmplen = (tmplen == 0) ? 1024 : tmplen * 2;
+	      tmp = xrealloc (tmp, tmplen);
+	    }
+	  selector = strchr (method, ' ');
+	  if (selector != NULL)
+	    selector++;
+
+	  category = strchr (method, '(');
+
+	  if ((category != NULL) && (selector != NULL))
+	    {
+	      memcpy (tmp, method, (category - method));
+	      tmp[category - method] = ' ';
+	      memcpy (tmp + (category - method) + 1, selector, strlen (selector) + 1);
+	      completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
+	      if (sym_text[0] == '[')
+		completion_list_add_name (tmp + 1, sym_text, sym_text_len, text, word);
+	    }
+
+	  if (selector != NULL)
+	    {
+	      /* complete on selector only */
+	      strcpy (tmp, selector);
+	      tmp2 = strchr (tmp, ']');
+	      if (tmp2 != NULL)
+		*tmp2 = '\0';
+
+	      completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
+	    }
+	}
+    }
+
 
   /* Search upwards from currently selected frame (so that we can
      complete on local vars.  */
@@ -3409,6 +3490,7 @@ make_symbol_completion_list (char *text,
 
       ALL_BLOCK_SYMBOLS (b, i, sym)
 	{
+	  QUIT;
 	  COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
 	  if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
 	    {
@@ -3514,25 +3596,58 @@ make_file_symbol_completion_list (char *
       }
     else
       {
-	/* It is not a quoted string.  Break it based on the characters
-	   which are in symbols.  */
-	while (p > text)
-	  {
-	    if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
-	      --p;
-	    else
-	      break;
-	  }
+        /* It is not a quoted string.  Break it based on the characters
+           which are in symbols.  */
+        for (; p > text; --p)
+          {
+            if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
+              continue;
+            else
+              {
+                if ((current_language->la_language == language_objc))
+		  {
+                  if (p[-1] == ':')     /* might be part of a method name */
+                    continue;
+                  else if (p[-1] == '[' && (p[-2] == '-' || p[-2] == '+'))
+                    p -= 2;             /* beginning of a method name */
+                  else if (p[-1] == ' ' || p[-1] == '(' || p[-1] == ')')
+                    {                   /* might be part of a method name */
+                      char *t = p;
+
+                      /* Seeing a ' ' or a '(' is not conclusive evidence
+                         that we are in the middle of a method name.  However,
+                         finding "-[" or "+[" should be pretty un-ambiguous.
+                         Unfortunately we have to find it now to decide.  */
+
+                      while (t > text)
+                        if (isalnum (t[-1]) || t[-1] == '_' ||
+                            t[-1] == ' '    || t[-1] == ':' ||
+                            t[-1] == '('    || t[-1] == ')')
+                          --t;
+                        else
+                          break;
+
+                      if (t[-1] == '[' && (t[-2] == '-' || t[-2] == '+'))
+                        p = t - 2;      /* method name detected */
+                      /* else we leave with p unchanged */
+                    }
+		  }
+                break;
+              }
+          }
 	sym_text = p;
       }
   }
 
-  sym_text_len = strlen (sym_text);
-
   return_val_size = 10;
   return_val_index = 0;
   return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
   return_val[0] = NULL;
+
+  /* Look through the partial symtabs for all symbols which begin
+     by matching SYM_TEXT.  Add each one that you find to the list.  */
+
+  sym_text_len = strlen (sym_text);
 
   /* Find the symtab for SRCFILE (this loads it if it was not yet read
      in).  */

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] Demangle ObjC symbols in symtab.c [4/5]
  2003-01-03 23:03 [RFA] Demangle ObjC symbols in symtab.c [4/5] Adam Fedor
@ 2003-01-04  1:25 ` Michael Snyder
  2003-01-11  4:01   ` Adam Fedor
  2003-01-06 21:42 ` Elena Zannoni
  1 sibling, 1 reply; 10+ messages in thread
From: Michael Snyder @ 2003-01-04  1:25 UTC (permalink / raw)
  To: Adam Fedor; +Cc: GDB Patches

Adam Fedor wrote:
> 
> 2003-01-03  Adam Fedor  <fedor@gnu.org>
> 
>         * symtab.c (symbol_init_demangled_name): Check for and demangle
>         ObjC symbols.
>         (make_symbol_completion_list): Look for ObjC symbols

Not to be too fussy, but these two changes seem unrelated.
It might be better to submit them separately.  Easier to 
review and approve.


> 
> Index: symtab.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/symtab.c,v
> retrieving revision 1.84
> diff -u -p -r1.84 symtab.c
> --- symtab.c    2 Jan 2003 14:27:26 -0000       1.84
> +++ symtab.c    3 Jan 2003 03:20:14 -0000
> @@ -440,8 +440,18 @@ void
>  symbol_init_demangled_name (struct general_symbol_info *gsymbol,
>                              struct obstack *obstack)
>  {
> -  char *mangled = gsymbol->name;
> -  char *demangled = NULL;
> -

Was it necessary to move these variables into the inner scope?


>    if (gsymbol->language == language_unknown)
>      gsymbol->language = language_auto;
> +
> +  if (gsymbol->language == language_objc
> +      || gsymbol->language == language_auto)
> +    {
> +      char *demangled =
> +       objc_demangle (gsymbol->name);
> +      if (demangled != NULL)
> +       {
> +         gsymbol->language = language_objc;
> +         gsymbol->language_specific.objc_specific.demangled_name =
> +           obsavestring (demangled, strlen (demangled), (obstack));
> +         xfree (demangled);
> +       }+
> 
> +      else
> +       {
> +         gsymbol->language_specific.objc_specific.demangled_name = NULL;
> +       }
> +    }
> +

This certainly seems safe.

>    if (gsymbol->language == language_cplus
>        || gsymbol->language == language_auto)
>      {
> -      demangled =
> +      char *demangled =
>          cplus_demangle (gsymbol->name, DMGL_PARAMS | DMGL_ANSI);
>        if (demangled != NULL)
>          {
> @@ -462,9 +478,10 @@ symbol_init_demangled_name (struct gener
>            gsymbol->language_specific.cplus_specific.demangled_name = NULL;
>          }
>      }
> +
>    if (gsymbol->language == language_java)
>      {
> -      demangled =
> +      char *demangled =
>          cplus_demangle (gsymbol->name,
>                          DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
>        if (demangled != NULL)
> @@ -479,6 +496,9 @@ symbol_init_demangled_name (struct gener
>            gsymbol->language_specific.cplus_specific.demangled_name = NULL;
>          }
>      }
> +
> +  if (gsymbol->language == language_auto)
> +    gsymbol->language = language_unknown;

Yow!  Why in the world are you doing that?

>  }
> 
>  /* Return the demangled name for a symbol based on the language for
> @@ -831,7 +851,7 @@ lookup_symbol_aux (const char *name, con
>      }
>  #endif /* 0 */
> 
> -  /* C++: If requested to do so by the caller,
> +  /* C++/Java/Objective-C: If requested to do so by the caller,
>       check to see if NAME is a field of `this'. */
>    if (is_a_field_of_this)
>      {
> @@ -1483,9 +1503,9 @@ find_main_psymtab (void)
>     for now we don't worry about the slight inefficiency of looking for
>     a match we'll never find, since it will go pretty quick.  Once the
>     binary search terminates, we drop through and do a straight linear
> -   search on the symbols.  Each symbol which is marked as being a C++
> -   symbol (language_cplus set) has both the encoded and non-encoded names
> -   tested for a match.
> +   search on the symbols.  Each symbol which is marked as being a ObjC/C++
> +   symbol (language_cplus or language_objc set) has both the encoded and
> +   non-encoded names tested for a match.

Fairly obvious.

> 
>     If MANGLED_NAME is non-NULL, verify that any symbol we find has this
>     particular mangled name.
> @@ -3346,8 +3366,6 @@ make_symbol_completion_list (char *text,
>        }
>    }
> 
> -  sym_text_len = strlen (sym_text);
> -
>    return_val_size = 100;
>    return_val_index = 0;
>    return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
> @@ -3356,6 +3374,8 @@ make_symbol_completion_list (char *text,
>    /* Look through the partial symtabs for all symbols which begin
>       by matching SYM_TEXT.  Add each one that you find to the list.  */
> 
> +  sym_text_len = strlen (sym_text);
> +

This change seems like a no-op.

>    ALL_PSYMTABS (objfile, ps)
>    {
>      /* If the psymtab's been read in we'll get it when we search

From here down is a separate change.


> @@ -3388,11 +3408,72 @@ make_symbol_completion_list (char *text,
>       anything that isn't a text symbol (everything else will be
>       handled by the psymtab code above).  */
> 
> -  ALL_MSYMBOLS (objfile, msymbol)
> -  {
> -    QUIT;
> -    COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
> -  }
> +  /* ObjC: In case we are completing on a selector, look thru the msymbols
> +     again and feed all the selectors into the mill. */
> +
> +  ALL_OBJFILES (objfile)
> +    {
> +      /*objfile_demangle_msymbols (objfile);*/
> +      ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
> +       {
> +         static char *tmp = NULL;
> +         static unsigned int tmplen = 0;
> +
> +         char *method, *category, *selector;
> +         char *tmp2 = NULL;
> +
> +         QUIT;
> +
> +         method = SYMBOL_DEMANGLED_NAME (msymbol);
> +         if (method == NULL)
> +           method = SYMBOL_NAME (msymbol);
> +         if (method == NULL)
> +           continue;
> +
> +         /* add the minimal symbol no matter what */
> +         completion_list_add_name (method, sym_text, sym_text_len, text, word);
> +
> +         /* is it a method? */
> +         if ((method[0] != '-') && (method[0] != '+'))
> +           continue;
> +         if (sym_text[0] == '[')
> +           /* complete on shortened method method */
> +           completion_list_add_name (method + 1, sym_text, sym_text_len, text, word);
> +
> +         while ((strlen (method) + 1) >= tmplen)
> +           {
> +             tmplen = (tmplen == 0) ? 1024 : tmplen * 2;
> +             tmp = xrealloc (tmp, tmplen);
> +           }
> +         selector = strchr (method, ' ');
> +         if (selector != NULL)
> +           selector++;
> +
> +         category = strchr (method, '(');
> +
> +         if ((category != NULL) && (selector != NULL))
> +           {
> +             memcpy (tmp, method, (category - method));
> +             tmp[category - method] = ' ';
> +             memcpy (tmp + (category - method) + 1, selector, strlen (selector) + 1);
> +             completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
> +             if (sym_text[0] == '[')
> +               completion_list_add_name (tmp + 1, sym_text, sym_text_len, text, word);
> +           }
> +
> +         if (selector != NULL)
> +           {
> +             /* complete on selector only */
> +             strcpy (tmp, selector);
> +             tmp2 = strchr (tmp, ']');
> +             if (tmp2 != NULL)
> +               *tmp2 = '\0';
> +
> +             completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
> +           }
> +       }
> +    }
> +

Abstaining to comment on the above...

> 
>    /* Search upwards from currently selected frame (so that we can
>       complete on local vars.  */
> @@ -3409,6 +3490,7 @@ make_symbol_completion_list (char *text,
> 
>        ALL_BLOCK_SYMBOLS (b, i, sym)
>         {
> +         QUIT;

That's good (and obvious)

>           COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
>           if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
>             {
> @@ -3514,25 +3596,58 @@ make_file_symbol_completion_list (char *
>        }
>      else
>        {
> -       /* It is not a quoted string.  Break it based on the characters
> -          which are in symbols.  */
> -       while (p > text)
> -         {
> -           if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
> -             --p;
> -           else
> -             break;
> -         }

Indentation change below?

> +        /* It is not a quoted string.  Break it based on the characters
> +           which are in symbols.  */
> +        for (; p > text; --p)
> +          {
> +            if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
> +              continue;
> +            else
> +              {
> +                if ((current_language->la_language == language_objc))
> +                 {
> +                  if (p[-1] == ':')     /* might be part of a method name */
> +                    continue;
> +                  else if (p[-1] == '[' && (p[-2] == '-' || p[-2] == '+'))
> +                    p -= 2;             /* beginning of a method name */
> +                  else if (p[-1] == ' ' || p[-1] == '(' || p[-1] == ')')
> +                    {                   /* might be part of a method name */
> +                      char *t = p;
> +
> +                      /* Seeing a ' ' or a '(' is not conclusive evidence
> +                         that we are in the middle of a method name.  However,
> +                         finding "-[" or "+[" should be pretty un-ambiguous.
> +                         Unfortunately we have to find it now to decide.  */
> +
> +                      while (t > text)
> +                        if (isalnum (t[-1]) || t[-1] == '_' ||
> +                            t[-1] == ' '    || t[-1] == ':' ||
> +                            t[-1] == '('    || t[-1] == ')')
> +                          --t;
> +                        else
> +                          break;
> +
> +                      if (t[-1] == '[' && (t[-2] == '-' || t[-2] == '+'))
> +                        p = t - 2;      /* method name detected */
> +                      /* else we leave with p unchanged */
> +                    }
> +                 }
> +                break;
> +              }
> +          }

Extra level of brackets.  Seems safe, since all the new code
is protected with if(objc).

>         sym_text = p;
>        }
>    }
> 
> -  sym_text_len = strlen (sym_text);
> -
>    return_val_size = 10;
>    return_val_index = 0;
>    return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
>    return_val[0] = NULL;
> +
> +  /* Look through the partial symtabs for all symbols which begin
> +     by matching SYM_TEXT.  Add each one that you find to the list.  */
> +
> +  sym_text_len = strlen (sym_text);

Again, this change seems gratuitous.

> 
>    /* Find the symtab for SRCFILE (this loads it if it was not yet read
>       in).  */


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] Demangle ObjC symbols in symtab.c [4/5]
  2003-01-03 23:03 [RFA] Demangle ObjC symbols in symtab.c [4/5] Adam Fedor
  2003-01-04  1:25 ` Michael Snyder
@ 2003-01-06 21:42 ` Elena Zannoni
  2003-01-07 23:14   ` Daniel Jacobowitz
  2003-01-11  3:59   ` Adam Fedor
  1 sibling, 2 replies; 10+ messages in thread
From: Elena Zannoni @ 2003-01-06 21:42 UTC (permalink / raw)
  To: Adam Fedor; +Cc: GDB Patches

Adam Fedor writes:
 > 2003-01-03  Adam Fedor  <fedor@gnu.org>
 > 
 > 	* symtab.c (symbol_init_demangled_name): Check for and demangle
 > 	ObjC symbols.
 > 	(make_symbol_completion_list): Look for ObjC symbols
 > 
 > Index: symtab.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/symtab.c,v
 > retrieving revision 1.84
 > diff -u -p -r1.84 symtab.c
 > --- symtab.c	2 Jan 2003 14:27:26 -0000	1.84
 > +++ symtab.c	3 Jan 2003 03:20:14 -0000
 > @@ -440,8 +440,18 @@ void
 >  symbol_init_demangled_name (struct general_symbol_info *gsymbol,
 >                              struct obstack *obstack)
 >  {
 > -  char *mangled = gsymbol->name;
 > -  char *demangled = NULL;
 > -
 >    if (gsymbol->language == language_unknown)
 >      gsymbol->language = language_auto;
 > +
 > +  if (gsymbol->language == language_objc
 > +      || gsymbol->language == language_auto)
 > +    {
 > +      char *demangled =
 > +	objc_demangle (gsymbol->name);
 > +      if (demangled != NULL)
 > +	{
 > +	  gsymbol->language = language_objc;
 > +	  gsymbol->language_specific.objc_specific.demangled_name =
 > +	    obsavestring (demangled, strlen (demangled), (obstack));
 > +	  xfree (demangled);


 > +	}+
       ^^^^ ??? I assume it's a cut/paste typo.

 > 
 > +      else
 > +	{
 > +	  gsymbol->language_specific.objc_specific.demangled_name = NULL;
 > +	}
 > +    }
 > +  
 >    if (gsymbol->language == language_cplus
 >        || gsymbol->language == language_auto)
 >      {
 > -      demangled =
 > +      char *demangled =
 >          cplus_demangle (gsymbol->name, DMGL_PARAMS | DMGL_ANSI);
 >        if (demangled != NULL)
 >          {
 > @@ -462,9 +478,10 @@ symbol_init_demangled_name (struct gener
 >            gsymbol->language_specific.cplus_specific.demangled_name = NULL;
 >          }
 >      }
 > +
 >    if (gsymbol->language == language_java)
 >      {
 > -      demangled =
 > +      char *demangled =
 >          cplus_demangle (gsymbol->name,
 >                          DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
 >        if (demangled != NULL)
 > @@ -479,6 +496,9 @@ symbol_init_demangled_name (struct gener
 >            gsymbol->language_specific.cplus_specific.demangled_name = NULL;
 >          }
 >      }
 > +
 > +  if (gsymbol->language == language_auto)
 > +    gsymbol->language = language_unknown;

Why this? There was a (kind of a) rationale on setting the language to
auto, to speed up some searches. There was a controversy about that
too, and it never got resolved. Do the current C++ people have an opinion?

See:
http://sources.redhat.com/ml/gdb-patches/2000-09/msg00241.html

and
http://sources.redhat.com/ml/gdb-patches/2000-10/msg00251.html

Also, why do you move the declaration of the variable 'demangle'
inside each block? Ok on deleting the variable 'mangled'.


 >  }
 >  
 >  /* Return the demangled name for a symbol based on the language for



 > @@ -831,7 +851,7 @@ lookup_symbol_aux (const char *name, con
 >      }
 >  #endif /* 0 */
 >  
 > -  /* C++: If requested to do so by the caller, 
 > +  /* C++/Java/Objective-C: If requested to do so by the caller, 
 >       check to see if NAME is a field of `this'. */
 >    if (is_a_field_of_this)
 >      {
 > @@ -1483,9 +1503,9 @@ find_main_psymtab (void)
 >     for now we don't worry about the slight inefficiency of looking for
 >     a match we'll never find, since it will go pretty quick.  Once the
 >     binary search terminates, we drop through and do a straight linear
 > -   search on the symbols.  Each symbol which is marked as being a C++
 > -   symbol (language_cplus set) has both the encoded and non-encoded names
 > -   tested for a match.
 > +   search on the symbols.  Each symbol which is marked as being a ObjC/C++
 > +   symbol (language_cplus or language_objc set) has both the encoded and 
 > +   non-encoded names tested for a match.
 >  
 >     If MANGLED_NAME is non-NULL, verify that any symbol we find has this
 >     particular mangled name.
 > @@ -3346,8 +3366,6 @@ make_symbol_completion_list (char *text,
 >        }
 >    }
 >  
 > -  sym_text_len = strlen (sym_text);
 > -
 >    return_val_size = 100;
 >    return_val_index = 0;
 >    return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
 > @@ -3356,6 +3374,8 @@ make_symbol_completion_list (char *text,
 >    /* Look through the partial symtabs for all symbols which begin
 >       by matching SYM_TEXT.  Add each one that you find to the list.  */
 >  
 > +  sym_text_len = strlen (sym_text);
 > +
 >    ALL_PSYMTABS (objfile, ps)
 >    {
 >      /* If the psymtab's been read in we'll get it when we search
 > @@ -3388,11 +3408,72 @@ make_symbol_completion_list (char *text,
 >       anything that isn't a text symbol (everything else will be
 >       handled by the psymtab code above).  */
 >  
 > -  ALL_MSYMBOLS (objfile, msymbol)
 > -  {
 > -    QUIT;
 > -    COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
 > -  }
 > +  /* ObjC: In case we are completing on a selector, look thru the msymbols
 > +     again and feed all the selectors into the mill. */
 > +
 > +  ALL_OBJFILES (objfile)
 > +    {
 > +      /*objfile_demangle_msymbols (objfile);*/

Do you need this line? If not, could you collapse the two for-loop
macros into the ALL_MSYMBOLS one? you don't use the objfile variable
in the code below, and it would minimize the diffs.

 > +      ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
 > +	{
 > +	  static char *tmp = NULL;
 > +	  static unsigned int tmplen = 0;
 > +	  
 > +	  char *method, *category, *selector;
 > +	  char *tmp2 = NULL;
 > +	  
 > +	  QUIT;
 > +	  
 > +	  method = SYMBOL_DEMANGLED_NAME (msymbol);
 > +	  if (method == NULL)
 > +	    method = SYMBOL_NAME (msymbol);
 > +	  if (method == NULL)
 > +	    continue;
 > +
 > +	  /* add the minimal symbol no matter what */
 > +	  completion_list_add_name (method, sym_text, sym_text_len, text, word);
 > +     

Why don't you use the (yes, awful) macro COMPLETION_LIST_ADD_SYMBOL ? 

 
 > +	  /* is it a method? */
 > +	  if ((method[0] != '-') && (method[0] != '+'))
 > +	    continue;
 > +	  if (sym_text[0] == '[')
 > +	    /* complete on shortened method method */
 > +	    completion_list_add_name (method + 1, sym_text, sym_text_len, text, word);

Do you add 2 methods for a symbol that starts with '['?


 > +
 > +	  while ((strlen (method) + 1) >= tmplen)
 > +	    {
 > +	      tmplen = (tmplen == 0) ? 1024 : tmplen * 2;

Conditional expressions are generally frowned upon.

 > +	      tmp = xrealloc (tmp, tmplen);
 > +	    }
 > +	  selector = strchr (method, ' ');
 > +	  if (selector != NULL)
 > +	    selector++;
 > +
 > +	  category = strchr (method, '(');
 > +
 > +	  if ((category != NULL) && (selector != NULL))
 > +	    {
 > +	      memcpy (tmp, method, (category - method));
 > +	      tmp[category - method] = ' ';
 > +	      memcpy (tmp + (category - method) + 1, selector, strlen (selector) + 1);
 > +	      completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
 > +	      if (sym_text[0] == '[')
 > +		completion_list_add_name (tmp + 1, sym_text, sym_text_len, text, word);
 > +	    }
 > +
 > +	  if (selector != NULL)
 > +	    {
 > +	      /* complete on selector only */
 > +	      strcpy (tmp, selector);
 > +	      tmp2 = strchr (tmp, ']');
 > +	      if (tmp2 != NULL)
 > +		*tmp2 = '\0';
 > +
 > +	      completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
 > +	    }

I am not sure I understand: how many variations of the same name get
added to the completion list?

 > +	}
 > +    }
 > +
 >  
 >    /* Search upwards from currently selected frame (so that we can
 >       complete on local vars.  */
 > @@ -3409,6 +3490,7 @@ make_symbol_completion_list (char *text,
 >  
 >        ALL_BLOCK_SYMBOLS (b, i, sym)
 >  	{
 > +	  QUIT;
 >  	  COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
 >  	  if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
 >  	    {
 > @@ -3514,25 +3596,58 @@ make_file_symbol_completion_list (char *
 >        }
 >      else
 >        {
 > -	/* It is not a quoted string.  Break it based on the characters
 > -	   which are in symbols.  */
 > -	while (p > text)
 > -	  {
 > -	    if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
 > -	      --p;
 > -	    else
 > -	      break;
 > -	  }
 > +        /* It is not a quoted string.  Break it based on the characters
 > +           which are in symbols.  */
 > +        for (; p > text; --p)
 > +          {
 > +            if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
 > +              continue;
 > +            else
 > +              {
 > +                if ((current_language->la_language == language_objc))
 > +		  {
 > +                  if (p[-1] == ':')     /* might be part of a method name */
 > +                    continue;
 > +                  else if (p[-1] == '[' && (p[-2] == '-' || p[-2] == '+'))
 > +                    p -= 2;             /* beginning of a method name */
 > +                  else if (p[-1] == ' ' || p[-1] == '(' || p[-1] == ')')
 > +                    {                   /* might be part of a method name */
 > +                      char *t = p;
 > +
 > +                      /* Seeing a ' ' or a '(' is not conclusive evidence
 > +                         that we are in the middle of a method name.  However,
 > +                         finding "-[" or "+[" should be pretty un-ambiguous.
 > +                         Unfortunately we have to find it now to decide.  */
 > +
 > +                      while (t > text)
 > +                        if (isalnum (t[-1]) || t[-1] == '_' ||
 > +                            t[-1] == ' '    || t[-1] == ':' ||
 > +                            t[-1] == '('    || t[-1] == ')')
 > +                          --t;
 > +                        else
 > +                          break;
 > +
 > +                      if (t[-1] == '[' && (t[-2] == '-' || t[-2] == '+'))
 > +                        p = t - 2;      /* method name detected */
 > +                      /* else we leave with p unchanged */
 > +                    }
 > +		  }
 > +                break;
 > +              }
 > +          }
 >  	sym_text = p;
 >        }
 >    }
 >  
 > -  sym_text_len = strlen (sym_text);
 > -
 >    return_val_size = 10;
 >    return_val_index = 0;
 >    return_val = (char **) xmalloc ((return_val_size + 1) * sizeof (char *));
 >    return_val[0] = NULL;
 > +
 > +  /* Look through the partial symtabs for all symbols which begin
 > +     by matching SYM_TEXT.  Add each one that you find to the list.  */
 > +
 > +  sym_text_len = strlen (sym_text);
 >  
 >    /* Find the symtab for SRCFILE (this loads it if it was not yet read
 >       in).  */


As for the other patch, the comments should begin with a capital
letter and end with a period.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] Demangle ObjC symbols in symtab.c [4/5]
  2003-01-06 21:42 ` Elena Zannoni
@ 2003-01-07 23:14   ` Daniel Jacobowitz
  2003-01-11  3:59   ` Adam Fedor
  1 sibling, 0 replies; 10+ messages in thread
From: Daniel Jacobowitz @ 2003-01-07 23:14 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: Adam Fedor, GDB Patches

On Mon, Jan 06, 2003 at 04:46:32PM -0500, Elena Zannoni wrote:
> Adam Fedor writes:
>  > 2003-01-03  Adam Fedor  <fedor@gnu.org>
>  > 
>  > 	* symtab.c (symbol_init_demangled_name): Check for and demangle
>  > 	ObjC symbols.
>  > 	(make_symbol_completion_list): Look for ObjC symbols
>  > 
>  > Index: symtab.c
>  > ===================================================================
>  > RCS file: /cvs/src/src/gdb/symtab.c,v
>  > retrieving revision 1.84
>  > diff -u -p -r1.84 symtab.c
>  > --- symtab.c	2 Jan 2003 14:27:26 -0000	1.84
>  > +++ symtab.c	3 Jan 2003 03:20:14 -0000
>  > @@ -440,8 +440,18 @@ void
>  >  symbol_init_demangled_name (struct general_symbol_info *gsymbol,
>  >                              struct obstack *obstack)
>  >  {
>  > -  char *mangled = gsymbol->name;
>  > -  char *demangled = NULL;
>  > -
>  >    if (gsymbol->language == language_unknown)
>  >      gsymbol->language = language_auto;
>  > +
>  > +  if (gsymbol->language == language_objc
>  > +      || gsymbol->language == language_auto)
>  > +    {
>  > +      char *demangled =
>  > +	objc_demangle (gsymbol->name);
>  > +      if (demangled != NULL)
>  > +	{
>  > +	  gsymbol->language = language_objc;
>  > +	  gsymbol->language_specific.objc_specific.demangled_name =
>  > +	    obsavestring (demangled, strlen (demangled), (obstack));
>  > +	  xfree (demangled);
> 
> 
>  > +	}+
>        ^^^^ ??? I assume it's a cut/paste typo.
> 
>  > 
>  > +      else
>  > +	{
>  > +	  gsymbol->language_specific.objc_specific.demangled_name = NULL;
>  > +	}
>  > +    }
>  > +  
>  >    if (gsymbol->language == language_cplus
>  >        || gsymbol->language == language_auto)
>  >      {
>  > -      demangled =
>  > +      char *demangled =
>  >          cplus_demangle (gsymbol->name, DMGL_PARAMS | DMGL_ANSI);
>  >        if (demangled != NULL)
>  >          {
>  > @@ -462,9 +478,10 @@ symbol_init_demangled_name (struct gener
>  >            gsymbol->language_specific.cplus_specific.demangled_name = NULL;
>  >          }
>  >      }
>  > +
>  >    if (gsymbol->language == language_java)
>  >      {
>  > -      demangled =
>  > +      char *demangled =
>  >          cplus_demangle (gsymbol->name,
>  >                          DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
>  >        if (demangled != NULL)
>  > @@ -479,6 +496,9 @@ symbol_init_demangled_name (struct gener
>  >            gsymbol->language_specific.cplus_specific.demangled_name = NULL;
>  >          }
>  >      }
>  > +
>  > +  if (gsymbol->language == language_auto)
>  > +    gsymbol->language = language_unknown;
> 
> Why this? There was a (kind of a) rationale on setting the language to
> auto, to speed up some searches. There was a controversy about that
> too, and it never got resolved. Do the current C++ people have an opinion?
> 
> See:
> http://sources.redhat.com/ml/gdb-patches/2000-09/msg00241.html
> 
> and
> http://sources.redhat.com/ml/gdb-patches/2000-10/msg00251.html

Well, I'm discussing (off-list) ways to prevent this function from
being called multiple times; I haven't worked out how they interact
with the file's language yet, however.  I need to investigate that some
more.

I don't like the set back to unknown very much, in principle.  And
whatever problem Dan was discussing in the messages above appears to be
gone, or at least worked around somewhere else.


-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] Demangle ObjC symbols in symtab.c [4/5]
  2003-01-06 21:42 ` Elena Zannoni
  2003-01-07 23:14   ` Daniel Jacobowitz
@ 2003-01-11  3:59   ` Adam Fedor
  2003-01-11  5:24     ` Daniel Jacobowitz
  1 sibling, 1 reply; 10+ messages in thread
From: Adam Fedor @ 2003-01-11  3:59 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: GDB Patches

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



Elena Zannoni wrote:
> Adam Fedor writes:
>  > 2003-01-03  Adam Fedor  <fedor@gnu.org>
>  > 
>  > 	* symtab.c (symbol_init_demangled_name): Check for and demangle
>  > 	ObjC symbols.
>  > 	(make_symbol_completion_list): Look for ObjC symbols
>  > 
>  > Index: symtab.c
>  > ===================================================================
>  > RCS file: /cvs/src/src/gdb/symtab.c,v
>  > retrieving revision 1.84
>  > diff -u -p -r1.84 symtab.c
[...snip...]
>  > +      ALL_OBJFILE_MSYMBOLS (objfile, msymbol)
>  > +	{
>  > +	  static char *tmp = NULL;
>  > +	  static unsigned int tmplen = 0;
>  > +	  
>  > +	  char *method, *category, *selector;
>  > +	  char *tmp2 = NULL;
>  > +	  
>  > +	  QUIT;
>  > +	  
>  > +	  method = SYMBOL_DEMANGLED_NAME (msymbol);
>  > +	  if (method == NULL)
>  > +	    method = SYMBOL_NAME (msymbol);
>  > +	  if (method == NULL)
>  > +	    continue;
>  > +
>  > +	  /* add the minimal symbol no matter what */
>  > +	  completion_list_add_name (method, sym_text, sym_text_len, text, word);
>  > +     
> 
> Why don't you use the (yes, awful) macro COMPLETION_LIST_ADD_SYMBOL ? 
> 

I guess I'm not sure that SYMBOL_NAME(msymbol) is always non-NULL. Is 
that the case?

>  
>  > +	  /* is it a method? */
>  > +	  if ((method[0] != '-') && (method[0] != '+'))
>  > +	    continue;
>  > +	  if (sym_text[0] == '[')
>  > +	    /* complete on shortened method method */
>  > +	    completion_list_add_name (method + 1, sym_text, sym_text_len, text, word);
> 
> Do you add 2 methods for a symbol that starts with '['?
> 
> 
>  > +
>  > +	  while ((strlen (method) + 1) >= tmplen)
>  > +	    {
>  > +	      tmplen = (tmplen == 0) ? 1024 : tmplen * 2;
> 
> Conditional expressions are generally frowned upon.
> 
>  > +	      tmp = xrealloc (tmp, tmplen);
>  > +	    }
>  > +	  selector = strchr (method, ' ');
>  > +	  if (selector != NULL)
>  > +	    selector++;
>  > +
>  > +	  category = strchr (method, '(');
>  > +
>  > +	  if ((category != NULL) && (selector != NULL))
>  > +	    {
>  > +	      memcpy (tmp, method, (category - method));
>  > +	      tmp[category - method] = ' ';
>  > +	      memcpy (tmp + (category - method) + 1, selector, strlen (selector) + 1);
>  > +	      completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
>  > +	      if (sym_text[0] == '[')
>  > +		completion_list_add_name (tmp + 1, sym_text, sym_text_len, text, word);
>  > +	    }
>  > +
>  > +	  if (selector != NULL)
>  > +	    {
>  > +	      /* complete on selector only */
>  > +	      strcpy (tmp, selector);
>  > +	      tmp2 = strchr (tmp, ']');
>  > +	      if (tmp2 != NULL)
>  > +		*tmp2 = '\0';
>  > +
>  > +	      completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
>  > +	    }
> 
> I am not sure I understand: how many variations of the same name get
> added to the completion list?
> 
>  > +	}
>

For a particular completion symbol, which could be something like

isFlip or [MyObject isFlip

You could potentially complete on any of

-[MyObject(PrivateCategory) isFlipped]
-[MyObject isFlipped]
[MyObject isFlipped]
isFlipped


All of these symbols COULD be unique, although in practice this is 
unlikely. Attached is an updated patch (second half only).


[-- Attachment #2: objc22b.patch --]
[-- Type: text/plain, Size: 4855 bytes --]

2003-01-10  Adam Fedor  <fedor@gnu.org>

	* symtab.c (make_symbol_completion_list): Look for ObjC
	symbols.

Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.84
diff -u -p -r1.84 symtab.c
--- symtab.c	2 Jan 2003 14:27:26 -0000	1.84
+++ symtab.c	11 Jan 2003 03:55:19 -0000
@@ -3388,10 +3406,69 @@ make_symbol_completion_list (char *text,
      anything that isn't a text symbol (everything else will be
      handled by the psymtab code above).  */
 
+  /* ObjC: In case we are completing on a selector, look thru the msymbols
+     again and feed all the selectors into the mill.  */
+
   ALL_MSYMBOLS (objfile, msymbol)
   {
+    static char *tmp = NULL;
+    static unsigned int tmplen = 0;
+    
+    char *method, *category, *selector;
+    char *tmp2 = NULL;
+    
     QUIT;
-    COMPLETION_LIST_ADD_SYMBOL (msymbol, sym_text, sym_text_len, text, word);
+    
+    method = SYMBOL_DEMANGLED_NAME (msymbol);
+    if (method == NULL)
+      method = SYMBOL_NAME (msymbol);
+    if (method == NULL)
+      continue;
+    
+    /* Add the minimal symbol no matter what.  */
+    completion_list_add_name (method, sym_text, sym_text_len, text, word);
+    
+    /* Is it a method?  */
+    if ((method[0] != '-') && (method[0] != '+'))
+      continue;
+    if (sym_text[0] == '[')
+      /* Complete on shortened method method.  */
+      completion_list_add_name (method + 1, sym_text, sym_text_len, text, word);
+    
+    while ((strlen (method) + 1) >= tmplen)
+      {
+	if (tmplen == 0)
+	  tmplen = 1024;
+	else
+	  tmplen *= 2;
+	tmp = xrealloc (tmp, tmplen);
+      }
+    selector = strchr (method, ' ');
+    if (selector != NULL)
+      selector++;
+    
+    category = strchr (method, '(');
+    
+    if ((category != NULL) && (selector != NULL))
+      {
+	memcpy (tmp, method, (category - method));
+	tmp[category - method] = ' ';
+	memcpy (tmp + (category - method) + 1, selector, strlen (selector) + 1);
+	completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
+	if (sym_text[0] == '[')
+	  completion_list_add_name (tmp + 1, sym_text, sym_text_len, text, word);
+      }
+    
+    if (selector != NULL)
+      {
+	/* Complete on selector only.  */
+	strcpy (tmp, selector);
+	tmp2 = strchr (tmp, ']');
+	if (tmp2 != NULL)
+	  *tmp2 = '\0';
+	
+	completion_list_add_name (tmp, sym_text, sym_text_len, text, word);
+      }
   }
 
   /* Search upwards from currently selected frame (so that we can
@@ -3409,6 +3486,7 @@ make_symbol_completion_list (char *text,
 
       ALL_BLOCK_SYMBOLS (b, i, sym)
 	{
+	  QUIT;
 	  COMPLETION_LIST_ADD_SYMBOL (sym, sym_text, sym_text_len, text, word);
 	  if (SYMBOL_CLASS (sym) == LOC_TYPEDEF)
 	    {
@@ -3514,15 +3592,45 @@ make_file_symbol_completion_list (char *
       }
     else
       {
-	/* It is not a quoted string.  Break it based on the characters
-	   which are in symbols.  */
-	while (p > text)
-	  {
-	    if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
-	      --p;
-	    else
-	      break;
-	  }
+        /* It is not a quoted string.  Break it based on the characters
+           which are in symbols.  */
+        for (; p > text; --p)
+          {
+            if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0')
+              continue;
+            else
+              {
+                if ((current_language->la_language == language_objc))
+		  {
+                  if (p[-1] == ':')     /* might be part of a method name */
+                    continue;
+                  else if (p[-1] == '[' && (p[-2] == '-' || p[-2] == '+'))
+                    p -= 2;             /* beginning of a method name */
+                  else if (p[-1] == ' ' || p[-1] == '(' || p[-1] == ')')
+                    {                   /* might be part of a method name */
+                      char *t = p;
+
+                      /* Seeing a ' ' or a '(' is not conclusive evidence
+                         that we are in the middle of a method name.  However,
+                         finding "-[" or "+[" should be pretty un-ambiguous.
+                         Unfortunately we have to find it now to decide.  */
+
+                      while (t > text)
+                        if (isalnum (t[-1]) || t[-1] == '_' ||
+                            t[-1] == ' '    || t[-1] == ':' ||
+                            t[-1] == '('    || t[-1] == ')')
+                          --t;
+                        else
+                          break;
+
+                      if (t[-1] == '[' && (t[-2] == '-' || t[-2] == '+'))
+                        p = t - 2;      /* method name detected */
+                      /* else we leave with p unchanged */
+                    }
+		  }
+                break;
+              }
+          }
 	sym_text = p;
       }
   }

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] Demangle ObjC symbols in symtab.c [4/5]
  2003-01-04  1:25 ` Michael Snyder
@ 2003-01-11  4:01   ` Adam Fedor
  2003-02-19 14:59     ` Elena Zannoni
  0 siblings, 1 reply; 10+ messages in thread
From: Adam Fedor @ 2003-01-11  4:01 UTC (permalink / raw)
  To: GDB Patches; +Cc: Michael Snyder, Elena Zannoni

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


Michael Snyder wrote:
> Adam Fedor wrote:
> 
>>2003-01-03  Adam Fedor  <fedor@gnu.org>
>>
>>        * symtab.c (symbol_init_demangled_name): Check for and demangle
>>        ObjC symbols.
>>        (make_symbol_completion_list): Look for ObjC symbols
> 
> 
> Not to be too fussy, but these two changes seem unrelated.
> It might be better to submit them separately.  Easier to 
> review and approve.
> 

Here's the first half of the patch again with a small change.


[-- Attachment #2: objc22a.patch --]
[-- Type: text/plain, Size: 2969 bytes --]

2003-01-10  Adam Fedor  <fedor@gnu.org>

	* symtab.c (symbol_init_demangled_name): Check for and demangle
	ObjC symbols.

Index: symtab.c
===================================================================
RCS file: /cvs/src/src/gdb/symtab.c,v
retrieving revision 1.84
diff -u -p -r1.84 symtab.c
--- symtab.c	2 Jan 2003 14:27:26 -0000	1.84
+++ symtab.c	11 Jan 2003 03:51:34 -0000
@@ -40,6 +40,7 @@
 #include "linespec.h"
 #include "source.h"
 #include "filenames.h"		/* for FILENAME_CMP */
+#include "objc-lang.h"
 
 #include "gdb_obstack.h"
 
@@ -440,15 +441,31 @@ void
 symbol_init_demangled_name (struct general_symbol_info *gsymbol,
                             struct obstack *obstack)
 {
-  char *mangled = gsymbol->name;
-  char *demangled = NULL;
-
   if (gsymbol->language == language_unknown)
     gsymbol->language = language_auto;
+
+  if (gsymbol->language == language_objc
+      || gsymbol->language == language_auto)
+    {
+      char *demangled =
+	objc_demangle (gsymbol->name);
+      if (demangled != NULL)
+	{
+	  gsymbol->language = language_objc;
+	  gsymbol->language_specific.objc_specific.demangled_name =
+	    obsavestring (demangled, strlen (demangled), (obstack));
+	  xfree (demangled);
+	}
+      else
+	{
+	  gsymbol->language_specific.objc_specific.demangled_name = NULL;
+	}
+    }
+  
   if (gsymbol->language == language_cplus
       || gsymbol->language == language_auto)
     {
-      demangled =
+      char *demangled =
         cplus_demangle (gsymbol->name, DMGL_PARAMS | DMGL_ANSI);
       if (demangled != NULL)
         {
@@ -462,9 +479,10 @@ symbol_init_demangled_name (struct gener
           gsymbol->language_specific.cplus_specific.demangled_name = NULL;
         }
     }
+
   if (gsymbol->language == language_java)
     {
-      demangled =
+      char *demangled =
         cplus_demangle (gsymbol->name,
                         DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
       if (demangled != NULL)
@@ -831,7 +849,7 @@ lookup_symbol_aux (const char *name, con
     }
 #endif /* 0 */
 
-  /* C++: If requested to do so by the caller, 
+  /* C++/Java/Objective-C: If requested to do so by the caller, 
      check to see if NAME is a field of `this'. */
   if (is_a_field_of_this)
     {
@@ -1483,9 +1501,9 @@ find_main_psymtab (void)
    for now we don't worry about the slight inefficiency of looking for
    a match we'll never find, since it will go pretty quick.  Once the
    binary search terminates, we drop through and do a straight linear
-   search on the symbols.  Each symbol which is marked as being a C++
-   symbol (language_cplus set) has both the encoded and non-encoded names
-   tested for a match.
+   search on the symbols.  Each symbol which is marked as being a ObjC/C++
+   symbol (language_cplus or language_objc set) has both the encoded and 
+   non-encoded names tested for a match.
 
    If MANGLED_NAME is non-NULL, verify that any symbol we find has this
    particular mangled name.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] Demangle ObjC symbols in symtab.c [4/5]
  2003-01-11  3:59   ` Adam Fedor
@ 2003-01-11  5:24     ` Daniel Jacobowitz
  0 siblings, 0 replies; 10+ messages in thread
From: Daniel Jacobowitz @ 2003-01-11  5:24 UTC (permalink / raw)
  To: GDB Patches

On Fri, Jan 10, 2003 at 08:58:58PM -0700, Adam Fedor wrote:
> I guess I'm not sure that SYMBOL_NAME(msymbol) is always non-NULL. Is 
> that the case?

It should be, yes; otherwise plenty of other places in minsyms.c will
crash.


-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] Demangle ObjC symbols in symtab.c [4/5]
  2003-01-11  4:01   ` Adam Fedor
@ 2003-02-19 14:59     ` Elena Zannoni
  2003-02-19 15:15       ` Elena Zannoni
  0 siblings, 1 reply; 10+ messages in thread
From: Elena Zannoni @ 2003-02-19 14:59 UTC (permalink / raw)
  To: Adam Fedor; +Cc: GDB Patches, Michael Snyder, Elena Zannoni

Adam Fedor writes:
 > 
 > Michael Snyder wrote:
 > > Adam Fedor wrote:
 > > 
 > >>2003-01-03  Adam Fedor  <fedor@gnu.org>
 > >>
 > >>        * symtab.c (symbol_init_demangled_name): Check for and demangle
 > >>        ObjC symbols.
 > >>        (make_symbol_completion_list): Look for ObjC symbols
 > > 
 > > 
 > > Not to be too fussy, but these two changes seem unrelated.
 > > It might be better to submit them separately.  Easier to 
 > > review and approve.
 > > 
 > 
 > Here's the first half of the patch again with a small change.
 > 

OK

elena


 > 2003-01-10  Adam Fedor  <fedor@gnu.org>
 > 
 > 	* symtab.c (symbol_init_demangled_name): Check for and demangle
 > 	ObjC symbols.
 > 
 > Index: symtab.c
 > ===================================================================
 > RCS file: /cvs/src/src/gdb/symtab.c,v
 > retrieving revision 1.84
 > diff -u -p -r1.84 symtab.c
 > --- symtab.c	2 Jan 2003 14:27:26 -0000	1.84
 > +++ symtab.c	11 Jan 2003 03:51:34 -0000
 > @@ -40,6 +40,7 @@
 >  #include "linespec.h"
 >  #include "source.h"
 >  #include "filenames.h"		/* for FILENAME_CMP */
 > +#include "objc-lang.h"
 >  
 >  #include "gdb_obstack.h"
 >  
 > @@ -440,15 +441,31 @@ void
 >  symbol_init_demangled_name (struct general_symbol_info *gsymbol,
 >                              struct obstack *obstack)
 >  {
 > -  char *mangled = gsymbol->name;
 > -  char *demangled = NULL;
 > -
 >    if (gsymbol->language == language_unknown)
 >      gsymbol->language = language_auto;
 > +
 > +  if (gsymbol->language == language_objc
 > +      || gsymbol->language == language_auto)
 > +    {
 > +      char *demangled =
 > +	objc_demangle (gsymbol->name);
 > +      if (demangled != NULL)
 > +	{
 > +	  gsymbol->language = language_objc;
 > +	  gsymbol->language_specific.objc_specific.demangled_name =
 > +	    obsavestring (demangled, strlen (demangled), (obstack));
 > +	  xfree (demangled);
 > +	}
 > +      else
 > +	{
 > +	  gsymbol->language_specific.objc_specific.demangled_name = NULL;
 > +	}
 > +    }
 > +  
 >    if (gsymbol->language == language_cplus
 >        || gsymbol->language == language_auto)
 >      {
 > -      demangled =
 > +      char *demangled =
 >          cplus_demangle (gsymbol->name, DMGL_PARAMS | DMGL_ANSI);
 >        if (demangled != NULL)
 >          {
 > @@ -462,9 +479,10 @@ symbol_init_demangled_name (struct gener
 >            gsymbol->language_specific.cplus_specific.demangled_name = NULL;
 >          }
 >      }
 > +
 >    if (gsymbol->language == language_java)
 >      {
 > -      demangled =
 > +      char *demangled =
 >          cplus_demangle (gsymbol->name,
 >                          DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
 >        if (demangled != NULL)
 > @@ -831,7 +849,7 @@ lookup_symbol_aux (const char *name, con
 >      }
 >  #endif /* 0 */
 >  
 > -  /* C++: If requested to do so by the caller, 
 > +  /* C++/Java/Objective-C: If requested to do so by the caller, 
 >       check to see if NAME is a field of `this'. */
 >    if (is_a_field_of_this)
 >      {
 > @@ -1483,9 +1501,9 @@ find_main_psymtab (void)
 >     for now we don't worry about the slight inefficiency of looking for
 >     a match we'll never find, since it will go pretty quick.  Once the
 >     binary search terminates, we drop through and do a straight linear
 > -   search on the symbols.  Each symbol which is marked as being a C++
 > -   symbol (language_cplus set) has both the encoded and non-encoded names
 > -   tested for a match.
 > +   search on the symbols.  Each symbol which is marked as being a ObjC/C++
 > +   symbol (language_cplus or language_objc set) has both the encoded and 
 > +   non-encoded names tested for a match.
 >  
 >     If MANGLED_NAME is non-NULL, verify that any symbol we find has this
 >     particular mangled name.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] Demangle ObjC symbols in symtab.c [4/5]
  2003-02-19 14:59     ` Elena Zannoni
@ 2003-02-19 15:15       ` Elena Zannoni
  2003-02-19 16:48         ` Adam Fedor
  0 siblings, 1 reply; 10+ messages in thread
From: Elena Zannoni @ 2003-02-19 15:15 UTC (permalink / raw)
  To: fedor; +Cc: GDB Patches

Elena Zannoni writes:
 > Adam Fedor writes:
 >  > 
 >  > Michael Snyder wrote:
 >  > > Adam Fedor wrote:
 >  > > 
 >  > >>2003-01-03  Adam Fedor  <fedor@gnu.org>
 >  > >>
 >  > >>        * symtab.c (symbol_init_demangled_name): Check for and demangle
 >  > >>        ObjC symbols.
 >  > >>        (make_symbol_completion_list): Look for ObjC symbols
 >  > > 
 >  > > 
 >  > > Not to be too fussy, but these two changes seem unrelated.
 >  > > It might be better to submit them separately.  Easier to 
 >  > > review and approve.
 >  > > 
 >  > 
 >  > Here's the first half of the patch again with a small change.
 >  > 
 > 
 > OK
 > 

Adam, on second thought, you also need the Makefile dependency change.
(no need to resubmit)

 > elena
 > 
 > 
 >  > 2003-01-10  Adam Fedor  <fedor@gnu.org>
 >  > 
 >  > 	* symtab.c (symbol_init_demangled_name): Check for and demangle
 >  > 	ObjC symbols.
 >  > 
 >  > Index: symtab.c
 >  > ===================================================================
 >  > RCS file: /cvs/src/src/gdb/symtab.c,v
 >  > retrieving revision 1.84
 >  > diff -u -p -r1.84 symtab.c
 >  > --- symtab.c	2 Jan 2003 14:27:26 -0000	1.84
 >  > +++ symtab.c	11 Jan 2003 03:51:34 -0000
 >  > @@ -40,6 +40,7 @@
 >  >  #include "linespec.h"
 >  >  #include "source.h"
 >  >  #include "filenames.h"		/* for FILENAME_CMP */
 >  > +#include "objc-lang.h"
 >  >  
 >  >  #include "gdb_obstack.h"
 >  >  
 >  > @@ -440,15 +441,31 @@ void
 >  >  symbol_init_demangled_name (struct general_symbol_info *gsymbol,
 >  >                              struct obstack *obstack)
 >  >  {
 >  > -  char *mangled = gsymbol->name;
 >  > -  char *demangled = NULL;
 >  > -
 >  >    if (gsymbol->language == language_unknown)
 >  >      gsymbol->language = language_auto;
 >  > +
 >  > +  if (gsymbol->language == language_objc
 >  > +      || gsymbol->language == language_auto)
 >  > +    {
 >  > +      char *demangled =
 >  > +	objc_demangle (gsymbol->name);
 >  > +      if (demangled != NULL)
 >  > +	{
 >  > +	  gsymbol->language = language_objc;
 >  > +	  gsymbol->language_specific.objc_specific.demangled_name =
 >  > +	    obsavestring (demangled, strlen (demangled), (obstack));
 >  > +	  xfree (demangled);
 >  > +	}
 >  > +      else
 >  > +	{
 >  > +	  gsymbol->language_specific.objc_specific.demangled_name = NULL;
 >  > +	}
 >  > +    }
 >  > +  
 >  >    if (gsymbol->language == language_cplus
 >  >        || gsymbol->language == language_auto)
 >  >      {
 >  > -      demangled =
 >  > +      char *demangled =
 >  >          cplus_demangle (gsymbol->name, DMGL_PARAMS | DMGL_ANSI);
 >  >        if (demangled != NULL)
 >  >          {
 >  > @@ -462,9 +479,10 @@ symbol_init_demangled_name (struct gener
 >  >            gsymbol->language_specific.cplus_specific.demangled_name = NULL;
 >  >          }
 >  >      }
 >  > +
 >  >    if (gsymbol->language == language_java)
 >  >      {
 >  > -      demangled =
 >  > +      char *demangled =
 >  >          cplus_demangle (gsymbol->name,
 >  >                          DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA);
 >  >        if (demangled != NULL)
 >  > @@ -831,7 +849,7 @@ lookup_symbol_aux (const char *name, con
 >  >      }
 >  >  #endif /* 0 */
 >  >  
 >  > -  /* C++: If requested to do so by the caller, 
 >  > +  /* C++/Java/Objective-C: If requested to do so by the caller, 
 >  >       check to see if NAME is a field of `this'. */
 >  >    if (is_a_field_of_this)
 >  >      {
 >  > @@ -1483,9 +1501,9 @@ find_main_psymtab (void)
 >  >     for now we don't worry about the slight inefficiency of looking for
 >  >     a match we'll never find, since it will go pretty quick.  Once the
 >  >     binary search terminates, we drop through and do a straight linear
 >  > -   search on the symbols.  Each symbol which is marked as being a C++
 >  > -   symbol (language_cplus set) has both the encoded and non-encoded names
 >  > -   tested for a match.
 >  > +   search on the symbols.  Each symbol which is marked as being a ObjC/C++
 >  > +   symbol (language_cplus or language_objc set) has both the encoded and 
 >  > +   non-encoded names tested for a match.
 >  >  
 >  >     If MANGLED_NAME is non-NULL, verify that any symbol we find has this
 >  >     particular mangled name.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [RFA] Demangle ObjC symbols in symtab.c [4/5]
  2003-02-19 15:15       ` Elena Zannoni
@ 2003-02-19 16:48         ` Adam Fedor
  0 siblings, 0 replies; 10+ messages in thread
From: Adam Fedor @ 2003-02-19 16:48 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: GDB Patches



Elena Zannoni wrote:
> Elena Zannoni writes:
>  > Adam Fedor writes:
>  >  > 
>  >  > Michael Snyder wrote:
>  >  > > Adam Fedor wrote:
>  >  > > 
>  >  > >>2003-01-03  Adam Fedor  <fedor@gnu.org>
>  >  > >>
>  >  > >>        * symtab.c (symbol_init_demangled_name): Check for and demangle
>  >  > >>        ObjC symbols.
>  >  > >>        (make_symbol_completion_list): Look for ObjC symbols
>  >  > > 
>  >  > > 
>  >  > > Not to be too fussy, but these two changes seem unrelated.
>  >  > > It might be better to submit them separately.  Easier to 
>  >  > > review and approve.
>  >  > > 
>  >  > 
>  >  > Here's the first half of the patch again with a small change.
>  >  > 
>  > 
>  > OK
>  > 
> 
> Adam, on second thought, you also need the Makefile dependency change.
> (no need to resubmit)
> 

OK Thanks. Just FYI though: I need PR 997 and 1003 (they're the same 
thing) approval before I can put any of the other patches in.


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2003-02-19 16:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-03 23:03 [RFA] Demangle ObjC symbols in symtab.c [4/5] Adam Fedor
2003-01-04  1:25 ` Michael Snyder
2003-01-11  4:01   ` Adam Fedor
2003-02-19 14:59     ` Elena Zannoni
2003-02-19 15:15       ` Elena Zannoni
2003-02-19 16:48         ` Adam Fedor
2003-01-06 21:42 ` Elena Zannoni
2003-01-07 23:14   ` Daniel Jacobowitz
2003-01-11  3:59   ` Adam Fedor
2003-01-11  5:24     ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox