From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28658 invoked by alias); 4 Jan 2003 01:25:02 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 28649 invoked from network); 4 Jan 2003 01:25:01 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by 209.249.29.67 with SMTP; 4 Jan 2003 01:25:01 -0000 Received: from int-mx2.corp.redhat.com (nat-pool-rdu-dmz.redhat.com [172.16.52.200]) by mx1.redhat.com (8.11.6/8.11.6) with ESMTP id h040vRB20037 for ; Fri, 3 Jan 2003 19:57:27 -0500 Received: from potter.sfbay.redhat.com (potter.sfbay.redhat.com [172.16.27.15]) by int-mx2.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h041Oln30275; Fri, 3 Jan 2003 20:24:47 -0500 Received: from redhat.com (reddwarf.sfbay.redhat.com [172.16.24.50]) by potter.sfbay.redhat.com (8.11.6/8.11.6) with ESMTP id h041Ogn07860; Fri, 3 Jan 2003 17:24:42 -0800 Message-ID: <3E1637DA.BFD960F9@redhat.com> Date: Sat, 04 Jan 2003 01:25:00 -0000 From: Michael Snyder Organization: Red Hat, Inc. X-Accept-Language: en MIME-Version: 1.0 To: Adam Fedor CC: GDB Patches Subject: Re: [RFA] Demangle ObjC symbols in symtab.c [4/5] References: <3E1616B7.1010001@doc.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-SW-Source: 2003-01/txt/msg00135.txt.bz2 Adam Fedor wrote: > > 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 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). */