Re: gdb.objc/objcdecode.exp test error..

Matt Rice
2009-09-24T22:51:22Z

[-- 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)