X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fsymtab.c;h=09b2326ed5276026a772c3cf750f972a9af3fd2f;hb=8372a7cb96e9d193cb1f85f3fd2c01e38c33a750;hp=8ef3966fc16a338675a79c6e0b0eb074134d321f;hpb=f85f34ede85d0c306e689736c6694caa2f0a0f78;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/symtab.c b/gdb/symtab.c index 8ef3966fc1..09b2326ed5 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -1,6 +1,6 @@ /* Symbol table lookup for the GNU debugger, GDB. - Copyright (C) 1986-2013 Free Software Foundation, Inc. + Copyright (C) 1986-2014 Free Software Foundation, Inc. This file is part of GDB. @@ -50,8 +50,8 @@ #include #include -#include "gdb_string.h" -#include "gdb_stat.h" +#include +#include #include #include "cp-abi.h" #include "cp-support.h" @@ -61,7 +61,6 @@ #include "macrotab.h" #include "macroscope.h" -#include "psymtab.h" #include "parser-defs.h" /* Prototypes for local functions */ @@ -101,14 +100,29 @@ 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); /* */ +/* Program space key for finding name and language of "main". */ + +static const struct program_space_data *main_progspace_key; + +/* Type of the data stored on the program space. */ + +struct main_info +{ + /* Name of "main". */ + + char *name_of_main; + + /* Language of "main". */ + + enum language language_of_main; +}; + /* When non-zero, print debugging messages related to symtab creation. */ -int symtab_create_debug = 0; +unsigned int symtab_create_debug = 0; /* Non-zero if a file may be known by two different basenames. This is the uncommon case, and significantly slows down gdb. @@ -145,6 +159,53 @@ 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"); + } +} + +/* Set the primary field in SYMTAB. */ + +void +set_symtab_primary (struct symtab *symtab, int primary) +{ + symtab->primary = primary; + + if (symtab_create_debug && primary) + { + fprintf_unfiltered (gdb_stdlog, + "Created primary symtab %s for %s.\n", + host_address_to_string (symtab), + symtab_to_filename_for_display (symtab)); + } +} + /* 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 +247,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 +279,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; @@ -561,7 +624,7 @@ create_demangled_names_hash (struct objfile *objfile) Choosing a much larger table size wastes memory, and saves only about 1% in symbol reading. */ - objfile->demangled_names_hash = htab_create_alloc + objfile->per_bfd->demangled_names_hash = htab_create_alloc (256, hash_demangled_name_entry, eq_demangled_name_entry, NULL, xcalloc, xfree); } @@ -596,7 +659,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; @@ -606,8 +669,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; @@ -645,6 +708,42 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol, symbols). Just the mangling standard is not standardized across compilers and there is no DW_AT_producer available for inferiors with only the ELF symbols to check the mangling kind. */ + + /* Check for Ada symbols last. See comment below explaining why. */ + + if (gsymbol->language == language_auto) + { + const char *demangled = ada_decode (mangled); + + if (demangled != mangled && demangled != NULL && demangled[0] != '<') + { + /* Set the gsymbol language to Ada, but still return NULL. + Two reasons for that: + + 1. For Ada, we prefer computing the symbol's decoded name + on the fly rather than pre-compute it, in order to save + memory (Ada projects are typically very large). + + 2. There are some areas in the definition of the GNAT + encoding where, with a bit of bad luck, we might be able + to decode a non-Ada symbol, generating an incorrect + demangled name (Eg: names ending with "TB" for instance + are identified as task bodies and so stripped from + the decoded name returned). + + Returning NULL, here, helps us get a little bit of + the best of both worlds. Because we're last, we should + not affect any of the other languages that were able to + demangle the symbol before us; we get to correctly tag + Ada symbols as such; and even if we incorrectly tagged + a non-Ada symbol, which should be rare, any routing + through the Ada language should be transparent (Ada + tries to behave much like C/C++ with non-Ada symbols). */ + gsymbol->language = language_ada; + return NULL; + } + } + return NULL; } @@ -656,7 +755,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol, objfile), and it will not be copied. The hash table corresponding to OBJFILE is used, and the memory - comes from that objfile's objfile_obstack. LINKAGE_NAME is copied, + comes from the per-BFD storage_obstack. LINKAGE_NAME is copied, so the pointer can be discarded after calling this function. */ /* We have to be careful when dealing with Java names: when we run @@ -692,6 +791,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, /* The length of lookup_name. */ int lookup_len; struct demangled_name_entry entry; + struct objfile_per_bfd_storage *per_bfd = objfile->per_bfd; if (gsymbol->language == language_ada) { @@ -707,18 +807,18 @@ symbol_set_names (struct general_symbol_info *gsymbol, gsymbol->name = linkage_name; else { - char *name = obstack_alloc (&objfile->objfile_obstack, len + 1); + char *name = obstack_alloc (&per_bfd->storage_obstack, len + 1); memcpy (name, linkage_name, len); name[len] = '\0'; gsymbol->name = name; } - symbol_set_demangled_name (gsymbol, NULL, &objfile->objfile_obstack); + symbol_set_demangled_name (gsymbol, NULL, &per_bfd->storage_obstack); return; } - if (objfile->demangled_names_hash == NULL) + if (per_bfd->demangled_names_hash == NULL) create_demangled_names_hash (objfile); /* The stabs reader generally provides names that are not @@ -758,7 +858,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, entry.mangled = lookup_name; slot = ((struct demangled_name_entry **) - htab_find_slot (objfile->demangled_names_hash, + htab_find_slot (per_bfd->demangled_names_hash, &entry, INSERT)); /* If this name is not in the hash table, add it. */ @@ -783,7 +883,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, us better bcache hit rates for partial symbols. */ if (!copy_name && lookup_name == linkage_name) { - *slot = obstack_alloc (&objfile->objfile_obstack, + *slot = obstack_alloc (&per_bfd->storage_obstack, offsetof (struct demangled_name_entry, demangled) + demangled_len + 1); @@ -796,7 +896,7 @@ symbol_set_names (struct general_symbol_info *gsymbol, /* If we must copy the mangled name, put it directly after the demangled name so we can have a single allocation. */ - *slot = obstack_alloc (&objfile->objfile_obstack, + *slot = obstack_alloc (&per_bfd->storage_obstack, offsetof (struct demangled_name_entry, demangled) + lookup_len + demangled_len + 2); @@ -817,9 +917,9 @@ 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->objfile_obstack); + &per_bfd->storage_obstack); else - symbol_set_demangled_name (gsymbol, NULL, &objfile->objfile_obstack); + symbol_set_demangled_name (gsymbol, NULL, &per_bfd->storage_obstack); } /* Return the source code name of a symbol. In languages where @@ -979,7 +1079,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 @@ -1018,10 +1118,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 @@ -1061,20 +1158,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; } } @@ -1086,9 +1194,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)); @@ -1096,6 +1201,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); @@ -1152,7 +1260,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; @@ -1172,8 +1280,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; @@ -1941,29 +2049,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 @@ -2071,7 +2156,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 @@ -2131,7 +2216,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) @@ -2202,7 +2288,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; @@ -2288,11 +2374,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: @@ -2308,7 +2395,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", @@ -2762,7 +2849,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 @@ -2773,7 +2860,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) @@ -2814,25 +2901,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); @@ -2877,8 +2964,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; @@ -3249,8 +3336,8 @@ sources_info (char *ignore, int from_tty) clear_filename_seen_cache (data.filename_seen_cache); data.first = 1; - map_partial_symbol_filenames (output_partial_symbol_filename, &data, - 1 /*need_fullname*/); + map_symbol_filenames (output_partial_symbol_filename, &data, + 1 /*need_fullname*/); printf_filtered ("\n"); do_cleanups (cleanups); @@ -3295,64 +3382,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 = FILENAME_CMP (sym_a->symtab->filename, sym_b->symtab->filename); + if (c != 0) + return c; - return strcmp (SYMBOL_PRINT_NAME ((*sym_a)->symbol), - SYMBOL_PRINT_NAME ((*sym_b)->symbol)); + 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)); } -/* 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 @@ -3400,8 +3512,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, @@ -3429,10 +3542,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. */ @@ -3446,8 +3559,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) @@ -3507,19 +3619,11 @@ search_symbols (char *regexp, enum search_domain kind, datum.nfiles = nfiles; datum.files = files; - ALL_OBJFILES (objfile) - { - if (objfile->sf) - objfile->sf->qf->expand_symtabs_matching (objfile, - (nfiles == 0 - ? NULL - : search_symbols_file_matches), - search_symbols_name_matches, - kind, - &datum); - } - - retval_chain = old_chain; + expand_symtabs_matching ((nfiles == 0 + ? NULL + : search_symbols_file_matches), + search_symbols_name_matches, + kind, &datum); /* Here, we search through the minimal symbol tables for functions and variables that match, and force their symbols to be read. @@ -3569,14 +3673,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) { @@ -3611,39 +3717,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. */ @@ -3675,18 +3772,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; @@ -3699,7 +3794,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 @@ -3745,20 +3840,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 @@ -3781,7 +3876,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"), @@ -3793,7 +3888,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) { @@ -3883,14 +3978,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); @@ -3916,7 +4011,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) { @@ -3924,12 +4019,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)); } } @@ -4169,7 +4264,7 @@ completion_list_add_fields (struct symbol *sym, const char *sym_text, } /* Type of the user_data argument passed to add_macro_name or - expand_partial_symbol_name. The contents are simply whatever is + symbol_completion_matcher. The contents are simply whatever is needed by completion_list_add_name. */ struct add_name_data { @@ -4194,10 +4289,10 @@ add_macro_name (const char *name, const struct macro_definition *ignore, datum->text, datum->word); } -/* A callback for expand_partial_symbol_names. */ +/* A callback for expand_symtabs_matching. */ static int -expand_partial_symbol_name (const char *name, void *user_data) +symbol_completion_matcher (const char *name, void *user_data) { struct add_name_data *datum = (struct add_name_data *) user_data; @@ -4308,7 +4403,8 @@ default_make_symbol_completion_list_break_on (const char *text, /* Look through the partial symtabs for all symbols which begin by matching SYM_TEXT. Expand all CUs that you find to the list. The real names will get added by COMPLETION_LIST_ADD_SYMBOL below. */ - expand_partial_symbol_names (expand_partial_symbol_name, &datum); + expand_symtabs_matching (NULL, symbol_completion_matcher, ALL_DOMAIN, + &datum); /* At this point scan through the misc symbol vectors and add each symbol you find to the list. Eventually we want to ignore @@ -4722,8 +4818,8 @@ make_source_files_completion_list (const char *text, const char *word) datum.word = word; datum.text_len = text_len; datum.list = &list; - map_partial_symbol_filenames (maybe_add_partial_symtab_filename, &datum, - 0 /*need_fullname*/); + map_symbol_filenames (maybe_add_partial_symtab_filename, &datum, + 0 /*need_fullname*/); do_cleanups (cache_cleanup); discard_cleanups (back_to); @@ -4919,22 +5015,62 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr) } /* Track MAIN */ -static char *name_of_main; -enum language language_of_main = language_unknown; -void -set_main_name (const char *name) +/* Return the "main_info" object for the current program space. If + the object has not yet been created, create it and fill in some + default values. */ + +static struct main_info * +get_main_info (void) +{ + struct main_info *info = program_space_data (current_program_space, + main_progspace_key); + + if (info == NULL) + { + /* It may seem strange to store the main name in the progspace + and also in whatever objfile happens to see a main name in + its debug info. The reason for this is mainly historical: + gdb returned "main" as the name even if no function named + "main" was defined the program; and this approach lets us + keep compatibility. */ + info = XCNEW (struct main_info); + info->language_of_main = language_unknown; + set_program_space_data (current_program_space, main_progspace_key, + info); + } + + return info; +} + +/* A cleanup to destroy a struct main_info when a progspace is + destroyed. */ + +static void +main_info_cleanup (struct program_space *pspace, void *data) { - if (name_of_main != NULL) + struct main_info *info = data; + + if (info != NULL) + xfree (info->name_of_main); + xfree (info); +} + +static void +set_main_name (const char *name, enum language lang) +{ + struct main_info *info = get_main_info (); + + if (info->name_of_main != NULL) { - xfree (name_of_main); - name_of_main = NULL; - language_of_main = language_unknown; + xfree (info->name_of_main); + info->name_of_main = NULL; + info->language_of_main = language_unknown; } if (name != NULL) { - name_of_main = xstrdup (name); - language_of_main = language_unknown; + info->name_of_main = xstrdup (name); + info->language_of_main = lang; } } @@ -4945,6 +5081,23 @@ static void find_main_name (void) { const char *new_main_name; + struct objfile *objfile; + + /* First check the objfiles to see whether a debuginfo reader has + picked up the appropriate main name. Historically the main name + was found in a more or less random way; this approach instead + relies on the order of objfile creation -- which still isn't + guaranteed to get the correct answer, but is just probably more + accurate. */ + ALL_OBJFILES (objfile) + { + if (objfile->per_bfd->name_of_main != NULL) + { + set_main_name (objfile->per_bfd->name_of_main, + objfile->per_bfd->language_of_main); + return; + } + } /* Try to see if the main procedure is in Ada. */ /* FIXME: brobecker/2005-03-07: Another way of doing this would @@ -4965,36 +5118,52 @@ find_main_name (void) new_main_name = ada_main_name (); if (new_main_name != NULL) { - set_main_name (new_main_name); + set_main_name (new_main_name, language_ada); return; } new_main_name = go_main_name (); if (new_main_name != NULL) { - set_main_name (new_main_name); + set_main_name (new_main_name, language_go); return; } new_main_name = pascal_main_name (); if (new_main_name != NULL) { - set_main_name (new_main_name); + set_main_name (new_main_name, language_pascal); return; } /* The languages above didn't identify the name of the main procedure. Fallback to "main". */ - set_main_name ("main"); + set_main_name ("main", language_unknown); } char * main_name (void) { - if (name_of_main == NULL) + struct main_info *info = get_main_info (); + + if (info->name_of_main == NULL) find_main_name (); - return name_of_main; + return info->name_of_main; +} + +/* Return the language of the main function. If it is not known, + return language_unknown. */ + +enum language +main_language (void) +{ + struct main_info *info = get_main_info (); + + if (info->name_of_main == NULL) + find_main_name (); + + return info->language_of_main; } /* Handle ``executable_changed'' events for the symtab module. */ @@ -5003,7 +5172,7 @@ static void symtab_observer_executable_changed (void) { /* NAME_OF_MAIN may no longer be the same, so reset it for now. */ - set_main_name (NULL); + set_main_name (NULL, language_unknown); } /* Return 1 if the supplied producer string matches the ARM RealView @@ -5145,6 +5314,7 @@ 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 @@ -5156,6 +5326,7 @@ allocate_symbol (struct objfile *objfile) struct symbol *result; result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); + SYMBOL_SECTION (result) = -1; return result; } @@ -5169,6 +5340,7 @@ 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; } @@ -5180,6 +5352,9 @@ _initialize_symtab (void) { initialize_ordinary_address_classes (); + main_progspace_key + = register_program_space_data_with_cleanup (NULL, main_info_cleanup); + add_info ("variables", variables_info, _("\ All global and static variable names, or those matching REGEXP.")); if (dbx_commands) @@ -5237,13 +5412,15 @@ one base name, and gdb will do file name comparisons more efficiently."), NULL, NULL, &setlist, &showlist); - add_setshow_boolean_cmd ("symtab-create", no_class, &symtab_create_debug, - _("Set debugging of symbol table creation."), - _("Show debugging of symbol table creation."), _("\ -When enabled, debugging messages are printed when building symbol tables."), - NULL, - NULL, - &setdebuglist, &showdebuglist); + add_setshow_zuinteger_cmd ("symtab-create", no_class, &symtab_create_debug, + _("Set debugging of symbol table creation."), + _("Show debugging of symbol table creation."), _("\ +When enabled (non-zero), debugging messages are printed when building\n\ +symbol tables. A value of 1 (one) normally provides enough information.\n\ +A value greater than 1 provides more verbose information."), + NULL, + NULL, + &setdebuglist, &showdebuglist); observer_attach_executable_changed (symtab_observer_executable_changed); }