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 --- 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; - 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; + } + } + 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; } /* 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. 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); + ALL_PSYMTABS (objfile, ps) { /* If the psymtab's been read in we'll get it when we search @@ -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); + } + } + } + /* 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; 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; - } + /* 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; } } - 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); /* Find the symtab for SRCFILE (this loads it if it was not yet read in). */