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

Matt Rice
2009-09-24T22:29:03Z

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

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.

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.

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

diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 0e4fb71..b94c0af 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -244,22 +244,20 @@ objc_demangle (const char *mangled, int options)
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 */
@@ -1702,11 +1700,9 @@ find_implementation_from_class (struct gdbarch *gdbarch,
struct objc_method meth_str;
read_objc_methlist_method (gdbarch, mlist, i, &meth_str);

-#if 0
fprintf (stderr,
"checking method 0x%lx against selector 0x%lx\n",
meth_str.name, sel);
-#endif

if (meth_str.name == sel)
/* FIXME: hppa arch was doing a pointer dereference
@@ -1841,3 +1837,50 @@ _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);
+
+// objf = gsymbol->obj_section->objfile;
+// *resultp = obsavestring (*resultp, newlen, &objf->objfile_obstack);
+ return *resultp;
+ }
+#if 0
+ if (*resultp == NULL)
+ {
+ char **slot = (char **) htab_find_slot (decoded_names_store,
+ decoded, INSERT);
+ if (*slot == NULL)
+ *slot = xstrdup (decoded);
+
+ *resultp = *slot;
+ }
+#endif
+ }
+ return gsymbol->name;
+}
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)