Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Matt Rice <ratmice@gmail.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: gdb.objc/objcdecode.exp test error..
Date: Thu, 24 Sep 2009 22:51:00 -0000	[thread overview]
Message-ID: <8ba6bed40909241551u4e239309u8551898132369173@mail.gmail.com> (raw)
In-Reply-To: <8ba6bed40909241528m1e98f425k8792016b29179239@mail.gmail.com>

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

On Thu, Sep 24, 2009 at 3:28 PM, Matt Rice <ratmice@gmail.com> wrote:
> On Thu, Sep 24, 2009 at 1:24 AM, Matt Rice <ratmice@gmail.com> wrote:
>> On Wed, Sep 23, 2009 at 5:53 PM, Joel Brobecker <brobecker@adacore.com> wrote:
>
>>> This would not help handling the case of breakpoint expressions
>>> leading to more than one location.  For this, once we have determined
>>> all possible matches, we need to be able to store their location in
>>> a way that uniquely identifies them.  Otherwise, we wouldn't be
>>> able to "re_set" each one of them when running the program, or when
>>> a new shared-library is loaded.
>>
>> It just occured to me that we could canonicalize these homonyms
>> using '-[Foo() bar]' to mean method not in a category, and
>> '-[Foo(categoryName) bar]', that also means extending decode_objc to
>> accept -[Foo() bar] syntax I'm not sure if it will currently accept
>> it.
>
>
> ok, so this patch disambiguates the homonyms,
>
> given a method with 2 implementations:
> -[Foo bar] and -[Foo(aCategoryName) bar]
>
> going 'break -[Foo bar]' will possibly create up to 2 breakpoints
> -[Foo() bar], and -[Foo(aCategoryname) bar]
>
> if we get better homonym support we can still refer to them both as a
> single deal, using [Foo bar] syntax, but we can also refer to each
> method individually.
>
> I'll get working on the other part now, I see that the ada code uses
> obsavestring in this, but i'm really not quite sure what its doing and
> if it is possible to do this that in this fashion yet.
>

Doh, missing headers, lots of cruft, and missing changelog entries...
itchy trigger finger, sorry.


2009-09-24  Matt Rice  <ratmice@gmail.com>

        * symtab.c (symbol_natural_name): Call objc_decode_symbol.
        * objc-lang.c (objc_decode_symbol): New function.
        (demangle_obj): Leave category parentheses even if there is no
        category name.  Fix for gnu coding standards.
        * objc-lang.h: (objc_decode_symbol): Declare.

[-- Attachment #2: category.diff --]
[-- Type: application/octet-stream, Size: 4284 bytes --]

diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 0e4fb71..fdd0a8c 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -225,7 +225,7 @@ objc_demangle (const char *mangled, int options)
      (mangled[1] == 'i' || mangled[1] == 'c') &&
       mangled[2] == '_')
     {
-      cp = demangled = xmalloc(strlen(mangled) + 2);
+      cp = demangled = xmalloc (strlen (mangled) + 2);
 
       if (mangled[1] == 'i')
 	*cp++ = '-';		/* for instance method */
@@ -233,33 +233,31 @@ objc_demangle (const char *mangled, int options)
 	*cp++ = '+';		/* for class    method */
 
       *cp++ = '[';		/* opening left brace  */
-      strcpy(cp, mangled+3);	/* tack on the rest of the mangled name */
+      strcpy (cp, mangled+3);	/* tack on the rest of the mangled name */
 
       while (*cp && *cp == '_')
 	cp++;			/* skip any initial underbars in class name */
 
-      cp = strchr(cp, '_');
+      cp = strchr (cp, '_');
       if (!cp)	                /* find first non-initial underbar */
 	{
-	  xfree(demangled);	/* not mangled name */
+	  xfree (demangled);	/* not mangled name */
 	  return NULL;
 	}
-      if (cp[1] == '_') {	/* easy case: no category name     */
-	*cp++ = ' ';		/* replace two '_' with one ' '    */
-	strcpy(cp, mangled + (cp - demangled) + 2);
-      }
-      else {
-	*cp++ = '(';		/* less easy case: category name */
-	cp = strchr(cp, '_');
-	if (!cp)
-	  {
-	    xfree(demangled);	/* not mangled name */
-	    return NULL;
-	  }
-	*cp++ = ')';
-	*cp++ = ' ';		/* overwriting 1st char of method name...  */
-	strcpy(cp, mangled + (cp - demangled));	/* get it back */
-      }
+
+      /* We leave the parentheses when lacking a category name to
+         disambiguate when there is multiple versions of a method.
+         So that break [Foo bar] can return canonical results.  */ 
+      *cp++ = '(';		/* less easy case: category name */
+      cp = strchr (cp, '_');
+      if (!cp)
+	{
+	  xfree (demangled);	/* not mangled name */
+	  return NULL;
+	}
+      *cp++ = ')';
+      *cp++ = ' ';		/* overwriting 1st char of method name...  */
+      strcpy (cp, mangled + (cp - demangled));	/* get it back */
 
       while (*cp && *cp == '_')
 	cp++;			/* skip any initial underbars in method name */
@@ -1841,3 +1839,40 @@ _initialize_objc_lang (void)
 {
   objc_objfile_data = register_objfile_data ();
 }
+
+char *
+objc_decode_symbol (const struct general_symbol_info *gsymbol)
+{
+  char ntype = '\0';
+  char *nclass = NULL;
+  char *ncategory = NULL;
+  char *nselector = NULL;
+
+  char **resultp =
+    (char **) &gsymbol->language_specific.cplus_specific.demangled_name;
+
+  if (*resultp == NULL)
+    {
+ 
+      parse_method (gsymbol->name, &ntype, &nclass, &ncategory, &nselector);
+
+      if (ncategory == NULL)
+	ncategory = "\0";
+      if (ntype && nclass && ncategory && nselector)
+	{ 
+	  size_t newlen;
+	  struct objfile *objf;
+
+	  newlen = sizeof (ntype) + strlen (nclass) + strlen (ncategory)
+			  + strlen (nselector) + sizeof ("[]()");
+
+	  *resultp = xmalloc(newlen);
+	  sprintf(*resultp, "%c[%s(%s) %s]", ntype, nclass, ncategory,
+					     nselector);
+
+	  return *resultp;
+        }
+    }
+
+  return gsymbol->name;
+}
diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h
index 0d23467..e5ae036 100644
--- a/gdb/objc-lang.h
+++ b/gdb/objc-lang.h
@@ -58,5 +58,7 @@ extern int end_msglist (void);
 
 struct symbol *lookup_struct_typedef (char *name, struct block *block,
 				      int noerr);
+char *
+objc_decode_symbol (const struct general_symbol_info *gsymbol);
 
 #endif
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 8d9d72c..f893155 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -632,9 +632,14 @@ symbol_natural_name (const struct general_symbol_info *gsymbol)
     {
     case language_cplus:
     case language_java:
+      if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
+	return gsymbol->language_specific.cplus_specific.demangled_name;
+      break;
     case language_objc:
       if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)
 	return gsymbol->language_specific.cplus_specific.demangled_name;
+      else
+	return objc_decode_symbol (gsymbol);
       break;
     case language_ada:
       if (gsymbol->language_specific.cplus_specific.demangled_name != NULL)

  reply	other threads:[~2009-09-24 22:51 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-06  1:31 Matt Rice
2009-03-06 17:33 ` Joel Brobecker
2009-03-06 19:13   ` Pedro Alves
2009-03-07 12:07     ` Matt Rice
2009-03-08 14:16       ` Matt Rice
2009-03-09  2:10         ` Matt Rice
2009-09-11 11:43           ` Matt Rice
2009-09-24  0:53             ` Joel Brobecker
2009-09-24  8:24               ` Matt Rice
2009-09-24 18:28                 ` Tom Tromey
2009-09-24 22:07                   ` Matt Rice
2009-09-24 22:29                 ` Matt Rice
2009-09-24 22:51                   ` Matt Rice [this message]
2009-09-25  4:03               ` Matt Rice
2009-10-13  0:44               ` Tom Tromey
2009-10-14  1:59                 ` Joel Brobecker
2009-09-23 23:13         ` Joel Brobecker
2009-09-24  6:48           ` Matt Rice
2009-09-24 16:41             ` Joel Brobecker
2009-09-24 17:31               ` Joel Brobecker
2009-09-24 17:41               ` Joel Brobecker
2009-09-24 16:52             ` Joel Brobecker

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=8ba6bed40909241551u4e239309u8551898132369173@mail.gmail.com \
    --to=ratmice@gmail.com \
    --cc=brobecker@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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