From 53c5240fe15861d08db96684b1a06c4b4ecb1958 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Wed, 28 Mar 2007 00:12:15 +0000 Subject: [PATCH 1/1] * linespec.c: Include language.h. (find_methods): Add language parameter. Call lookup_symbol_in_language. Pass language down. (add_matching_methods): Likewise. Call lookup_symbol_in_language. (add_constructors): Likewise. (find_method): Pass sym_class to collect_methods. (collect_methods): Add sym_class parameter. Pass language down. * symtab.c (lookup_symbol): Rename to ... (lookup_symbol_in_language): ... this. Add language parameter. Use passed language instead of current_language. (lookup_symbol): New as wrapper around lookup_symbol_in_language. (lookup_symbol_aux): Add language parameter. Use passed language instead of current_language. (search_symbols): Indent. * symtab.h (enum language): Forward declare. (lookup_symbol_in_language): Declare. (lookup_symbol): Update description. * ada-lang.h (lookup_symbol_in_language): Remove declaration. * ada-lang.c (restore_language): Remove. (lookup_symbol_in_language): Remove. --- gdb/ChangeLog | 26 +++++++++++++++++++++++++ gdb/ada-lang.c | 25 ------------------------ gdb/ada-lang.h | 11 ----------- gdb/linespec.c | 41 +++++++++++++++++++++++---------------- gdb/symtab.c | 52 ++++++++++++++++++++++++++++++++++---------------- gdb/symtab.h | 13 ++++++++++++- 6 files changed, 99 insertions(+), 69 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 503e6815ae..e8768abb5c 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,29 @@ +2007-03-28 Pedro Alves + + * linespec.c: Include language.h. + (find_methods): Add language parameter. Call + lookup_symbol_in_language. Pass language down. + (add_matching_methods): Likewise. Call + lookup_symbol_in_language. + (add_constructors): Likewise. + (find_method): Pass sym_class to collect_methods. + (collect_methods): Add sym_class parameter. Pass language + down. + * symtab.c (lookup_symbol): Rename to ... + (lookup_symbol_in_language): ... this. Add language + parameter. Use passed language instead of current_language. + (lookup_symbol): New as wrapper around + lookup_symbol_in_language. + (lookup_symbol_aux): Add language parameter. Use passed + language instead of current_language. + (search_symbols): Indent. + * symtab.h (enum language): Forward declare. + (lookup_symbol_in_language): Declare. + (lookup_symbol): Update description. + * ada-lang.h (lookup_symbol_in_language): Remove declaration. + * ada-lang.c (restore_language): Remove. + (lookup_symbol_in_language): Remove. + 2007-03-27 Pedro Alves * breakpoint.c (bpstat_num): Add int *num parameter. diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index afee231811..5447e43e57 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -4213,31 +4213,6 @@ add_symbols_from_enclosing_procs (struct obstack *obstackp, { } -/* FIXME: The next two routines belong in symtab.c */ - -static void -restore_language (void *lang) -{ - set_language ((enum language) lang); -} - -/* As for lookup_symbol, but performed as if the current language - were LANG. */ - -struct symbol * -lookup_symbol_in_language (const char *name, const struct block *block, - domain_enum domain, enum language lang, - int *is_a_field_of_this, struct symtab **symtab) -{ - struct cleanup *old_chain - = make_cleanup (restore_language, (void *) current_language->la_language); - struct symbol *result; - set_language (lang); - result = lookup_symbol (name, block, domain, is_a_field_of_this, symtab); - do_cleanups (old_chain); - return result; -} - /* True if TYPE is definitely an artificial type supplied to a symbol for which no debugging information was given in the symbol file. */ diff --git a/gdb/ada-lang.h b/gdb/ada-lang.h index ac6f5a4511..c3873ebc58 100644 --- a/gdb/ada-lang.h +++ b/gdb/ada-lang.h @@ -474,17 +474,6 @@ extern void ada_reset_thread_registers (void); extern int ada_build_task_list (void); -/* Look up a symbol by name using the search conventions of - a specific language (optional block, optional symtab). - FIXME: Should be symtab.h. */ - -extern struct symbol *lookup_symbol_in_language (const char *, - const struct block *, - domain_enum, - enum language, - int *, - struct symtab **); - extern int ada_exception_catchpoint_p (struct breakpoint *b); extern struct symtab_and_line diff --git a/gdb/linespec.c b/gdb/linespec.c index 7fc169175f..4950d373cb 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -37,6 +37,7 @@ #include "objc-lang.h" #include "linespec.h" #include "exceptions.h" +#include "language.h" /* We share this one with symtab.c, but it is not exported widely. */ @@ -75,6 +76,7 @@ static struct symtabs_and_lines find_method (int funfirstline, struct symbol *sym_class); static int collect_methods (char *copy, struct type *t, + struct symbol *sym_class, struct symbol **sym_arr); static NORETURN void cplusplus_error (const char *name, @@ -83,12 +85,15 @@ static NORETURN void cplusplus_error (const char *name, static int total_number_of_methods (struct type *type); -static int find_methods (struct type *, char *, struct symbol **); +static int find_methods (struct type *, char *, + enum language, struct symbol **); static int add_matching_methods (int method_counter, struct type *t, + enum language language, struct symbol **sym_arr); static int add_constructors (int method_counter, struct type *t, + enum language language, struct symbol **sym_arr); static void build_canonical_line_spec (struct symtab_and_line *, @@ -196,7 +201,8 @@ total_number_of_methods (struct type *type) Note that this function is g++ specific. */ static int -find_methods (struct type *t, char *name, struct symbol **sym_arr) +find_methods (struct type *t, char *name, enum language language, + struct symbol **sym_arr) { int i1 = 0; int ibase; @@ -206,8 +212,8 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr) unless we figure out how to get the physname without the name of the class, then the loop can't do any good. */ if (class_name - && (lookup_symbol (class_name, (struct block *) NULL, - STRUCT_DOMAIN, (int *) NULL, + && (lookup_symbol_in_language (class_name, (struct block *) NULL, + STRUCT_DOMAIN, language, (int *) NULL, (struct symtab **) NULL))) { int method_counter; @@ -238,12 +244,12 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr) if (strcmp_iw (name, method_name) == 0) /* Find all the overloaded methods with that name. */ - i1 += add_matching_methods (method_counter, t, + i1 += add_matching_methods (method_counter, t, language, sym_arr + i1); else if (strncmp (class_name, name, name_len) == 0 && (class_name[name_len] == '\0' || class_name[name_len] == '<')) - i1 += add_constructors (method_counter, t, + i1 += add_constructors (method_counter, t, language, sym_arr + i1); } } @@ -261,7 +267,8 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr) if (i1 == 0) for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++) - i1 += find_methods (TYPE_BASECLASS (t, ibase), name, sym_arr + i1); + i1 += find_methods (TYPE_BASECLASS (t, ibase), name, + language, sym_arr + i1); return i1; } @@ -272,7 +279,7 @@ find_methods (struct type *t, char *name, struct symbol **sym_arr) static int add_matching_methods (int method_counter, struct type *t, - struct symbol **sym_arr) + enum language language, struct symbol **sym_arr) { int field_counter; int i1 = 0; @@ -299,14 +306,15 @@ add_matching_methods (int method_counter, struct type *t, } else phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); - + /* Destructor is handled by caller, don't add it to the list. */ if (is_destructor_name (phys_name) != 0) continue; - sym_arr[i1] = lookup_symbol (phys_name, + sym_arr[i1] = lookup_symbol_in_language (phys_name, NULL, VAR_DOMAIN, + language, (int *) NULL, (struct symtab **) NULL); if (sym_arr[i1]) @@ -333,7 +341,7 @@ add_matching_methods (int method_counter, struct type *t, static int add_constructors (int method_counter, struct type *t, - struct symbol **sym_arr) + enum language language, struct symbol **sym_arr) { int field_counter; int i1 = 0; @@ -349,7 +357,7 @@ add_constructors (int method_counter, struct type *t, { struct fn_field *f; char *phys_name; - + f = TYPE_FN_FIELDLIST1 (t, method_counter); /* GCC 3.x will never produce stabs stub methods, so @@ -362,8 +370,9 @@ add_constructors (int method_counter, struct type *t, /* If this method is actually defined, include it in the list. */ - sym_arr[i1] = lookup_symbol (phys_name, + sym_arr[i1] = lookup_symbol_in_language (phys_name, NULL, VAR_DOMAIN, + language, (int *) NULL, (struct symtab **) NULL); if (sym_arr[i1]) @@ -1410,7 +1419,7 @@ find_method (int funfirstline, char ***canonical, char *saved_arg, /* Find all methods with a matching name, and put them in sym_arr. */ - i1 = collect_methods (copy, t, sym_arr); + i1 = collect_methods (copy, t, sym_class, sym_arr); if (i1 == 1) { @@ -1466,7 +1475,7 @@ find_method (int funfirstline, char ***canonical, char *saved_arg, static int collect_methods (char *copy, struct type *t, - struct symbol **sym_arr) + struct symbol *sym_class, struct symbol **sym_arr) { int i1 = 0; /* Counter for the symbol array. */ @@ -1488,7 +1497,7 @@ collect_methods (char *copy, struct type *t, } } else - i1 = find_methods (t, copy, sym_arr); + i1 = find_methods (t, copy, SYMBOL_LANGUAGE (sym_class), sym_arr); return i1; } diff --git a/gdb/symtab.c b/gdb/symtab.c index c427c98637..7e6d03164a 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -84,6 +84,7 @@ static struct symbol *lookup_symbol_aux (const char *name, const char *linkage_name, const struct block *block, const domain_enum domain, + enum language language, int *is_a_field_of_this, struct symtab **symtab); @@ -1079,9 +1080,10 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile) code). */ struct symbol * -lookup_symbol (const char *name, const struct block *block, - const domain_enum domain, int *is_a_field_of_this, - struct symtab **symtab) +lookup_symbol_in_language (const char *name, const struct block *block, + const domain_enum domain, enum language lang, + int *is_a_field_of_this, + struct symtab **symtab) { char *demangled_name = NULL; const char *modified_name = NULL; @@ -1093,7 +1095,7 @@ lookup_symbol (const char *name, const struct block *block, /* If we are using C++ or Java, demangle the name before doing a lookup, so we can always binary search. */ - if (current_language->la_language == language_cplus) + if (lang == language_cplus) { demangled_name = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS); if (demangled_name) @@ -1103,7 +1105,7 @@ lookup_symbol (const char *name, const struct block *block, needtofreename = 1; } } - else if (current_language->la_language == language_java) + else if (lang == language_java) { demangled_name = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA); @@ -1129,7 +1131,8 @@ lookup_symbol (const char *name, const struct block *block, } returnval = lookup_symbol_aux (modified_name, mangled_name, block, - domain, is_a_field_of_this, symtab); + domain, lang, + is_a_field_of_this, symtab); if (needtofreename) xfree (demangled_name); @@ -1140,7 +1143,20 @@ lookup_symbol (const char *name, const struct block *block, return returnval; } -/* Behave like lookup_symbol_aux except that NAME is the natural name +/* Behave like lookup_symbol_in_language, but performed with the + current language. */ + +struct symbol * +lookup_symbol (const char *name, const struct block *block, + domain_enum domain, int *is_a_field_of_this, + struct symtab **symtab) +{ + return lookup_symbol_in_language (name, block, domain, + current_language->la_language, + is_a_field_of_this, symtab); +} + +/* Behave like lookup_symbol except that NAME is the natural name of the symbol that we're looking for and, if LINKAGE_NAME is non-NULL, ensure that the symbol's linkage name matches as well. */ @@ -1148,9 +1164,11 @@ lookup_symbol (const char *name, const struct block *block, static struct symbol * lookup_symbol_aux (const char *name, const char *linkage_name, const struct block *block, const domain_enum domain, + enum language language, int *is_a_field_of_this, struct symtab **symtab) { struct symbol *sym; + const struct language_defn *langdef; /* Make sure we do something sensible with is_a_field_of_this, since the callers that set this parameter to some non-null value will @@ -1168,13 +1186,15 @@ lookup_symbol_aux (const char *name, const char *linkage_name, if (sym != NULL) return sym; - /* If requested to do so by the caller and if appropriate for the - current language, check to see if NAME is a field of `this'. */ + /* If requested to do so by the caller and if appropriate for LANGUAGE, + check to see if NAME is a field of `this'. */ + + langdef = language_def (language); - if (current_language->la_value_of_this != NULL + if (langdef->la_value_of_this != NULL && is_a_field_of_this != NULL) { - struct value *v = current_language->la_value_of_this (0); + struct value *v = langdef->la_value_of_this (0); if (v && check_field (v, name)) { @@ -1185,12 +1205,11 @@ lookup_symbol_aux (const char *name, const char *linkage_name, } } - /* Now do whatever is appropriate for the current language to look + /* Now do whatever is appropriate for LANGUAGE to look up static and global variables. */ - sym = current_language->la_lookup_symbol_nonlocal (name, linkage_name, - block, domain, - symtab); + sym = langdef->la_lookup_symbol_nonlocal (name, linkage_name, + block, domain, symtab); if (sym != NULL) return sym; @@ -3070,7 +3089,8 @@ search_symbols (char *regexp, domain_enum kind, int nfiles, char *files[], || lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), (struct block *) NULL, VAR_DOMAIN, - 0, (struct symtab **) NULL) == NULL) + 0, (struct symtab **) NULL) + == NULL) found_misc = 1; } } diff --git a/gdb/symtab.h b/gdb/symtab.h index da637cb0cf..cefb0ad0ad 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -34,6 +34,7 @@ struct block; struct blockvector; struct axs_value; struct agent_expr; +enum language; /* Some of the structures in this file are space critical. The space-critical structures are: @@ -1007,7 +1008,17 @@ extern int asm_demangle; extern struct symtab *lookup_symtab (const char *); -/* lookup a symbol by name (optional block, optional symtab) */ +/* lookup a symbol by name (optional block, optional symtab) in language */ + +extern struct symbol *lookup_symbol_in_language (const char *, + const struct block *, + const domain_enum, + enum language, + int *, + struct symtab **); + +/* lookup a symbol by name (optional block, optional symtab) + in the current language */ extern struct symbol *lookup_symbol (const char *, const struct block *, const domain_enum, int *, -- 2.34.1