X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fsymtab.c;h=cf03b43c7c488db7f073005f5f36cfd54090a718;hb=6b9780fbbd65d5a1cf56a15552c50bd6bfa10a10;hp=a46cdb81f1e9eae2b91dbc5b36c3d3e633e8f3a0;hpb=f1e6e0721c5115e2e6c60359c9afbdfe927f0431;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/symtab.c b/gdb/symtab.c index a46cdb81f1..cf03b43c7c 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -101,8 +101,6 @@ struct symbol *lookup_symbol_aux_quick (struct objfile *objfile, const char *name, const domain_enum domain); -static void print_msymbol_info (struct minimal_symbol *); - void _initialize_symtab (void); /* */ @@ -145,6 +143,37 @@ multiple_symbols_select_mode (void) const struct block *block_found; +/* Return the name of a domain_enum. */ + +const char * +domain_name (domain_enum e) +{ + switch (e) + { + case UNDEF_DOMAIN: return "UNDEF_DOMAIN"; + case VAR_DOMAIN: return "VAR_DOMAIN"; + case STRUCT_DOMAIN: return "STRUCT_DOMAIN"; + case LABEL_DOMAIN: return "LABEL_DOMAIN"; + case COMMON_BLOCK_DOMAIN: return "COMMON_BLOCK_DOMAIN"; + default: gdb_assert_not_reached ("bad domain_enum"); + } +} + +/* Return the name of a search_domain . */ + +const char * +search_domain_name (enum search_domain e) +{ + switch (e) + { + case VARIABLES_DOMAIN: return "VARIABLES_DOMAIN"; + case FUNCTIONS_DOMAIN: return "FUNCTIONS_DOMAIN"; + case TYPES_DOMAIN: return "TYPES_DOMAIN"; + case ALL_DOMAIN: return "ALL_DOMAIN"; + default: gdb_assert_not_reached ("bad search_domain"); + } +} + /* See whether FILENAME matches SEARCH_NAME using the rule that we advertise to the user. (The manual's description of linespecs describes what we advertise). Returns true if they match, false @@ -186,6 +215,9 @@ compare_filenames_for_search (const char *filename, const char *search_name) /* Check for a symtab of a specific name by searching some symtabs. This is a helper function for callbacks of iterate_over_symtabs. + If NAME is not absolute, then REAL_PATH is NULL + If NAME is absolute, then REAL_PATH is the gdb_realpath form of NAME. + The return value, NAME, REAL_PATH, CALLBACK, and DATA are identical to the `map_symtabs_matching_filename' method of quick_symbol_functions. @@ -215,35 +247,34 @@ iterate_over_some_symtabs (const char *name, continue; } - /* Before we invoke realpath, which can get expensive when many - files are involved, do a quick comparison of the basenames. */ - if (! basenames_may_differ - && FILENAME_CMP (base_name, lbasename (s->filename)) != 0) - continue; - - if (compare_filenames_for_search (symtab_to_fullname (s), name)) - { - if (callback (s, data)) - return 1; + /* Before we invoke realpath, which can get expensive when many + files are involved, do a quick comparison of the basenames. */ + if (! basenames_may_differ + && FILENAME_CMP (base_name, lbasename (s->filename)) != 0) continue; - } - /* If the user gave us an absolute path, try to find the file in - this symtab and use its absolute path. */ + if (compare_filenames_for_search (symtab_to_fullname (s), name)) + { + if (callback (s, data)) + return 1; + continue; + } - if (real_path != NULL) - { - const char *fullname = symtab_to_fullname (s); + /* If the user gave us an absolute path, try to find the file in + this symtab and use its absolute path. */ + if (real_path != NULL) + { + const char *fullname = symtab_to_fullname (s); - gdb_assert (IS_ABSOLUTE_PATH (real_path)); - gdb_assert (IS_ABSOLUTE_PATH (name)); - if (FILENAME_CMP (real_path, fullname) == 0) - { - if (callback (s, data)) - return 1; - continue; - } - } + gdb_assert (IS_ABSOLUTE_PATH (real_path)); + gdb_assert (IS_ABSOLUTE_PATH (name)); + if (FILENAME_CMP (real_path, fullname) == 0) + { + if (callback (s, data)) + return 1; + continue; + } + } } return 0; @@ -420,15 +451,15 @@ gdb_mangle_name (struct type *type, int method_id, int signature_id) static void symbol_init_cplus_specific (struct general_symbol_info *gsymbol, - struct objfile *objfile) + struct obstack *obstack) { /* A language_specific structure should not have been previously initialized. */ gdb_assert (gsymbol->language_specific.cplus_specific == NULL); - gdb_assert (objfile != NULL); + gdb_assert (obstack != NULL); gsymbol->language_specific.cplus_specific = - OBSTACK_ZALLOC (&objfile->objfile_obstack, struct cplus_specific); + OBSTACK_ZALLOC (obstack, struct cplus_specific); } /* Set the demangled name of GSYMBOL to NAME. NAME must be already @@ -439,15 +470,28 @@ symbol_init_cplus_specific (struct general_symbol_info *gsymbol, void symbol_set_demangled_name (struct general_symbol_info *gsymbol, const char *name, - struct objfile *objfile) + struct obstack *obstack) { if (gsymbol->language == language_cplus) { if (gsymbol->language_specific.cplus_specific == NULL) - symbol_init_cplus_specific (gsymbol, objfile); + symbol_init_cplus_specific (gsymbol, obstack); gsymbol->language_specific.cplus_specific->demangled_name = name; } + else if (gsymbol->language == language_ada) + { + if (name == NULL) + { + gsymbol->ada_mangled = 0; + gsymbol->language_specific.obstack = obstack; + } + else + { + gsymbol->ada_mangled = 1; + gsymbol->language_specific.mangled_lang.demangled_name = name; + } + } else gsymbol->language_specific.mangled_lang.demangled_name = name; } @@ -464,8 +508,14 @@ symbol_get_demangled_name (const struct general_symbol_info *gsymbol) else return NULL; } - else - return gsymbol->language_specific.mangled_lang.demangled_name; + else if (gsymbol->language == language_ada) + { + if (!gsymbol->ada_mangled) + return NULL; + /* Fall through. */ + } + + return gsymbol->language_specific.mangled_lang.demangled_name; } @@ -474,7 +524,8 @@ symbol_get_demangled_name (const struct general_symbol_info *gsymbol) void symbol_set_language (struct general_symbol_info *gsymbol, - enum language language) + enum language language, + struct obstack *obstack) { gsymbol->language = language; if (gsymbol->language == language_d @@ -483,7 +534,12 @@ symbol_set_language (struct general_symbol_info *gsymbol, || gsymbol->language == language_objc || gsymbol->language == language_fortran) { - symbol_set_demangled_name (gsymbol, NULL, NULL); + symbol_set_demangled_name (gsymbol, NULL, obstack); + } + else if (gsymbol->language == language_ada) + { + gdb_assert (gsymbol->ada_mangled == 0); + gsymbol->language_specific.obstack = obstack; } else if (gsymbol->language == language_cplus) gsymbol->language_specific.cplus_specific = NULL; @@ -571,7 +627,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol, || gsymbol->language == language_auto) { demangled = - cplus_demangle (mangled, DMGL_PARAMS | DMGL_ANSI); + gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI); if (demangled != NULL) { gsymbol->language = language_cplus; @@ -581,8 +637,8 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol, if (gsymbol->language == language_java) { demangled = - cplus_demangle (mangled, - DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA); + gdb_demangle (mangled, + DMGL_PARAMS | DMGL_ANSI | DMGL_JAVA); if (demangled != NULL) { gsymbol->language = language_java; @@ -688,7 +744,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, name[len] = '\0'; gsymbol->name = name; } - symbol_set_demangled_name (gsymbol, NULL, NULL); + symbol_set_demangled_name (gsymbol, NULL, &objfile->objfile_obstack); return; } @@ -791,9 +847,10 @@ symbol_set_names (struct general_symbol_info *gsymbol, gsymbol->name = (*slot)->mangled + lookup_len - len; if ((*slot)->demangled[0] != '\0') - symbol_set_demangled_name (gsymbol, (*slot)->demangled, objfile); + symbol_set_demangled_name (gsymbol, (*slot)->demangled, + &objfile->objfile_obstack); else - symbol_set_demangled_name (gsymbol, NULL, objfile); + symbol_set_demangled_name (gsymbol, NULL, &objfile->objfile_obstack); } /* Return the source code name of a symbol. In languages where @@ -814,11 +871,7 @@ symbol_natural_name (const struct general_symbol_info *gsymbol) return symbol_get_demangled_name (gsymbol); break; case language_ada: - if (symbol_get_demangled_name (gsymbol) != NULL) - return symbol_get_demangled_name (gsymbol); - else - return ada_decode_symbol (gsymbol); - break; + return ada_decode_symbol (gsymbol); default: break; } @@ -844,9 +897,7 @@ symbol_demangled_name (const struct general_symbol_info *gsymbol) dem_name = symbol_get_demangled_name (gsymbol); break; case language_ada: - dem_name = symbol_get_demangled_name (gsymbol); - if (dem_name == NULL) - dem_name = ada_decode_symbol (gsymbol); + dem_name = ada_decode_symbol (gsymbol); break; default: break; @@ -959,7 +1010,7 @@ find_pc_sect_symtab_via_partial (CORE_ADDR pc, struct obj_section *section) /* If we know that this is not a text address, return failure. This is necessary because we loop based on texthigh and textlow, which do not include the data ranges. */ - msymbol = lookup_minimal_symbol_by_pc_section (pc, section); + msymbol = lookup_minimal_symbol_by_pc_section (pc, section).minsym; if (msymbol && (MSYMBOL_TYPE (msymbol) == mst_data || MSYMBOL_TYPE (msymbol) == mst_bss @@ -998,10 +1049,7 @@ fixup_section (struct general_symbol_info *ginfo, point to the actual function code. */ msym = lookup_minimal_symbol_by_pc_name (addr, ginfo->name, objfile); if (msym) - { - ginfo->obj_section = SYMBOL_OBJ_SECTION (msym); - ginfo->section = SYMBOL_SECTION (msym); - } + ginfo->section = SYMBOL_SECTION (msym); else { /* Static, function-local variables do appear in the linker @@ -1041,20 +1089,31 @@ fixup_section (struct general_symbol_info *ginfo, a search of the section table. */ struct obj_section *s; + int fallback = -1; ALL_OBJFILE_OSECTIONS (objfile, s) { - int idx = s->the_bfd_section->index; + int idx = s - objfile->sections; CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx); + if (fallback == -1) + fallback = idx; + if (obj_section_addr (s) - offset <= addr && addr < obj_section_endaddr (s) - offset) { - ginfo->obj_section = s; ginfo->section = idx; return; } } + + /* If we didn't find the section, assume it is in the first + section. If there is no allocated section, then it hardly + matters what we pick, so just pick zero. */ + if (fallback == -1) + ginfo->section = 0; + else + ginfo->section = fallback; } } @@ -1066,9 +1125,6 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile) if (!sym) return NULL; - if (SYMBOL_OBJ_SECTION (sym)) - return sym; - /* We either have an OBJFILE, or we can get at it from the sym's symtab. Anything else is a bug. */ gdb_assert (objfile || SYMBOL_SYMTAB (sym)); @@ -1076,6 +1132,9 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile) if (objfile == NULL) objfile = SYMBOL_SYMTAB (sym)->objfile; + if (SYMBOL_OBJ_SECTION (objfile, sym)) + return sym; + /* We should have an objfile by now. */ gdb_assert (objfile); @@ -1132,7 +1191,7 @@ demangle_for_lookup (const char *name, enum language lang, lookup, so we can always binary search. */ if (lang == language_cplus) { - demangled_name = cplus_demangle (name, DMGL_ANSI | DMGL_PARAMS); + demangled_name = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS); if (demangled_name) { modified_name = demangled_name; @@ -1152,8 +1211,8 @@ demangle_for_lookup (const char *name, enum language lang, } else if (lang == language_java) { - demangled_name = cplus_demangle (name, - DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA); + demangled_name = gdb_demangle (name, + DMGL_ANSI | DMGL_PARAMS | DMGL_JAVA); if (demangled_name) { modified_name = demangled_name; @@ -1921,29 +1980,6 @@ basic_lookup_transparent_type (const char *name) return (struct type *) 0; } -/* Find the name of the file containing main(). */ -/* FIXME: What about languages without main() or specially linked - executables that have no main() ? */ - -const char * -find_main_filename (void) -{ - struct objfile *objfile; - char *name = main_name (); - - ALL_OBJFILES (objfile) - { - const char *result; - - if (!objfile->sf) - continue; - result = objfile->sf->qf->find_symbol_file (objfile, name); - if (result) - return result; - } - return (NULL); -} - /* Search BLOCK for symbol NAME in DOMAIN. Note that if NAME is the demangled form of a C++ symbol, we will fail @@ -2051,7 +2087,7 @@ find_pc_sect_symtab (CORE_ADDR pc, struct obj_section *section) addresses, which do not include the data ranges, and because we call find_pc_sect_psymtab which has a similar restriction based on the partial_symtab's texthigh and textlow. */ - msymbol = lookup_minimal_symbol_by_pc_section (pc, section); + msymbol = lookup_minimal_symbol_by_pc_section (pc, section).minsym; if (msymbol && (MSYMBOL_TYPE (msymbol) == mst_data || MSYMBOL_TYPE (msymbol) == mst_bss @@ -2111,7 +2147,8 @@ find_pc_sect_symtab (CORE_ADDR pc, struct obj_section *section) ALL_BLOCK_SYMBOLS (b, iter, sym) { fixup_symbol_section (sym, objfile); - if (matching_obj_sections (SYMBOL_OBJ_SECTION (sym), section)) + if (matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, sym), + section)) break; } if (sym == NULL) @@ -2182,7 +2219,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) struct linetable_entry *item; struct symtab_and_line val; struct blockvector *bv; - struct minimal_symbol *msymbol; + struct bound_minimal_symbol msymbol; struct minimal_symbol *mfunsym; struct objfile *objfile; @@ -2268,11 +2305,12 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) * infinite recursion. */ msymbol = lookup_minimal_symbol_by_pc (pc); - if (msymbol != NULL) - if (MSYMBOL_TYPE (msymbol) == mst_solib_trampoline) + if (msymbol.minsym != NULL) + if (MSYMBOL_TYPE (msymbol.minsym) == mst_solib_trampoline) { - mfunsym = lookup_minimal_symbol_text (SYMBOL_LINKAGE_NAME (msymbol), - NULL); + mfunsym + = lookup_minimal_symbol_text (SYMBOL_LINKAGE_NAME (msymbol.minsym), + NULL); if (mfunsym == NULL) /* I eliminated this warning since it is coming out * in the following situation: @@ -2288,7 +2326,7 @@ find_pc_sect_line (CORE_ADDR pc, struct obj_section *section, int notcurrent) ; /* fall through */ else if (SYMBOL_VALUE_ADDRESS (mfunsym) - == SYMBOL_VALUE_ADDRESS (msymbol)) + == SYMBOL_VALUE_ADDRESS (msymbol.minsym)) /* Avoid infinite recursion */ /* See above comment about why warning is commented out. */ /* warning ("In stub for %s; unable to find real function/line info", @@ -2742,7 +2780,7 @@ find_function_start_sal (struct symbol *sym, int funfirstline) fixup_symbol_section (sym, NULL); sal = find_pc_sect_line (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), - SYMBOL_OBJ_SECTION (sym), 0); + SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sym), sym), 0); /* We always should have a line for the function start address. If we don't, something is odd. Create a plain SAL refering @@ -2753,7 +2791,7 @@ find_function_start_sal (struct symbol *sym, int funfirstline) init_sal (&sal); sal.pspace = current_program_space; sal.pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); - sal.section = SYMBOL_OBJ_SECTION (sym); + sal.section = SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sym), sym); } if (funfirstline) @@ -2794,25 +2832,25 @@ skip_prologue_sal (struct symtab_and_line *sal) fixup_symbol_section (sym, NULL); pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); - section = SYMBOL_OBJ_SECTION (sym); + section = SYMBOL_OBJ_SECTION (SYMBOL_OBJFILE (sym), sym); name = SYMBOL_LINKAGE_NAME (sym); objfile = SYMBOL_SYMTAB (sym)->objfile; } else { - struct minimal_symbol *msymbol + struct bound_minimal_symbol msymbol = lookup_minimal_symbol_by_pc_section (sal->pc, sal->section); - if (msymbol == NULL) + if (msymbol.minsym == NULL) { do_cleanups (old_chain); return; } - pc = SYMBOL_VALUE_ADDRESS (msymbol); - section = SYMBOL_OBJ_SECTION (msymbol); - name = SYMBOL_LINKAGE_NAME (msymbol); - objfile = msymbol_objfile (msymbol); + objfile = msymbol.objfile; + pc = SYMBOL_VALUE_ADDRESS (msymbol.minsym); + section = SYMBOL_OBJ_SECTION (objfile, msymbol.minsym); + name = SYMBOL_LINKAGE_NAME (msymbol.minsym); } gdbarch = get_objfile_arch (objfile); @@ -2857,8 +2895,8 @@ skip_prologue_sal (struct symtab_and_line *sal) if (skip && start_sal.pc != pc && (sym ? (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)) <= start_sal.end && start_sal.end < BLOCK_END (SYMBOL_BLOCK_VALUE (sym))) - : (lookup_minimal_symbol_by_pc_section (start_sal.end, section) - == lookup_minimal_symbol_by_pc_section (pc, section)))) + : (lookup_minimal_symbol_by_pc_section (start_sal.end, section).minsym + == lookup_minimal_symbol_by_pc_section (pc, section).minsym))) { /* First pc of next line */ pc = start_sal.end; @@ -3275,64 +3313,89 @@ free_search_symbols (struct symbol_search *symbols) } static void -do_free_search_symbols_cleanup (void *symbols) +do_free_search_symbols_cleanup (void *symbolsp) { + struct symbol_search *symbols = *(struct symbol_search **) symbolsp; + free_search_symbols (symbols); } struct cleanup * -make_cleanup_free_search_symbols (struct symbol_search *symbols) +make_cleanup_free_search_symbols (struct symbol_search **symbolsp) { - return make_cleanup (do_free_search_symbols_cleanup, symbols); + return make_cleanup (do_free_search_symbols_cleanup, symbolsp); } -/* Helper function for sort_search_symbols and qsort. Can only +/* Helper function for sort_search_symbols_remove_dups and qsort. Can only sort symbols, not minimal symbols. */ static int compare_search_syms (const void *sa, const void *sb) { - struct symbol_search **sym_a = (struct symbol_search **) sa; - struct symbol_search **sym_b = (struct symbol_search **) sb; + struct symbol_search *sym_a = *(struct symbol_search **) sa; + struct symbol_search *sym_b = *(struct symbol_search **) sb; + int c; + + c = strcmp (sym_a->symtab->filename, sym_b->symtab->filename); + if (c != 0) + return c; + + if (sym_a->block != sym_b->block) + return sym_a->block - sym_b->block; - return strcmp (SYMBOL_PRINT_NAME ((*sym_a)->symbol), - SYMBOL_PRINT_NAME ((*sym_b)->symbol)); + return strcmp (SYMBOL_PRINT_NAME (sym_a->symbol), + SYMBOL_PRINT_NAME (sym_b->symbol)); } -/* Sort the ``nfound'' symbols in the list after prevtail. Leave - prevtail where it is, but update its next pointer to point to - the first of the sorted symbols. */ +/* Sort the NFOUND symbols in list FOUND and remove duplicates. + The duplicates are freed, and the new list is returned in + *NEW_HEAD, *NEW_TAIL. */ -static struct symbol_search * -sort_search_symbols (struct symbol_search *prevtail, int nfound) +static void +sort_search_symbols_remove_dups (struct symbol_search *found, int nfound, + struct symbol_search **new_head, + struct symbol_search **new_tail) { struct symbol_search **symbols, *symp, *old_next; - int i; + int i, j, nunique; + gdb_assert (found != NULL && nfound > 0); + + /* Build an array out of the list so we can easily sort them. */ symbols = (struct symbol_search **) xmalloc (sizeof (struct symbol_search *) * nfound); - symp = prevtail->next; + symp = found; for (i = 0; i < nfound; i++) { + gdb_assert (symp != NULL); + gdb_assert (symp->block >= 0 && symp->block <= 1); symbols[i] = symp; symp = symp->next; } - /* Generally NULL. */ - old_next = symp; + gdb_assert (symp == NULL); qsort (symbols, nfound, sizeof (struct symbol_search *), compare_search_syms); - symp = prevtail; - for (i = 0; i < nfound; i++) + /* Collapse out the dups. */ + for (i = 1, j = 1; i < nfound; ++i) { - symp->next = symbols[i]; - symp = symp->next; + if (compare_search_syms (&symbols[j - 1], &symbols[i]) != 0) + symbols[j++] = symbols[i]; + else + xfree (symbols[i]); } - symp->next = old_next; + nunique = j; + symbols[j - 1]->next = NULL; + /* Rebuild the linked list. */ + for (i = 0; i < nunique - 1; i++) + symbols[i]->next = symbols[i + 1]; + symbols[nunique - 1]->next = NULL; + + *new_head = symbols[0]; + *new_tail = symbols[nunique - 1]; xfree (symbols); - return symp; } /* An object of this type is passed as the user_data to the @@ -3380,8 +3443,9 @@ search_symbols_name_matches (const char *symname, void *user_data) free_search_symbols should be called when *MATCHES is no longer needed. - The results are sorted locally; each symtab's global and static blocks are - separately alphabetized. */ + Within each file the results are sorted locally; each symtab's global and + static blocks are separately alphabetized. + Duplicate entries are removed. */ void search_symbols (char *regexp, enum search_domain kind, @@ -3409,10 +3473,10 @@ search_symbols (char *regexp, enum search_domain kind, enum minimal_symbol_type ourtype2; enum minimal_symbol_type ourtype3; enum minimal_symbol_type ourtype4; - struct symbol_search *sr; - struct symbol_search *psr; + struct symbol_search *found; struct symbol_search *tail; struct search_symbols_data datum; + int nfound; /* OLD_CHAIN .. RETVAL_CHAIN is always freed, RETVAL_CHAIN .. current CLEANUP_CHAIN is freed only in the case of an error. */ @@ -3426,8 +3490,7 @@ search_symbols (char *regexp, enum search_domain kind, ourtype3 = types3[kind]; ourtype4 = types4[kind]; - sr = *matches = NULL; - tail = NULL; + *matches = NULL; datum.preg_p = 0; if (regexp != NULL) @@ -3499,8 +3562,6 @@ search_symbols (char *regexp, enum search_domain kind, &datum); } - retval_chain = old_chain; - /* Here, we search through the minimal symbol tables for functions and variables that match, and force their symbols to be read. This is in particular necessary for demangled variable names, @@ -3549,14 +3610,16 @@ search_symbols (char *regexp, enum search_domain kind, } } + found = NULL; + tail = NULL; + nfound = 0; + retval_chain = make_cleanup_free_search_symbols (&found); + ALL_PRIMARY_SYMTABS (objfile, s) { bv = BLOCKVECTOR (s); for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) { - struct symbol_search *prevtail = tail; - int nfound = 0; - b = BLOCKVECTOR_BLOCK (bv, i); ALL_BLOCK_SYMBOLS (b, iter, sym) { @@ -3591,39 +3654,30 @@ search_symbols (char *regexp, enum search_domain kind, && SYMBOL_CLASS (sym) == LOC_TYPEDEF)))) { /* match */ - psr = (struct symbol_search *) + struct symbol_search *psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search)); psr->block = i; psr->symtab = real_symtab; psr->symbol = sym; - psr->msymbol = NULL; + memset (&psr->msymbol, 0, sizeof (psr->msymbol)); psr->next = NULL; if (tail == NULL) - sr = psr; + found = psr; else tail->next = psr; tail = psr; nfound ++; } } - if (nfound > 0) - { - if (prevtail == NULL) - { - struct symbol_search dummy; - - dummy.next = sr; - tail = sort_search_symbols (&dummy, nfound); - sr = dummy.next; - - make_cleanup_free_search_symbols (sr); - } - else - tail = sort_search_symbols (prevtail, nfound); - } } } + if (found != NULL) + { + sort_search_symbols_remove_dups (found, nfound, &found, &tail); + /* Note: nfound is no longer useful beyond this point. */ + } + /* If there are no eyes, avoid all contact. I mean, if there are no debug symbols, then print directly from the msymbol_vector. */ @@ -3655,18 +3709,16 @@ search_symbols (char *regexp, enum search_domain kind, == NULL) { /* match */ - psr = (struct symbol_search *) + struct symbol_search *psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search)); psr->block = i; - psr->msymbol = msymbol; + psr->msymbol.minsym = msymbol; + psr->msymbol.objfile = objfile; psr->symtab = NULL; psr->symbol = NULL; psr->next = NULL; if (tail == NULL) - { - sr = psr; - make_cleanup_free_search_symbols (sr); - } + found = psr; else tail->next = psr; tail = psr; @@ -3679,7 +3731,7 @@ search_symbols (char *regexp, enum search_domain kind, discard_cleanups (retval_chain); do_cleanups (old_chain); - *matches = sr; + *matches = found; } /* Helper function for symtab_symbol_info, this function uses @@ -3725,20 +3777,20 @@ print_symbol_info (enum search_domain kind, for non-debugging symbols to gdb_stdout. */ static void -print_msymbol_info (struct minimal_symbol *msymbol) +print_msymbol_info (struct bound_minimal_symbol msymbol) { - struct gdbarch *gdbarch = get_objfile_arch (msymbol_objfile (msymbol)); + struct gdbarch *gdbarch = get_objfile_arch (msymbol.objfile); char *tmp; if (gdbarch_addr_bit (gdbarch) <= 32) - tmp = hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol) + tmp = hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol.minsym) & (CORE_ADDR) 0xffffffff, 8); else - tmp = hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol), + tmp = hex_string_custom (SYMBOL_VALUE_ADDRESS (msymbol.minsym), 16); printf_filtered ("%s %s\n", - tmp, SYMBOL_PRINT_NAME (msymbol)); + tmp, SYMBOL_PRINT_NAME (msymbol.minsym)); } /* This is the guts of the commands "info functions", "info types", and @@ -3761,7 +3813,7 @@ symtab_symbol_info (char *regexp, enum search_domain kind, int from_tty) /* Must make sure that if we're interrupted, symbols gets freed. */ search_symbols (regexp, kind, 0, (char **) NULL, &symbols); - old_chain = make_cleanup_free_search_symbols (symbols); + old_chain = make_cleanup_free_search_symbols (&symbols); if (regexp != NULL) printf_filtered (_("All %ss matching regular expression \"%s\":\n"), @@ -3773,7 +3825,7 @@ symtab_symbol_info (char *regexp, enum search_domain kind, int from_tty) { QUIT; - if (p->msymbol != NULL) + if (p->msymbol.minsym != NULL) { if (first) { @@ -3863,14 +3915,14 @@ rbreak_command (char *regexp, int from_tty) } search_symbols (regexp, FUNCTIONS_DOMAIN, nfiles, files, &ss); - old_chain = make_cleanup_free_search_symbols (ss); + old_chain = make_cleanup_free_search_symbols (&ss); make_cleanup (free_current_contents, &string); start_rbreak_breakpoints (); make_cleanup (do_end_rbreak_breakpoints, NULL); for (p = ss; p != NULL; p = p->next) { - if (p->msymbol == NULL) + if (p->msymbol.minsym == NULL) { const char *fullname = symtab_to_fullname (p->symtab); @@ -3896,7 +3948,7 @@ rbreak_command (char *regexp, int from_tty) } else { - int newlen = (strlen (SYMBOL_LINKAGE_NAME (p->msymbol)) + 3); + int newlen = (strlen (SYMBOL_LINKAGE_NAME (p->msymbol.minsym)) + 3); if (newlen > len) { @@ -3904,12 +3956,12 @@ rbreak_command (char *regexp, int from_tty) len = newlen; } strcpy (string, "'"); - strcat (string, SYMBOL_LINKAGE_NAME (p->msymbol)); + strcat (string, SYMBOL_LINKAGE_NAME (p->msymbol.minsym)); strcat (string, "'"); break_command (string, from_tty); printf_filtered (" %s;\n", - SYMBOL_PRINT_NAME (p->msymbol)); + SYMBOL_PRINT_NAME (p->msymbol.minsym)); } } @@ -5053,6 +5105,13 @@ register_symbol_computed_impl (enum address_class aclass, symbol_impl[result].aclass = aclass; symbol_impl[result].ops_computed = ops; + /* Sanity check OPS. */ + gdb_assert (ops != NULL); + gdb_assert (ops->tracepoint_var_ref != NULL); + gdb_assert (ops->describe_location != NULL); + gdb_assert (ops->read_needs_frame != NULL); + gdb_assert (ops->read_variable != NULL); + return result; } @@ -5112,6 +5171,45 @@ initialize_ordinary_address_classes (void) +/* Initialize the symbol SYM. */ + +void +initialize_symbol (struct symbol *sym) +{ + memset (sym, 0, sizeof (*sym)); + SYMBOL_SECTION (sym) = -1; +} + +/* Allocate and initialize a new 'struct symbol' on OBJFILE's + obstack. */ + +struct symbol * +allocate_symbol (struct objfile *objfile) +{ + struct symbol *result; + + result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); + SYMBOL_SECTION (result) = -1; + + return result; +} + +/* Allocate and initialize a new 'struct template_symbol' on OBJFILE's + obstack. */ + +struct template_symbol * +allocate_template_symbol (struct objfile *objfile) +{ + struct template_symbol *result; + + result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct template_symbol); + SYMBOL_SECTION (&result->base) = -1; + + return result; +} + + + void _initialize_symtab (void) {