diff options
Diffstat (limited to 'gdb/symtab.c')
-rw-r--r-- | gdb/symtab.c | 605 |
1 files changed, 195 insertions, 410 deletions
diff --git a/gdb/symtab.c b/gdb/symtab.c index 5147aee..d4089c8 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -56,11 +56,9 @@ #include <sys/types.h> #include <fcntl.h> #include <sys/stat.h> -#include <ctype.h> #include "cp-abi.h" #include "cp-support.h" #include "observable.h" -#include "solist.h" #include "macrotab.h" #include "macroscope.h" @@ -124,41 +122,6 @@ struct main_info static const registry<program_space>::key<main_info> main_progspace_key; -/* Symbol lookup is not reentrant (though this is not an intrinsic - restriction). Keep track of whether a symbol lookup is active, to be able - to detect reentrancy. */ -static bool in_symbol_lookup; - -/* Struct to mark that a symbol lookup is active for the duration of its - lifetime. */ - -struct enter_symbol_lookup -{ - enter_symbol_lookup () - { - /* Ensure that the current language has been set. Normally the - language is set lazily. However, when performing a symbol lookup, - this could result in a recursive call into the lookup code in some - cases. Set it now to ensure that this does not happen. */ - get_current_language (); - - /* Detect symbol lookup reentrance. */ - gdb_assert (!in_symbol_lookup); - - in_symbol_lookup = true; - } - - ~enter_symbol_lookup () - { - /* Sanity check. */ - gdb_assert (in_symbol_lookup); - - in_symbol_lookup = false; - } - - DISABLE_COPY_AND_ASSIGN (enter_symbol_lookup); -}; - /* The default symbol cache size. There is no extra cpu cost for large N (except when flushing the cache, which is rare). The value here is just a first attempt. A better default @@ -465,7 +428,8 @@ void compunit_symtab::set_call_site_htab (call_site_htab_t &&call_site_htab) { gdb_assert (m_call_site_htab == nullptr); - m_call_site_htab = new call_site_htab_t (std::move (call_site_htab)); + m_call_site_htab + = std::make_unique<call_site_htab_t> (std::move (call_site_htab)); } /* See symtab.h. */ @@ -530,11 +494,26 @@ compunit_symtab::forget_cached_source_info () /* See symtab.h. */ -void -compunit_symtab::finalize () +compunit_symtab::compunit_symtab (struct objfile *objfile, + const char *name_) + : m_objfile (objfile), + /* The name we record here is only for display/debugging purposes. + Just save the basename to avoid path issues (too long for + display, relative vs absolute, etc.). */ + name (obstack_strdup (&objfile->objfile_obstack, lbasename (name_))), + m_locations_valid (false), + m_epilogue_unwind_valid (false) +{ + symtab_create_debug_printf_v ("created compunit symtab %s for %s", + host_address_to_string (this), + name); +} + +/* See symtab.h. */ + +compunit_symtab::~compunit_symtab () { this->forget_cached_source_info (); - delete m_call_site_htab; } /* The relocated address of the minimal symbol, using the section @@ -623,82 +602,6 @@ compare_filenames_for_search (const char *filename, const char *search_name) && STRIP_DRIVE_SPEC (filename) == &filename[len - search_len])); } -/* 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 and CALLBACK are identical to the - `map_symtabs_matching_filename' method of quick_symbol_functions. - - FIRST and AFTER_LAST indicate the range of compunit symtabs to search. - Each symtab within the specified compunit symtab is also searched. - AFTER_LAST is one past the last compunit symtab to search; NULL means to - search until the end of the list. */ - -bool -iterate_over_some_symtabs (const char *name, - const char *real_path, - struct compunit_symtab *first, - struct compunit_symtab *after_last, - gdb::function_view<bool (symtab *)> callback) -{ - struct compunit_symtab *cust; - const char* base_name = lbasename (name); - - for (cust = first; cust != NULL && cust != after_last; cust = cust->next) - { - /* Skip included compunits. */ - if (cust->user != nullptr) - continue; - - for (symtab *s : cust->filetabs ()) - { - if (compare_filenames_for_search (s->filename, name)) - { - if (callback (s)) - return true; - 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)) - return true; - continue; - } - - /* 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)); - gdb::unique_xmalloc_ptr<char> fullname_real_path - = gdb_realpath (fullname); - fullname = fullname_real_path.get (); - if (FILENAME_CMP (real_path, fullname) == 0) - { - if (callback (s)) - return true; - continue; - } - } - } - } - - return false; -} - /* See symtab.h. */ void @@ -715,17 +618,9 @@ iterate_over_symtabs (program_space *pspace, const char *name, gdb_assert (IS_ABSOLUTE_PATH (real_path.get ())); } - for (objfile *objfile : pspace->objfiles ()) - if (iterate_over_some_symtabs (name, real_path.get (), - objfile->compunit_symtabs, nullptr, - callback)) - return; - - /* Same search rules as above apply here, but now we look through the - psymtabs. */ - for (objfile *objfile : pspace->objfiles ()) - if (objfile->map_symtabs_matching_filename (name, real_path.get (), - callback)) + for (objfile &objfile : pspace->objfiles ()) + if (objfile.map_symtabs_matching_filename (name, real_path.get (), + callback)) return; } @@ -1241,10 +1136,10 @@ matching_obj_sections (struct obj_section *obj_first, /* Otherwise check that they are in corresponding objfiles. */ struct objfile *obj = NULL; - for (objfile *objfile : current_program_space->objfiles ()) - if (objfile->obfd == first->owner) + for (objfile &objfile : current_program_space->objfiles ()) + if (objfile.obfd == first->owner) { - obj = objfile; + obj = &objfile; break; } gdb_assert (obj != NULL); @@ -1781,7 +1676,7 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile) index without doing the check that is done by the wrapper macros like SECT_OFF_TEXT. */ int fallback; - switch (sym->aclass ()) + switch (sym->loc_class ()) { case LOC_STATIC: fallback = objfile->sect_index_data; @@ -1847,18 +1742,18 @@ fixup_symbol_section (struct symbol *sym, struct objfile *objfile) this reason, we still attempt a lookup by name prior to doing a search of the section table. */ - for (obj_section *s : objfile->sections ()) + for (obj_section &s : objfile->sections ()) { - if ((bfd_section_flags (s->the_bfd_section) & SEC_ALLOC) == 0) + if ((bfd_section_flags (s.the_bfd_section) & SEC_ALLOC) == 0) continue; - int idx = s - objfile->sections_start; + int idx = &s - objfile->sections_start; CORE_ADDR offset = objfile->section_offsets[idx]; if (fallback == -1) fallback = idx; - if (s->addr () - offset <= addr && addr < s->endaddr () - offset) + if (s.addr () - offset <= addr && addr < s.endaddr () - offset) { sym->set_section_index (idx); return; @@ -2163,13 +2058,6 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type, domain_name (domain).c_str (), language_str (language)); } - /* 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 - certainly use it later. If we don't set it, the contents of - is_a_field_of_this are undefined. */ - if (is_a_field_of_this != NULL) - memset (is_a_field_of_this, 0, sizeof (*is_a_field_of_this)); - langdef = language_def (language); /* Search specified block and its superiors. Don't search @@ -2294,8 +2182,6 @@ lookup_symbol_in_block (const char *name, symbol_name_match_type match_type, const struct block *block, const domain_search_flags domain) { - enter_symbol_lookup tmp; - struct symbol *sym; if (symbol_lookup_debug) @@ -2331,8 +2217,6 @@ lookup_global_symbol_from_objfile (struct objfile *main_objfile, const char *name, const domain_search_flags domain) { - enter_symbol_lookup tmp; - gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK); for (objfile *objfile : main_objfile->separate_debug_objfiles ()) @@ -2365,44 +2249,26 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, block_index == GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK", name, domain_name (domain).c_str ()); - struct block_symbol other; - other.symbol = NULL; - for (compunit_symtab *cust : objfile->compunits ()) + lookup_name_info lookup_name (name, symbol_name_match_type::FULL); + best_symbol_tracker accum; + for (compunit_symtab &cust : objfile->compunits ()) { const struct blockvector *bv; const struct block *block; - struct block_symbol result; - bv = cust->blockvector (); + bv = cust.blockvector (); block = bv->block (block_index); - result.symbol = block_lookup_symbol_primary (block, name, domain); - result.block = block; - if (result.symbol == NULL) - continue; - if (best_symbol (result.symbol, domain)) - { - other = result; - break; - } - if (result.symbol->matches (domain)) - { - struct symbol *better - = better_symbol (other.symbol, result.symbol, domain); - if (better != other.symbol) - { - other.symbol = better; - other.block = block; - } - } + if (accum.search (&cust, block, lookup_name, domain)) + break; } - if (other.symbol != NULL) + if (accum.currently_best.symbol != nullptr) { symbol_lookup_debug_printf_v ("lookup_symbol_in_objfile_symtabs (...) = %s (block %s)", - host_address_to_string (other.symbol), - host_address_to_string (other.block)); - return other; + host_address_to_string (accum.currently_best.symbol), + host_address_to_string (accum.currently_best.block)); + return accum.currently_best; } symbol_lookup_debug_printf_v @@ -2476,11 +2342,6 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, enum block_enum block_index, const char *name, const domain_search_flags domain) { - struct compunit_symtab *cust; - const struct blockvector *bv; - const struct block *block; - struct block_symbol result; - symbol_lookup_debug_printf_v ("lookup_symbol_via_quick_fns (%s, %s, %s, %s)", objfile_debug_name (objfile), @@ -2488,27 +2349,36 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, name, domain_name (domain).c_str ()); lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - cust = objfile->lookup_symbol (block_index, lookup_name, domain); - if (cust == NULL) + best_symbol_tracker accum; + auto searcher = [&] (compunit_symtab *symtab) + { + const struct blockvector *bv = symtab->blockvector (); + const struct block *block = bv->block (block_index); + /* If the accumulator finds a best symbol, end the search by + returning false; otherwise keep going by returning true. */ + return !accum.search (symtab, block, lookup_name, domain); + }; + + objfile->search (nullptr, &lookup_name, nullptr, searcher, + block_index == GLOBAL_BLOCK + ? SEARCH_GLOBAL_BLOCK + : SEARCH_STATIC_BLOCK, + domain); + if (accum.best_symtab == nullptr) { symbol_lookup_debug_printf_v ("lookup_symbol_via_quick_fns (...) = NULL"); return {}; } - - bv = cust->blockvector (); - block = bv->block (block_index); - result.symbol = block_lookup_symbol (block, lookup_name, domain); - if (result.symbol == NULL) - error_in_psymtab_expansion (block_index, name, cust); + if (accum.currently_best.symbol == nullptr) + error_in_psymtab_expansion (block_index, name, accum.best_symtab); symbol_lookup_debug_printf_v ("lookup_symbol_via_quick_fns (...) = %s (block %s)", - host_address_to_string (result.symbol), - host_address_to_string (block)); + host_address_to_string (accum.currently_best.symbol), + host_address_to_string (accum.currently_best.block)); - result.block = block; - return result; + return accum.currently_best; } /* See language.h. */ @@ -2608,24 +2478,12 @@ lookup_symbol_in_objfile (struct objfile *objfile, enum block_enum block_index, ? "GLOBAL_BLOCK" : "STATIC_BLOCK", name, domain_name (domain).c_str ()); - result = lookup_symbol_in_objfile_symtabs (objfile, block_index, - name, domain); - if (result.symbol != NULL) - { - symbol_lookup_debug_printf - ("lookup_symbol_in_objfile (...) = %s (in symtabs)", - host_address_to_string (result.symbol)); - return result; - } - result = lookup_symbol_via_quick_fns (objfile, block_index, name, domain); - symbol_lookup_debug_printf ("lookup_symbol_in_objfile (...) = %s%s", + symbol_lookup_debug_printf ("lookup_symbol_in_objfile (...) = %s", result.symbol != NULL ? host_address_to_string (result.symbol) - : "NULL", - result.symbol != NULL ? " (via quick fns)" - : ""); + : "NULL"); return result; } @@ -2658,13 +2516,10 @@ lookup_global_or_static_symbol (const char *name, return result; } - enter_symbol_lookup tmp; - /* Do a global search (of global blocks, heh). */ if (result.symbol == NULL) - gdbarch_iterate_over_objfiles_in_search_order - (objfile != NULL ? objfile->arch () : current_inferior ()->arch (), - [&result, block_index, name, domain] (struct objfile *objfile_iter) + current_program_space->iterate_over_objfiles_in_search_order + ([&result, block_index, name, domain] (struct objfile *objfile_iter) { result = lookup_symbol_in_objfile (objfile_iter, block_index, name, domain); @@ -2776,35 +2631,6 @@ basic_lookup_transparent_type_quick (struct objfile *objfile, return sym->type (); } -/* Subroutine of basic_lookup_transparent_type to simplify it. - Look up the non-opaque definition of NAME in BLOCK_INDEX of OBJFILE. - BLOCK_INDEX is either GLOBAL_BLOCK or STATIC_BLOCK. */ - -static struct type * -basic_lookup_transparent_type_1 (struct objfile *objfile, - enum block_enum block_index, - domain_search_flags flags, - const lookup_name_info &name) -{ - const struct blockvector *bv; - const struct block *block; - const struct symbol *sym; - - for (compunit_symtab *cust : objfile->compunits ()) - { - bv = cust->blockvector (); - block = bv->block (block_index); - sym = block_find_symbol (block, name, flags, nullptr); - if (sym != nullptr) - { - gdb_assert (!TYPE_IS_OPAQUE (sym->type ())); - return sym->type (); - } - } - - return NULL; -} - /* The standard implementation of lookup_transparent_type. This code was modeled on lookup_symbol -- the parts not relevant to looking up types were just left out. In particular it's assumed here that @@ -2818,45 +2644,20 @@ basic_lookup_transparent_type (const char *name, domain_search_flags flags) lookup_name_info lookup_name (name, symbol_name_match_type::FULL); - /* Now search all the global symbols. Do the symtab's first, then - check the psymtab's. If a psymtab indicates the existence - of the desired name as a global, then do psymtab-to-symtab - conversion on the fly and return the found symbol. */ - - for (objfile *objfile : current_program_space->objfiles ()) - { - t = basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, - flags, lookup_name); - if (t) - return t; - } - - for (objfile *objfile : current_program_space->objfiles ()) + /* Search all the global symbols. */ + for (objfile &objfile : current_program_space->objfiles ()) { - t = basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, + t = basic_lookup_transparent_type_quick (&objfile, GLOBAL_BLOCK, flags, lookup_name); if (t) return t; } - /* Now search the static file-level symbols. - Not strictly correct, but more useful than an error. - Do the symtab's first, then - check the psymtab's. If a psymtab indicates the existence - of the desired name as a file-level static, then do psymtab-to-symtab - conversion on the fly and return the found symbol. */ - - for (objfile *objfile : current_program_space->objfiles ()) - { - t = basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, - flags, lookup_name); - if (t) - return t; - } - - for (objfile *objfile : current_program_space->objfiles ()) + /* Now search the static file-level symbols. Not strictly correct, + but more useful than an error. */ + for (objfile &objfile : current_program_space->objfiles ()) { - t = basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, + t = basic_lookup_transparent_type_quick (&objfile, STATIC_BLOCK, flags, lookup_name); if (t) return t; @@ -2935,11 +2736,11 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) It also happens for objfiles that have their functions reordered. For these, the symtab we are looking for is not necessarily read in. */ - for (objfile *obj_file : current_program_space->objfiles ()) + for (objfile &obj_file : current_program_space->objfiles ()) { - for (compunit_symtab *cust : obj_file->compunits ()) + for (compunit_symtab &cust : obj_file.compunits ()) { - const struct blockvector *bv = cust->blockvector (); + const struct blockvector *bv = cust.blockvector (); const struct block *global_block = bv->global_block (); CORE_ADDR start = global_block->start (); CORE_ADDR end = global_block->end (); @@ -2952,7 +2753,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) if (bv->map ()->find (pc) == nullptr) continue; - return cust; + return &cust; } CORE_ADDR range = end - start; @@ -2968,8 +2769,8 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) stabs and coff debugging info, we continue on if a psymtab can't be found. */ struct compunit_symtab *result - = obj_file->find_pc_sect_compunit_symtab (msymbol, pc, - section, 0); + = obj_file.find_pc_sect_compunit_symtab (msymbol, pc, + section, 0); if (result != nullptr) return result; @@ -2984,7 +2785,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) const struct block *b = bv->block (b_index); for (struct symbol *sym : block_iterator_range (b)) { - if (matching_obj_sections (sym->obj_section (obj_file), + if (matching_obj_sections (sym->obj_section (&obj_file), section)) { found_sym = sym; @@ -2998,7 +2799,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) } /* Cust is best found so far, save it. */ - best_cust = cust; + best_cust = &cust; best_cust_range = range; } } @@ -3008,10 +2809,10 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) /* Not found in symtabs, search the "quick" symtabs (e.g. psymtabs). */ - for (objfile *objf : current_program_space->objfiles ()) + for (objfile &objf : current_program_space->objfiles ()) { struct compunit_symtab *result - = objf->find_pc_sect_compunit_symtab (msymbol, pc, section, 1); + = objf.find_pc_sect_compunit_symtab (msymbol, pc, section, 1); if (result != NULL) return result; } @@ -3046,7 +2847,7 @@ find_symbol_at_address (CORE_ADDR address) for (struct symbol *sym : block_iterator_range (b)) { - if (sym->aclass () == LOC_STATIC + if (sym->loc_class () == LOC_STATIC && sym->value_address () == addr) return sym; } @@ -3054,15 +2855,15 @@ find_symbol_at_address (CORE_ADDR address) return nullptr; }; - for (objfile *objfile : current_program_space->objfiles ()) + for (objfile &objfile : current_program_space->objfiles ()) { /* If this objfile was read with -readnow, then we need to search the symtabs directly. */ - if ((objfile->flags & OBJF_READNOW) != 0) + if ((objfile.flags & OBJF_READNOW) != 0) { - for (compunit_symtab *symtab : objfile->compunits ()) + for (compunit_symtab &symtab : objfile.compunits ()) { - struct symbol *sym = search_symtab (symtab, address); + struct symbol *sym = search_symtab (&symtab, address); if (sym != nullptr) return sym; } @@ -3070,7 +2871,7 @@ find_symbol_at_address (CORE_ADDR address) else { struct compunit_symtab *symtab - = objfile->find_compunit_symtab_by_address (address); + = objfile.find_compunit_symtab_by_address (address); if (symtab != NULL) { struct symbol *sym = search_symtab (symtab, address); @@ -3497,14 +3298,14 @@ find_line_symtab (symtab *sym_tab, int line, int *index) else best = 0; - for (objfile *objfile : current_program_space->objfiles ()) - objfile->expand_symtabs_with_fullname (symtab_to_fullname (sym_tab)); + for (objfile &objfile : current_program_space->objfiles ()) + objfile.expand_symtabs_with_fullname (symtab_to_fullname (sym_tab)); - for (objfile *objfile : current_program_space->objfiles ()) + for (objfile &objfile : current_program_space->objfiles ()) { - for (compunit_symtab *cu : objfile->compunits ()) + for (compunit_symtab &cu : objfile.compunits ()) { - for (symtab *s : cu->filetabs ()) + for (symtab *s : cu.filetabs ()) { const struct linetable *l; int ind; @@ -3761,11 +3562,10 @@ find_function_start_sal_1 (CORE_ADDR func_addr, obj_section *section, /* See symtab.h. */ symtab_and_line -find_function_start_sal (CORE_ADDR func_addr, obj_section *section, - bool funfirstline) +find_function_start_sal (CORE_ADDR func_addr, bool funfirstline) { symtab_and_line sal - = find_function_start_sal_1 (func_addr, section, funfirstline); + = find_function_start_sal_1 (func_addr, nullptr, funfirstline); /* find_function_start_sal_1 does a linetable search, so it finds the symtab and linenumber, but not a symbol. Fill in the @@ -4318,7 +4118,7 @@ find_function_alias_target (bound_minimal_symbol msymbol) symbol *sym = find_pc_function (func_addr); if (sym != NULL - && sym->aclass () == LOC_BLOCK + && sym->loc_class () == LOC_BLOCK && sym->value_block ()->entry_pc () == func_addr) return sym; @@ -4341,7 +4141,7 @@ operator_chars (const char *p, const char **end) /* Don't get faked out by `operator' being part of a longer identifier. */ - if (isalpha (*p) || *p == '_' || *p == '$' || *p == '\0') + if (c_isalpha (*p) || *p == '_' || *p == '$' || *p == '\0') return *end; /* Allow some whitespace between `operator' and the operator symbol. */ @@ -4350,11 +4150,11 @@ operator_chars (const char *p, const char **end) /* Recognize 'operator TYPENAME'. */ - if (isalpha (*p) || *p == '_' || *p == '$') + if (c_isalpha (*p) || *p == '_' || *p == '$') { const char *q = p + 1; - while (isalnum (*q) || *q == '_' || *q == '$') + while (c_isalnum (*q) || *q == '_' || *q == '$') q++; *end = q; return p; @@ -4499,7 +4299,7 @@ info_sources_filter::matches (const char *fullname) const switch (m_match_type) { case match_on::DIRNAME: - dirname = ldirname (fullname); + dirname = gdb_ldirname (fullname); to_match = dirname.c_str (); break; case match_on::BASENAME: @@ -4702,19 +4502,19 @@ info_sources_worker (struct ui_out *uiout, gdb_assert (group_by_objfile || uiout->is_mi_like_p ()); - for (objfile *objfile : current_program_space->objfiles ()) + for (objfile &objfile : current_program_space->objfiles ()) { if (group_by_objfile) { output_tuple.emplace (uiout, nullptr); - uiout->field_string ("filename", objfile_name (objfile), + uiout->field_string ("filename", objfile_name (&objfile), file_name_style.style ()); uiout->text (":\n"); - bool debug_fully_readin = !objfile->has_unexpanded_symtabs (); + bool debug_fully_readin = !objfile.has_unexpanded_symtabs (); if (uiout->is_mi_like_p ()) { const char *debug_info_state; - if (objfile_has_symbols (objfile)) + if (objfile.has_symbols ()) { if (debug_fully_readin) debug_info_state = "fully-read"; @@ -4730,16 +4530,16 @@ info_sources_worker (struct ui_out *uiout, if (!debug_fully_readin) uiout->text ("(Full debug information has not yet been read " "for this file.)\n"); - if (!objfile_has_symbols (objfile)) + if (!objfile.has_symbols ()) uiout->text ("(Objfile has no debug information.)\n"); uiout->text ("\n"); } sources_list.emplace (uiout, "sources"); } - for (compunit_symtab *cu : objfile->compunits ()) + for (compunit_symtab &cu : objfile.compunits ()) { - for (symtab *s : cu->filetabs ()) + for (symtab *s : cu.filetabs ()) { const char *file = symtab_to_filename_for_display (s); const char *fullname = symtab_to_fullname (s); @@ -4749,7 +4549,7 @@ info_sources_worker (struct ui_out *uiout, if (group_by_objfile) { - objfile->map_symbol_filenames (data, true /* need_fullname */); + objfile.map_symbol_filenames (data, true /* need_fullname */); if (data.printed_filename_p ()) uiout->text ("\n\n"); data.reset_output (); @@ -4761,7 +4561,8 @@ info_sources_worker (struct ui_out *uiout, if (!group_by_objfile) { data.reset_output (); - map_symbol_filenames (data, true /*need_fullname*/); + current_program_space->map_symbol_filenames (data, + true /*need_fullname*/); } } @@ -4910,11 +4711,11 @@ global_symbol_searcher::expand_symtabs { return file_matches (filename, m_filenames, basenames); }; - expand_symtabs_file_matcher file_matcher = nullptr; + search_symtabs_file_matcher file_matcher = nullptr; if (!m_filenames.empty ()) file_matcher = do_file_match; - objfile->expand_symtabs_matching + objfile->search (file_matcher, &lookup_name_info::match_any (), [&] (const char *symname) @@ -4989,9 +4790,9 @@ global_symbol_searcher::add_matching_symbols domain_search_flags kind = m_kind; /* Add matching symbols (if not already present). */ - for (compunit_symtab *cust : objfile->compunits ()) + for (compunit_symtab &cust : objfile->compunits ()) { - const struct blockvector *bv = cust->blockvector (); + const struct blockvector *bv = cust.blockvector (); for (block_enum block : { GLOBAL_BLOCK, STATIC_BLOCK }) { @@ -5029,12 +4830,12 @@ global_symbol_searcher::add_matching_symbols if ((kind & SEARCH_VAR_DOMAIN) != 0) { - if (sym->aclass () == LOC_UNRESOLVED + if (sym->loc_class () == LOC_UNRESOLVED /* LOC_CONST can be used for more than just enums, e.g., c++ static const members. We only want to skip enums here. */ - || (sym->aclass () == LOC_CONST + || (sym->loc_class () == LOC_CONST && (sym->type ()->code () == TYPE_CODE_ENUM))) continue; } @@ -5128,7 +4929,7 @@ global_symbol_searcher::search () const int fix = -1; /* -1 means ok; otherwise number of spaces needed. */ - if (isalpha (*opname) || *opname == '_' || *opname == '$') + if (c_isalpha (*opname) || *opname == '_' || *opname == '$') { /* There should 1 space between 'operator' and 'TYPENAME'. */ if (opname[-1] != ' ' || opname[-2] == ' ') @@ -5165,17 +4966,17 @@ global_symbol_searcher::search () const bool found_msymbol = false; std::set<symbol_search> result_set; - for (objfile *objfile : current_program_space->objfiles ()) + for (objfile &objfile : current_program_space->objfiles ()) { /* Expand symtabs within objfile that possibly contain matching symbols. */ - found_msymbol |= expand_symtabs (objfile, preg); + found_msymbol |= expand_symtabs (&objfile, preg); /* Find matching symbols within OBJFILE and add them in to the RESULT_SET set. Use a set here so that we can easily detect duplicates as we go, and can therefore track how many unique matches we have found so far. */ - if (!add_matching_symbols (objfile, preg, treg, &result_set)) + if (!add_matching_symbols (&objfile, preg, treg, &result_set)) break; } @@ -5194,8 +4995,8 @@ global_symbol_searcher::search () const { gdb_assert ((m_kind & (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN)) != 0); - for (objfile *objfile : current_program_space->objfiles ()) - if (!add_matching_msymbols (objfile, preg, &result)) + for (objfile &objfile : current_program_space->objfiles ()) + if (!add_matching_msymbols (&objfile, preg, &result)) break; } @@ -5242,7 +5043,7 @@ symbol_to_info_string (struct symbol *sym, int block) string_file tmp_stream; type_print (sym->type (), - (sym->aclass () == LOC_TYPEDEF + (sym->loc_class () == LOC_TYPEDEF ? "" : sym->print_name ()), &tmp_stream, 0); @@ -5610,7 +5411,7 @@ rbreak_command (const char *regexp, int from_tty) if (colon && *(colon + 1) != ':') { int colon_index = colon - regexp; - while (colon_index > 0 && isspace (regexp[colon_index - 1])) + while (colon_index > 0 && c_isspace (regexp[colon_index - 1])) --colon_index; file_name = make_unique_xstrndup (regexp, colon_index); @@ -5761,7 +5562,7 @@ completion_list_add_symbol (completion_tracker &tracker, the msymbol name and removes the msymbol name from the completion tracker. */ if (sym->language () == language_cplus - && sym->aclass () == LOC_BLOCK) + && sym->loc_class () == LOC_BLOCK) { /* The call to canonicalize returns the empty string if the input string is already in canonical form, thanks to this we don't @@ -5862,7 +5663,7 @@ language_search_unquoted_string (const char *text, const char *p) { for (; p > text; --p) { - if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0') + if (c_isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0') continue; else { @@ -5882,7 +5683,7 @@ language_search_unquoted_string (const char *text, const char *p) Unfortunately we have to find it now to decide. */ while (t > text) - if (isalnum (t[-1]) || t[-1] == '_' || + if (c_isalnum (t[-1]) || t[-1] == '_' || t[-1] == ' ' || t[-1] == ':' || t[-1] == '(' || t[-1] == ')') --t; @@ -5906,7 +5707,7 @@ completion_list_add_fields (completion_tracker &tracker, const lookup_name_info &lookup_name, const char *text, const char *word) { - if (sym->aclass () == LOC_TYPEDEF) + if (sym->loc_class () == LOC_TYPEDEF) { struct type *t = sym->type (); enum type_code c = t->code (); @@ -5958,7 +5759,7 @@ symbol_is_function_or_method (minimal_symbol *msymbol) bound_minimal_symbol find_gnu_ifunc (const symbol *sym) { - if (sym->aclass () != LOC_BLOCK) + if (sym->loc_class () != LOC_BLOCK) return {}; lookup_name_info lookup_name (sym->search_name (), @@ -6090,7 +5891,7 @@ default_collect_symbol_completion_matches_break_on which are in symbols. */ while (p > text) { - if (isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0' + if (c_isalnum (p[-1]) || p[-1] == '_' || p[-1] == '\0' || p[-1] == ':' || strchr (break_on, p[-1]) != NULL) --p; else @@ -6109,9 +5910,9 @@ default_collect_symbol_completion_matches_break_on if (code == TYPE_CODE_UNDEF) { - for (objfile *objfile : current_program_space->objfiles ()) + for (objfile &objfile : current_program_space->objfiles ()) { - for (minimal_symbol *msymbol : objfile->msymbols ()) + for (minimal_symbol *msymbol : objfile.msymbols ()) { QUIT; @@ -6128,27 +5929,22 @@ default_collect_symbol_completion_matches_break_on } /* Add completions for all currently loaded symbol tables. */ - for (objfile *objfile : current_program_space->objfiles ()) - { - for (compunit_symtab *cust : objfile->compunits ()) - add_symtab_completions (cust, tracker, mode, lookup_name, - sym_text, word, code); - } - - /* Look through the partial symtabs for all symbols which begin by - matching SYM_TEXT. Expand all CUs that you find to the list. */ - expand_symtabs_matching (NULL, - lookup_name, - NULL, - [&] (compunit_symtab *symtab) /* expansion notify */ - { - add_symtab_completions (symtab, - tracker, mode, lookup_name, - sym_text, word, code); - return true; - }, - SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, - SEARCH_ALL_DOMAINS); + for (objfile &objfile : current_program_space->objfiles ()) + { + /* Look through the partial symtabs for all symbols which begin by + matching SYM_TEXT. Expand all CUs that you find to the list. */ + objfile.search + (nullptr, &lookup_name, nullptr, + [&] (compunit_symtab *symtab) + { + add_symtab_completions (symtab, + tracker, mode, lookup_name, + sym_text, word, code); + return true; + }, + SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, + SEARCH_ALL_DOMAINS); + } /* Search upwards from currently selected frame (so that we can complete on local vars). Also catch fields of types defined in @@ -6206,8 +6002,6 @@ default_collect_symbol_completion_matches_break_on if (current_language->macro_expansion () == macro_expansion_c && code == TYPE_CODE_UNDEF) { - gdb::unique_xmalloc_ptr<struct macro_scope> scope; - /* This adds a macro's name to the current completion list. */ auto add_macro_name = [&] (const char *macro_name, const macro_definition *, @@ -6225,10 +6019,9 @@ default_collect_symbol_completion_matches_break_on resulting expression will be evaluated at "file:line" -- but at there does not seem to be a way to detect this at completion time. */ - scope = default_macro_scope (); - if (scope) - macro_for_each_in_scope (scope->file, scope->line, - add_macro_name); + macro_scope scope = default_macro_scope (); + if (scope.is_valid ()) + macro_for_each_in_scope (scope.file, scope.line, add_macro_name); /* User-defined macros are always visible. */ macro_for_each (macro_user_macros, add_macro_name); @@ -6413,7 +6206,7 @@ add_partial_filename_data::operator() (const char *filename, program. */ completion_list -make_source_files_completion_list (const char *text, const char *word) +make_source_files_completion_list (const char *text) { size_t text_len = strlen (text); completion_list list; @@ -6426,11 +6219,11 @@ make_source_files_completion_list (const char *text, const char *word) filename_seen_cache filenames_seen; - for (objfile *objfile : current_program_space->objfiles ()) + for (objfile &objfile : current_program_space->objfiles ()) { - for (compunit_symtab *cu : objfile->compunits ()) + for (compunit_symtab &cu : objfile.compunits ()) { - for (symtab *s : cu->filetabs ()) + for (symtab *s : cu.filetabs ()) { if (not_interesting_fname (s->filename)) continue; @@ -6439,7 +6232,7 @@ make_source_files_completion_list (const char *text, const char *word) { /* This file matches for a completion; add it to the current list of matches. */ - add_filename_to_list (s->filename, text, word, &list); + add_filename_to_list (s->filename, text, text, &list); } else { @@ -6451,7 +6244,7 @@ make_source_files_completion_list (const char *text, const char *word) if (base_name != s->filename && !filenames_seen.seen (base_name) && filename_ncmp (base_name, text, text_len) == 0) - add_filename_to_list (base_name, text, word, &list); + add_filename_to_list (base_name, text, text, &list); } } } @@ -6459,10 +6252,10 @@ make_source_files_completion_list (const char *text, const char *word) datum.filename_seen_cache = &filenames_seen; datum.text = text; - datum.word = word; + datum.word = text; datum.text_len = text_len; datum.list = &list; - map_symbol_filenames (datum, false /*need_fullname*/); + current_program_space->map_symbol_filenames (datum, false /*need_fullname*/); return list; } @@ -6524,15 +6317,15 @@ find_main_name (void) relies on the order of objfile creation -- which still isn't guaranteed to get the correct answer, but is just probably more accurate. */ - for (objfile *objfile : current_program_space->objfiles ()) + for (objfile &objfile : current_program_space->objfiles ()) { - objfile->compute_main_name (); + objfile.compute_main_name (); - if (objfile->per_bfd->name_of_main != NULL) + if (objfile.per_bfd->name_of_main != NULL) { set_main_name (pspace, - objfile->per_bfd->name_of_main, - objfile->per_bfd->language_of_main); + objfile.per_bfd->name_of_main, + objfile.per_bfd->language_of_main); return; } } @@ -6586,9 +6379,8 @@ find_main_name (void) /* Try to find language for main in psymtabs. */ bool symbol_found_p = false; - gdbarch_iterate_over_objfiles_in_search_order - (current_inferior ()->arch (), - [&symbol_found_p, pspace] (objfile *obj) + current_program_space->iterate_over_objfiles_in_search_order + ([&symbol_found_p, pspace] (objfile *obj) { language lang = obj->lookup_global_symbol_language ("main", @@ -6640,13 +6432,13 @@ main_language (void) /* The next index to hand out in response to a registration request. */ -static int next_aclass_value = LOC_FINAL_VALUE; +static int next_loc_class_value = LOC_FINAL_VALUE; -/* The maximum number of "aclass" registrations we support. This is +/* The maximum number of "loc_class" registrations we support. This is constant for convenience. */ #define MAX_SYMBOL_IMPLS (LOC_FINAL_VALUE + 11) -/* The objects representing the various "aclass" values. The elements +/* The objects representing the various "loc_class" values. The elements from 0 up to LOC_FINAL_VALUE-1 represent themselves, and subsequent elements are those registered at gdb initialization time. */ @@ -6659,22 +6451,22 @@ gdb::array_view<const struct symbol_impl> symbol_impls (symbol_impl); /* Make sure we saved enough room in struct symbol. */ -static_assert (MAX_SYMBOL_IMPLS <= (1 << SYMBOL_ACLASS_BITS)); +static_assert (MAX_SYMBOL_IMPLS <= (1 << SYMBOL_LOC_CLASS_BITS)); -/* Register a computed symbol type. ACLASS must be LOC_COMPUTED. OPS +/* Register a computed symbol type. LOC_CLASS must be LOC_COMPUTED. OPS is the ops vector associated with this index. This returns the new - index, which should be used as the aclass_index field for symbols + index, which should be used as the loc_class_index field for symbols of this type. */ int -register_symbol_computed_impl (enum address_class aclass, +register_symbol_computed_impl (location_class loc_class, const struct symbol_computed_ops *ops) { - int result = next_aclass_value++; + int result = next_loc_class_value++; - gdb_assert (aclass == LOC_COMPUTED); + gdb_assert (loc_class == LOC_COMPUTED); gdb_assert (result < MAX_SYMBOL_IMPLS); - symbol_impl[result].aclass = aclass; + symbol_impl[result].loc_class = loc_class; symbol_impl[result].ops_computed = ops; /* Sanity check OPS. */ @@ -6687,20 +6479,20 @@ register_symbol_computed_impl (enum address_class aclass, return result; } -/* Register a function with frame base type. ACLASS must be LOC_BLOCK. +/* Register a function with frame base type. LOC_CLASS must be LOC_BLOCK. OPS is the ops vector associated with this index. This returns the - new index, which should be used as the aclass_index field for symbols + new index, which should be used as the loc_class_index field for symbols of this type. */ int -register_symbol_block_impl (enum address_class aclass, +register_symbol_block_impl (location_class loc_class, const struct symbol_block_ops *ops) { - int result = next_aclass_value++; + int result = next_loc_class_value++; - gdb_assert (aclass == LOC_BLOCK); + gdb_assert (loc_class == LOC_BLOCK); gdb_assert (result < MAX_SYMBOL_IMPLS); - symbol_impl[result].aclass = aclass; + symbol_impl[result].loc_class = loc_class; symbol_impl[result].ops_block = ops; /* Sanity check OPS. */ @@ -6711,35 +6503,33 @@ register_symbol_block_impl (enum address_class aclass, return result; } -/* Register a register symbol type. ACLASS must be LOC_REGISTER or +/* Register a register symbol type. LOC_CLASS must be LOC_REGISTER or LOC_REGPARM_ADDR. OPS is the register ops vector associated with this index. This returns the new index, which should be used as - the aclass_index field for symbols of this type. */ + the loc_class_index field for symbols of this type. */ int -register_symbol_register_impl (enum address_class aclass, +register_symbol_register_impl (location_class loc_class, const struct symbol_register_ops *ops) { - int result = next_aclass_value++; + int result = next_loc_class_value++; - gdb_assert (aclass == LOC_REGISTER || aclass == LOC_REGPARM_ADDR); + gdb_assert (loc_class == LOC_REGISTER || loc_class == LOC_REGPARM_ADDR); gdb_assert (result < MAX_SYMBOL_IMPLS); - symbol_impl[result].aclass = aclass; + symbol_impl[result].loc_class = loc_class; symbol_impl[result].ops_register = ops; return result; } /* Initialize elements of 'symbol_impl' for the constants in enum - address_class. */ + location_class. */ static void initialize_ordinary_address_classes (void) { - int i; - - for (i = 0; i < LOC_FINAL_VALUE; ++i) - symbol_impl[i].aclass = (enum address_class) i; + for (int i = 0; i < LOC_FINAL_VALUE; ++i) + symbol_impl[i].loc_class = static_cast<location_class> (i); } @@ -6787,7 +6577,7 @@ CORE_ADDR symbol::get_maybe_copied_address () const { gdb_assert (this->maybe_copied); - gdb_assert (this->aclass () == LOC_STATIC); + gdb_assert (this->loc_class () == LOC_STATIC); const char *linkage_name = this->linkage_name (); bound_minimal_symbol minsym @@ -6997,11 +6787,8 @@ info_module_subcommand (bool quiet, const char *module_regexp, const char *last_filename = ""; const symbol *last_module_symbol = nullptr; - for (const module_symbol_search &ms : module_symbols) + for (const auto &[p, q] : module_symbols) { - const symbol_search &p = ms.first; - const symbol_search &q = ms.second; - gdb_assert (q.symbol != nullptr); if (last_module_symbol != p.symbol) @@ -7120,9 +6907,7 @@ info_module_var_func_command_completer (struct cmd_list_element *ignore, -void _initialize_symtab (); -void -_initialize_symtab () +INIT_GDB_FILE (symtab) { cmd_list_element *c; |