X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fsymtab.c;h=719e5b2ee9a2f7bf472487f231971c21af151b2b;hb=cd215b2eb74c179d936a3b28577753a08de1cf83;hp=370c8b45b3268bc1945ddc09dffa2ca77a6fbdda;hpb=2030c079717475f5b6fad837bb81758891f3b802;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/symtab.c b/gdb/symtab.c index 370c8b45b3..719e5b2ee9 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -41,6 +41,7 @@ #include "p-lang.h" #include "addrmap.h" #include "cli/cli-utils.h" +#include "cli/cli-style.h" #include "fnmatch.h" #include "hashtab.h" #include "typeprint.h" @@ -63,11 +64,11 @@ #include "parser-defs.h" #include "completer.h" #include "progspace-and-thread.h" -#include "common/gdb_optional.h" +#include "gdbsupport/gdb_optional.h" #include "filename-seen-cache.h" #include "arch-utils.h" #include -#include "common/pathstuff.h" +#include "gdbsupport/pathstuff.h" /* Forward declarations for local functions. */ @@ -94,29 +95,29 @@ static struct block_symbol lookup_symbol_in_objfile (struct objfile *objfile, int block_index, const char *name, const domain_enum domain); -/* See symtab.h. */ -const struct block_symbol null_block_symbol = { NULL, NULL }; - -/* 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 { + main_info () = default; + + ~main_info () + { + xfree (name_of_main); + } + /* Name of "main". */ - char *name_of_main; + char *name_of_main = nullptr; /* Language of "main". */ - enum language language_of_main; + enum language language_of_main = language_unknown; }; -/* Program space key for finding its symbol cache. */ +/* Program space key for finding name and language of "main". */ -static const struct program_space_data *symbol_cache_key; +static const program_space_key main_progspace_key; /* The default symbol cache size. There is no extra cpu cost for large N (except when flushing the cache, @@ -209,10 +210,22 @@ struct block_symbol_cache struct symbol_cache { - struct block_symbol_cache *global_symbols; - struct block_symbol_cache *static_symbols; + symbol_cache () = default; + + ~symbol_cache () + { + xfree (global_symbols); + xfree (static_symbols); + } + + struct block_symbol_cache *global_symbols = nullptr; + struct block_symbol_cache *static_symbols = nullptr; }; +/* Program space key for finding its symbol cache. */ + +static const program_space_key symbol_cache_key; + /* When non-zero, print debugging messages related to symtab creation. */ unsigned int symtab_create_debug = 0; @@ -311,6 +324,31 @@ compunit_language (const struct compunit_symtab *cust) return SYMTAB_LANGUAGE (symtab); } +/* See symtab.h. */ + +bool +minimal_symbol::data_p () const +{ + return type == mst_data + || type == mst_bss + || type == mst_abs + || type == mst_file_data + || type == mst_file_bss; +} + +/* See symtab.h. */ + +bool +minimal_symbol::text_p () const +{ + return type == mst_text + || type == mst_text_gnu_ifunc + || type == mst_data_gnu_ifunc + || type == mst_slot_got_plt + || type == mst_solib_trampoline + || type == mst_file_text; +} + /* 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 @@ -675,6 +713,7 @@ symbol_set_language (struct general_symbol_info *gsymbol, struct demangled_name_entry { const char *mangled; + ENUM_BITFIELD(language) language : LANGUAGE_BITS; char demangled[1]; }; @@ -714,9 +753,9 @@ create_demangled_names_hash (struct objfile_per_bfd_storage *per_bfd) Choosing a much larger table size wastes memory, and saves only about 1% in symbol reading. */ - per_bfd->demangled_names_hash = htab_create_alloc + per_bfd->demangled_names_hash.reset (htab_create_alloc (256, hash_demangled_name_entry, eq_demangled_name_entry, - NULL, xcalloc, xfree); + NULL, xcalloc, xfree)); } /* Try to determine the demangled name for a symbol, based on the @@ -815,14 +854,9 @@ symbol_set_names (struct general_symbol_info *gsymbol, else linkage_name_copy = linkage_name; - /* Set the symbol language. */ - char *demangled_name_ptr - = symbol_find_demangled_name (gsymbol, linkage_name_copy); - gdb::unique_xmalloc_ptr demangled_name (demangled_name_ptr); - entry.mangled = linkage_name_copy; slot = ((struct demangled_name_entry **) - htab_find_slot (per_bfd->demangled_names_hash, + htab_find_slot (per_bfd->demangled_names_hash.get (), &entry, INSERT)); /* If this name is not in the hash table, add it. */ @@ -832,6 +866,9 @@ symbol_set_names (struct general_symbol_info *gsymbol, || (gsymbol->language == language_go && (*slot)->demangled[0] == '\0')) { + char *demangled_name_ptr + = symbol_find_demangled_name (gsymbol, linkage_name_copy); + gdb::unique_xmalloc_ptr demangled_name (demangled_name_ptr); int demangled_len = demangled_name ? strlen (demangled_name.get ()) : 0; /* Suppose we have demangled_name==NULL, copy_name==0, and @@ -868,12 +905,16 @@ symbol_set_names (struct general_symbol_info *gsymbol, strcpy (mangled_ptr, linkage_name_copy); (*slot)->mangled = mangled_ptr; } + (*slot)->language = gsymbol->language; if (demangled_name != NULL) - strcpy ((*slot)->demangled, demangled_name.get()); + strcpy ((*slot)->demangled, demangled_name.get ()); else (*slot)->demangled[0] = '\0'; } + else if (gsymbol->language == language_unknown + || gsymbol->language == language_auto) + gsymbol->language = (*slot)->language; gsymbol->name = (*slot)->mangled; if ((*slot)->demangled[0] != '\0') @@ -1039,12 +1080,7 @@ expand_symtab_containing_pc (CORE_ADDR pc, struct obj_section *section) 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); - if (msymbol.minsym - && (MSYMBOL_TYPE (msymbol.minsym) == mst_data - || MSYMBOL_TYPE (msymbol.minsym) == mst_bss - || MSYMBOL_TYPE (msymbol.minsym) == mst_abs - || MSYMBOL_TYPE (msymbol.minsym) == mst_file_data - || MSYMBOL_TYPE (msymbol.minsym) == mst_file_bss)) + if (msymbol.minsym && msymbol.minsym->data_p ()) return; for (objfile *objfile : current_program_space->objfiles ()) @@ -1201,57 +1237,23 @@ resize_symbol_cache (struct symbol_cache *cache, unsigned int new_size) } } -/* Make a symbol cache of size SIZE. */ - -static struct symbol_cache * -make_symbol_cache (unsigned int size) -{ - struct symbol_cache *cache; - - cache = XCNEW (struct symbol_cache); - resize_symbol_cache (cache, symbol_cache_size); - return cache; -} - -/* Free the space used by CACHE. */ - -static void -free_symbol_cache (struct symbol_cache *cache) -{ - xfree (cache->global_symbols); - xfree (cache->static_symbols); - xfree (cache); -} - /* Return the symbol cache of PSPACE. Create one if it doesn't exist yet. */ static struct symbol_cache * get_symbol_cache (struct program_space *pspace) { - struct symbol_cache *cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + struct symbol_cache *cache = symbol_cache_key.get (pspace); if (cache == NULL) { - cache = make_symbol_cache (symbol_cache_size); - set_program_space_data (pspace, symbol_cache_key, cache); + cache = symbol_cache_key.emplace (pspace); + resize_symbol_cache (cache, symbol_cache_size); } return cache; } -/* Delete the symbol cache of PSPACE. - Called when PSPACE is destroyed. */ - -static void -symbol_cache_cleanup (struct program_space *pspace, void *data) -{ - struct symbol_cache *cache = (struct symbol_cache *) data; - - free_symbol_cache (cache); -} - /* Set the size of the symbol cache in all program spaces. */ static void @@ -1261,8 +1263,7 @@ set_symbol_cache_size (unsigned int new_size) ALL_PSPACES (pspace) { - struct symbol_cache *cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + struct symbol_cache *cache = symbol_cache_key.get (pspace); /* The pspace could have been created but not have a cache yet. */ if (cache != NULL) @@ -1318,7 +1319,7 @@ symbol_cache_lookup (struct symbol_cache *cache, { *bsc_ptr = NULL; *slot_ptr = NULL; - return (struct block_symbol) {NULL, NULL}; + return {}; } hash = hash_symbol_entry (objfile_context, name, domain); @@ -1352,7 +1353,7 @@ symbol_cache_lookup (struct symbol_cache *cache, name, domain_name (domain)); } ++bsc->misses; - return (struct block_symbol) {NULL, NULL}; + return {}; } /* Clear out SLOT. */ @@ -1418,8 +1419,7 @@ symbol_cache_mark_not_found (struct block_symbol_cache *bsc, static void symbol_cache_flush (struct program_space *pspace) { - struct symbol_cache *cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + struct symbol_cache *cache = symbol_cache_key.get (pspace); int pass; if (cache == NULL) @@ -1533,8 +1533,7 @@ maintenance_print_symbol_cache (const char *args, int from_tty) : "(no object file)"); /* If the cache hasn't been created yet, avoid creating one. */ - cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + cache = symbol_cache_key.get (pspace); if (cache == NULL) printf_filtered (" \n"); else @@ -1605,8 +1604,7 @@ maintenance_print_symbol_cache_statistics (const char *args, int from_tty) : "(no object file)"); /* If the cache hasn't been created yet, avoid creating one. */ - cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + cache = symbol_cache_key.get (pspace); if (cache == NULL) printf_filtered (" empty, no stats available\n"); else @@ -1917,7 +1915,7 @@ lookup_language_this (const struct language_defn *lang, const struct block *block) { if (lang->la_name_of_this == NULL || block == NULL) - return (struct block_symbol) {NULL, NULL}; + return {}; if (symbol_lookup_debug > 1) { @@ -1954,7 +1952,7 @@ lookup_language_this (const struct language_defn *lang, if (symbol_lookup_debug > 1) fprintf_unfiltered (gdb_stdlog, " = NULL\n"); - return (struct block_symbol) {NULL, NULL}; + return {}; } /* Given TYPE, a structure/union, @@ -2081,7 +2079,7 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type, fprintf_unfiltered (gdb_stdlog, "lookup_symbol_aux (...) = NULL\n"); } - return (struct block_symbol) {NULL, NULL}; + return {}; } } } @@ -2131,7 +2129,7 @@ lookup_local_symbol (const char *name, /* Check if either no block is specified or it's a global block. */ if (static_block == NULL) - return (struct block_symbol) {NULL, NULL}; + return {}; while (block != static_block) { @@ -2156,7 +2154,7 @@ lookup_local_symbol (const char *name, /* We've reached the end of the function without finding a result. */ - return (struct block_symbol) {NULL, NULL}; + return {}; } /* See symtab.h. */ @@ -2171,7 +2169,7 @@ lookup_objfile_from_block (const struct block *block) /* Look through all blockvectors. */ for (objfile *obj : current_program_space->objfiles ()) { - for (compunit_symtab *cust : objfile_compunits (obj)) + for (compunit_symtab *cust : obj->compunits ()) if (block == BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK)) { @@ -2228,11 +2226,7 @@ lookup_global_symbol_from_objfile (struct objfile *main_objfile, const char *name, const domain_enum domain) { - struct objfile *objfile; - - for (objfile = main_objfile; - objfile; - objfile = objfile_separate_debug_iterate (main_objfile, objfile)) + for (objfile *objfile : main_objfile->separate_debug_objfiles ()) { struct block_symbol result = lookup_symbol_in_objfile (objfile, GLOBAL_BLOCK, name, domain); @@ -2241,7 +2235,7 @@ lookup_global_symbol_from_objfile (struct objfile *main_objfile, return result; } - return (struct block_symbol) {NULL, NULL}; + return {}; } /* Check to see if the symbol is defined in one of the OBJFILE's @@ -2265,7 +2259,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index, name, domain_name (domain)); } - for (compunit_symtab *cust : objfile_compunits (objfile)) + for (compunit_symtab *cust : objfile->compunits ()) { const struct blockvector *bv; const struct block *block; @@ -2291,7 +2285,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index, if (symbol_lookup_debug > 1) fprintf_unfiltered (gdb_stdlog, " = NULL\n"); - return (struct block_symbol) {NULL, NULL}; + return {}; } /* Wrapper around lookup_symbol_in_objfile_symtabs for search_symbols. @@ -2309,7 +2303,7 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile, domain_enum domain) { enum language lang = current_language->la_language; - struct objfile *main_objfile, *cur_objfile; + struct objfile *main_objfile; demangle_result_storage storage; const char *modified_name = demangle_for_lookup (linkage_name, lang, storage); @@ -2319,9 +2313,7 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile, else main_objfile = objfile; - for (cur_objfile = main_objfile; - cur_objfile; - cur_objfile = objfile_separate_debug_iterate (main_objfile, cur_objfile)) + for (::objfile *cur_objfile : main_objfile->separate_debug_objfiles ()) { struct block_symbol result; @@ -2334,7 +2326,7 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile, return result; } - return (struct block_symbol) {NULL, NULL}; + return {}; } /* A helper function that throws an exception when a symbol was found @@ -2367,7 +2359,7 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, int block_index, struct block_symbol result; if (!objfile->sf) - return (struct block_symbol) {NULL, NULL}; + return {}; if (symbol_lookup_debug > 1) { @@ -2387,7 +2379,7 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, int block_index, fprintf_unfiltered (gdb_stdlog, "lookup_symbol_via_quick_fns (...) = NULL\n"); } - return (struct block_symbol) {NULL, NULL}; + return {}; } bv = COMPUNIT_BLOCKVECTOR (cust); @@ -2491,7 +2483,7 @@ lookup_symbol_in_static_block (const char *name, struct symbol *sym; if (static_block == NULL) - return (struct block_symbol) {NULL, NULL}; + return {}; if (symbol_lookup_debug) { @@ -2584,7 +2576,7 @@ lookup_static_symbol (const char *name, const domain_enum domain) if (result.symbol != NULL) { if (SYMBOL_LOOKUP_FAILED_P (result)) - return (struct block_symbol) {NULL, NULL}; + return {}; return result; } @@ -2602,7 +2594,7 @@ lookup_static_symbol (const char *name, const domain_enum domain) /* Still pass NULL for OBJFILE_CONTEXT here. */ symbol_cache_mark_not_found (bsc, slot, NULL, name, domain); - return (struct block_symbol) {NULL, NULL}; + return {}; } /* Private data to be used with lookup_symbol_global_iterator_cb. */ @@ -2666,7 +2658,7 @@ lookup_global_symbol (const char *name, if (result.symbol != NULL) { if (SYMBOL_LOOKUP_FAILED_P (result)) - return (struct block_symbol) {NULL, NULL}; + return {}; return result; } @@ -2731,7 +2723,7 @@ basic_lookup_transparent_type_quick (struct objfile *objfile, int block_index, { struct compunit_symtab *cust; const struct blockvector *bv; - struct block *block; + const struct block *block; struct symbol *sym; if (!objfile->sf) @@ -2763,7 +2755,7 @@ basic_lookup_transparent_type_1 (struct objfile *objfile, int block_index, const struct block *block; const struct symbol *sym; - for (compunit_symtab *cust : objfile_compunits (objfile)) + for (compunit_symtab *cust : objfile->compunits ()) { bv = COMPUNIT_BLOCKVECTOR (cust); block = BLOCKVECTOR_BLOCK (bv, block_index); @@ -2879,12 +2871,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) 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); - if (msymbol.minsym - && (MSYMBOL_TYPE (msymbol.minsym) == mst_data - || MSYMBOL_TYPE (msymbol.minsym) == mst_bss - || MSYMBOL_TYPE (msymbol.minsym) == mst_abs - || MSYMBOL_TYPE (msymbol.minsym) == mst_file_data - || MSYMBOL_TYPE (msymbol.minsym) == mst_file_bss)) + if (msymbol.minsym && msymbol.minsym->data_p ()) return NULL; /* Search all symtabs for the one whose file contains our address, and which @@ -2904,9 +2891,9 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) for (objfile *obj_file : current_program_space->objfiles ()) { - for (compunit_symtab *cust : objfile_compunits (obj_file)) + for (compunit_symtab *cust : obj_file->compunits ()) { - struct block *b; + const struct block *b; const struct blockvector *bv; bv = COMPUNIT_BLOCKVECTOR (cust); @@ -3010,7 +2997,7 @@ find_symbol_at_address (CORE_ADDR address) for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i) { - struct block *b = BLOCKVECTOR_BLOCK (bv, i); + const struct block *b = BLOCKVECTOR_BLOCK (bv, i); struct block_iterator iter; struct symbol *sym; @@ -3360,7 +3347,7 @@ find_line_symtab (struct symtab *sym_tab, int line, for (objfile *objfile : current_program_space->objfiles ()) { - for (compunit_symtab *cu : objfile_compunits (objfile)) + for (compunit_symtab *cu : objfile->compunits ()) { for (symtab *s : compunit_filetabs (cu)) { @@ -3686,8 +3673,10 @@ skip_prologue_using_lineinfo (CORE_ADDR func_addr, struct symtab *symtab) /* Adjust SAL to the first instruction past the function prologue. If the PC was explicitly specified, the SAL is not changed. - If the line number was explicitly specified, at most the SAL's PC - is updated. If SAL is already past the prologue, then do nothing. */ + If the line number was explicitly specified then the SAL can still be + updated, unless the language for SAL is assembler, in which case the SAL + will be left unchanged. + If SAL is already past the prologue, then do nothing. */ void skip_prologue_sal (struct symtab_and_line *sal) @@ -3706,6 +3695,15 @@ skip_prologue_sal (struct symtab_and_line *sal) if (sal->explicit_pc) return; + /* In assembly code, if the user asks for a specific line then we should + not adjust the SAL. The user already has instruction level + visibility in this case, so selecting a line other than one requested + is likely to be the wrong choice. */ + if (sal->symtab != nullptr + && sal->explicit_line + && SYMTAB_LANGUAGE (sal->symtab) == language_asm) + return; + scoped_restore_current_pspace_and_thread restore_pspace_thread; switch_to_program_space_and_thread (sal->pspace); @@ -3825,12 +3823,6 @@ skip_prologue_sal (struct symtab_and_line *sal) sal->pc = pc; sal->section = section; - - /* Unless the explicit_line flag was set, update the SAL line - and symtab to correspond to the modified PC location. */ - if (sal->explicit_line) - return; - sal->symtab = start_sal.symtab; sal->line = start_sal.line; sal->end = start_sal.end; @@ -4168,7 +4160,7 @@ output_source_filename (const char *name, data->first = 0; wrap_here (""); - fputs_filtered (name, gdb_stdout); + fputs_styled (name, file_name_style.style (), gdb_stdout); } /* A callback for map_partial_symbol_filenames. */ @@ -4200,7 +4192,7 @@ info_sources_command (const char *ignore, int from_tty) data.first = 1; for (objfile *objfile : current_program_space->objfiles ()) { - for (compunit_symtab *cu : objfile_compunits (objfile)) + for (compunit_symtab *cu : objfile->compunits ()) { for (symtab *s : compunit_filetabs (cu)) { @@ -4341,7 +4333,7 @@ search_symbols (const char *regexp, enum search_domain kind, int nfiles, const char *files[]) { const struct blockvector *bv; - struct block *b; + const struct block *b; int i = 0; struct block_iterator iter; struct symbol *sym; @@ -4455,7 +4447,7 @@ search_symbols (const char *regexp, enum search_domain kind, { for (objfile *objfile : current_program_space->objfiles ()) { - for (minimal_symbol *msymbol : objfile_msymbols (objfile)) + for (minimal_symbol *msymbol : objfile->msymbols ()) { QUIT; @@ -4492,7 +4484,7 @@ search_symbols (const char *regexp, enum search_domain kind, for (objfile *objfile : current_program_space->objfiles ()) { - for (compunit_symtab *cust : objfile_compunits (objfile)) + for (compunit_symtab *cust : objfile->compunits ()) { bv = COMPUNIT_BLOCKVECTOR (cust); for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) @@ -4558,7 +4550,7 @@ search_symbols (const char *regexp, enum search_domain kind, { for (objfile *objfile : current_program_space->objfiles ()) { - for (minimal_symbol *msymbol : objfile_msymbols (objfile)) + for (minimal_symbol *msymbol : objfile->msymbols ()) { QUIT; @@ -4620,7 +4612,7 @@ print_symbol_info (enum search_domain kind, if (filename_cmp (last, s_filename) != 0) { fputs_filtered ("\nFile ", gdb_stdout); - fputs_filtered (s_filename, gdb_stdout); + fputs_styled (s_filename, file_name_style.style (), gdb_stdout); fputs_filtered (":\n", gdb_stdout); } @@ -4667,8 +4659,15 @@ print_msymbol_info (struct bound_minimal_symbol msymbol) else tmp = hex_string_custom (BMSYMBOL_VALUE_ADDRESS (msymbol), 16); - printf_filtered ("%s %s\n", - tmp, MSYMBOL_PRINT_NAME (msymbol.minsym)); + fputs_styled (tmp, address_style.style (), gdb_stdout); + fputs_filtered (" ", gdb_stdout); + if (msymbol.minsym->text_p ()) + fputs_styled (MSYMBOL_PRINT_NAME (msymbol.minsym), + function_name_style.style (), + gdb_stdout); + else + fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), gdb_stdout); + fputs_filtered ("\n", gdb_stdout); } /* This is the guts of the commands "info functions", "info types", and @@ -4688,6 +4687,9 @@ symtab_symbol_info (bool quiet, gdb_assert (kind <= TYPES_DOMAIN); + if (regexp != nullptr && *regexp == '\0') + regexp = nullptr; + /* Must make sure that if we're interrupted, symbols gets freed. */ std::vector symbols = search_symbols (regexp, kind, t_regexp, 0, NULL); @@ -4699,7 +4701,7 @@ symtab_symbol_info (bool quiet, if (t_regexp != NULL) printf_filtered (_("All %ss matching regular expression \"%s\"" - " with type matching regulation expression \"%s\":\n"), + " with type matching regular expression \"%s\":\n"), classnames[kind], regexp, t_regexp); else printf_filtered (_("All %ss matching regular expression \"%s\":\n"), @@ -4710,7 +4712,7 @@ symtab_symbol_info (bool quiet, if (t_regexp != NULL) printf_filtered (_("All defined %ss" - " with type matching regulation expression \"%s\" :\n"), + " with type matching regular expression \"%s\" :\n"), classnames[kind], t_regexp); else printf_filtered (_("All defined %ss:\n"), classnames[kind]); @@ -4743,47 +4745,28 @@ symtab_symbol_info (bool quiet, } } +/* Implement the 'info variables' command. */ + static void info_variables_command (const char *args, int from_tty) { - std::string regexp; - std::string t_regexp; - bool quiet = false; + info_print_options opts; + extract_info_print_options (&opts, &args); - while (args != NULL - && extract_info_print_args (&args, &quiet, ®exp, &t_regexp)) - ; - - if (args != NULL) - report_unrecognized_option_error ("info variables", args); - - symtab_symbol_info (quiet, - regexp.empty () ? NULL : regexp.c_str (), - VARIABLES_DOMAIN, - t_regexp.empty () ? NULL : t_regexp.c_str (), - from_tty); + symtab_symbol_info (opts.quiet, args, VARIABLES_DOMAIN, + opts.type_regexp, from_tty); } +/* Implement the 'info functions' command. */ static void info_functions_command (const char *args, int from_tty) { - std::string regexp; - std::string t_regexp; - bool quiet = false; - - while (args != NULL - && extract_info_print_args (&args, &quiet, ®exp, &t_regexp)) - ; + info_print_options opts; + extract_info_print_options (&opts, &args); - if (args != NULL) - report_unrecognized_option_error ("info functions", args); - - symtab_symbol_info (quiet, - regexp.empty () ? NULL : regexp.c_str (), - FUNCTIONS_DOMAIN, - t_regexp.empty () ? NULL : t_regexp.c_str (), - from_tty); + symtab_symbol_info (opts.quiet, args, FUNCTIONS_DOMAIN, + opts.type_regexp, from_tty); } @@ -5274,7 +5257,7 @@ default_collect_symbol_completion_matches_break_on { for (objfile *objfile : current_program_space->objfiles ()) { - for (minimal_symbol *msymbol : objfile_msymbols (objfile)) + for (minimal_symbol *msymbol : objfile->msymbols ()) { QUIT; @@ -5293,7 +5276,7 @@ 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 (objfile)) + for (compunit_symtab *cust : objfile->compunits ()) add_symtab_completions (cust, tracker, mode, lookup_name, sym_text, word, code); } @@ -5602,7 +5585,7 @@ make_source_files_completion_list (const char *text, const char *word) for (objfile *objfile : current_program_space->objfiles ()) { - for (compunit_symtab *cu : objfile_compunits (objfile)) + for (compunit_symtab *cu : objfile->compunits ()) { for (symtab *s : compunit_filetabs (cu)) { @@ -5651,9 +5634,7 @@ make_source_files_completion_list (const char *text, const char *word) static struct main_info * get_main_info (void) { - struct main_info *info - = (struct main_info *) program_space_data (current_program_space, - main_progspace_key); + struct main_info *info = main_progspace_key.get (current_program_space); if (info == NULL) { @@ -5663,28 +5644,12 @@ get_main_info (void) 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); + info = main_progspace_key.emplace (current_program_space); } 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) -{ - struct main_info *info = (struct main_info *) data; - - if (info != NULL) - xfree (info->name_of_main); - xfree (info); -} - static void set_main_name (const char *name, enum language lang) { @@ -5776,8 +5741,10 @@ find_main_name (void) set_main_name ("main", language_unknown); } -char * -main_name (void) +/* See symtab.h. */ + +const char * +main_name () { struct main_info *info = get_main_info (); @@ -6032,34 +5999,35 @@ symbol_set_symtab (struct symbol *symbol, struct symtab *symtab) void _initialize_symtab (void) { - initialize_ordinary_address_classes (); - - main_progspace_key - = register_program_space_data_with_cleanup (NULL, main_info_cleanup); + cmd_list_element *c; - symbol_cache_key - = register_program_space_data_with_cleanup (NULL, symbol_cache_cleanup); + initialize_ordinary_address_classes (); - add_info ("variables", info_variables_command, - info_print_args_help (_("\ + c = add_info ("variables", info_variables_command, + info_print_args_help (_("\ All global and static variable names or those matching REGEXPs.\n\ Usage: info variables [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\ Prints the global and static variables.\n"), _("global and static variables"))); + set_cmd_completer_handle_brkchars (c, info_print_command_completer); if (dbx_commands) - add_com ("whereis", class_info, info_variables_command, - info_print_args_help (_("\ + { + c = add_com ("whereis", class_info, info_variables_command, + info_print_args_help (_("\ All global and static variable names, or those matching REGEXPs.\n\ Usage: whereis [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\ Prints the global and static variables.\n"), _("global and static variables"))); + set_cmd_completer_handle_brkchars (c, info_print_command_completer); + } - add_info ("functions", info_functions_command, - info_print_args_help (_("\ + c = add_info ("functions", info_functions_command, + info_print_args_help (_("\ All function names or those matching REGEXPs.\n\ Usage: info functions [-q] [-t TYPEREGEXP] [NAMEREGEXP]\n\ Prints the functions.\n"), _("functions"))); + set_cmd_completer_handle_brkchars (c, info_print_command_completer); /* FIXME: This command has at least the following problems: 1. It prints builtin types (in a very strange and confusing fashion).