From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Received: (qmail 29587 invoked from network); 11 Jan 2003 03:59:13 -0000 Received: from unknown (63.119.183.65) by 209.249.29.67 with QMTP; 11 Jan 2003 03:59:13 -0000 Received: (qmail 23740 invoked from network); 11 Jan 2003 03:57:36 -0000 Received: from cpe-24-221-209-215.co.sprintbbd.net (HELO doc.com) (24.221.209.215) by external1 with SMTP; 11 Jan 2003 03:57:36 -0000 Message-ID: <3E1F9682.7050901@doc.com> Date: Sat, 11 Jan 2003 03:59:00 -0000 From: Adam Fedor User-Agent: Mozilla/5.0 (X11; U; Linux ppc; en-US; rv:1.1) Gecko/20020905 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Elena Zannoni CC: GDB Patches Subject: Re: [RFA] Demangle ObjC symbols in symtab.c [4/5] References: <3E1616B7.1010001@doc.com> <15897.63800.544503.672211@localhost.redhat.com> Content-Type: multipart/mixed; boundary="------------000902000909090906000301" X-SW-Source: 2003-01/txt/msg00441.txt.bz2 This is a multi-part message in MIME format. --------------000902000909090906000301 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 3222 Elena Zannoni wrote: > Adam Fedor writes: > > 2003-01-03 Adam Fedor > > > > * 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). --------------000902000909090906000301 Content-Type: text/plain; name="objc22b.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="objc22b.patch" Content-length: 4855 2003-01-10 Adam Fedor * 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; } } --------------000902000909090906000301--