the original value from here. */
static unsigned int symbol_cache_size = DEFAULT_SYMBOL_CACHE_SIZE;
-/* Non-zero if a file may be known by two different basenames.
+/* True if a file may be known by two different basenames.
This is the uncommon case, and significantly slows down gdb.
Default set to "off" to not slow down the common case. */
-int basenames_may_differ = 0;
+bool basenames_may_differ = false;
/* Allow the user to configure the debugger behavior with respect
to multiple-choice menus when more than one symbol matches during
void
symbol_set_names (struct general_symbol_info *gsymbol,
- const char *linkage_name, int len, int copy_name,
+ const char *linkage_name, int len, bool copy_name,
struct objfile_per_bfd_storage *per_bfd)
{
struct demangled_name_entry **slot;
have the same size, address, and name. We can't compare section indexes,
which would be more reliable, because some sections may have been
stripped. */
- if (bfd_get_section_size (first) != bfd_get_section_size (second))
+ if (bfd_section_size (first) != bfd_section_size (second))
return 0;
/* In-memory addresses may start at a different offset, relativize them. */
- if (bfd_get_section_vma (first->owner, first)
- - bfd_get_start_address (first->owner)
- != bfd_get_section_vma (second->owner, second)
- - bfd_get_start_address (second->owner))
+ if (bfd_section_vma (first) - bfd_get_start_address (first->owner)
+ != bfd_section_vma (second) - bfd_get_start_address (second->owner))
return 0;
- if (bfd_get_section_name (first->owner, first) == NULL
- || bfd_get_section_name (second->owner, second) == NULL
- || strcmp (bfd_get_section_name (first->owner, first),
- bfd_get_section_name (second->owner, second)) != 0)
+ if (bfd_section_name (first) == NULL
+ || bfd_section_name (second) == NULL
+ || strcmp (bfd_section_name (first), bfd_section_name (second)) != 0)
return 0;
/* Otherwise check that they are in corresponding objfiles. */
The result is the symbol if found, SYMBOL_LOOKUP_FAILED if a previous lookup
failed (and thus this one will too), or NULL if the symbol is not present
in the cache.
- If the symbol is not present in the cache, then *BSC_PTR and *SLOT_PTR are
- set to the cache and slot of the symbol to save the result of a full lookup
- attempt. */
+ *BSC_PTR and *SLOT_PTR are set to the cache and slot of the symbol, which
+ can be used to save the result of a full lookup attempt. */
static struct block_symbol
symbol_cache_lookup (struct symbol_cache *cache,
hash = hash_symbol_entry (objfile_context, name, domain);
slot = bsc->symbols + hash % bsc->size;
+ *bsc_ptr = bsc;
+ *slot_ptr = slot;
+
if (eq_symbol_entry (slot, objfile_context, name, domain))
{
if (symbol_lookup_debug)
/* Symbol is not present in the cache. */
- *bsc_ptr = bsc;
- *slot_ptr = slot;
-
if (symbol_lookup_debug)
{
fprintf_unfiltered (gdb_stdlog,
return result;
}
-/* See symtab.h. */
-
-struct block_symbol
-lookup_static_symbol (const char *name, const domain_enum domain)
-{
- struct symbol_cache *cache = get_symbol_cache (current_program_space);
- struct block_symbol result;
- struct block_symbol_cache *bsc;
- struct symbol_cache_slot *slot;
-
- /* Lookup in STATIC_BLOCK is not current-objfile-dependent, so just pass
- NULL for OBJFILE_CONTEXT. */
- result = symbol_cache_lookup (cache, NULL, STATIC_BLOCK, name, domain,
- &bsc, &slot);
- if (result.symbol != NULL)
- {
- if (SYMBOL_LOOKUP_FAILED_P (result))
- return {};
- return result;
- }
-
- for (objfile *objfile : current_program_space->objfiles ())
- {
- result = lookup_symbol_in_objfile (objfile, STATIC_BLOCK, name, domain);
- if (result.symbol != NULL)
- {
- /* Still pass NULL for OBJFILE_CONTEXT here. */
- symbol_cache_mark_found (bsc, slot, NULL, result.symbol,
- result.block);
- return result;
- }
- }
-
- /* Still pass NULL for OBJFILE_CONTEXT here. */
- symbol_cache_mark_not_found (bsc, slot, NULL, name, domain);
- return {};
-}
-
/* Private data to be used with lookup_symbol_global_iterator_cb. */
-struct global_sym_lookup_data
+struct global_or_static_sym_lookup_data
{
/* The name of the symbol we are searching for. */
const char *name;
/* The domain to use for our search. */
domain_enum domain;
+ /* The block index in which to search. */
+ enum block_enum block_index;
+
/* The field where the callback should store the symbol if found.
It should be initialized to {NULL, NULL} before the search is started. */
struct block_symbol result;
};
/* A callback function for gdbarch_iterate_over_objfiles_in_search_order.
- It searches by name for a symbol in the GLOBAL_BLOCK of the given
- OBJFILE. The arguments for the search are passed via CB_DATA,
- which in reality is a pointer to struct global_sym_lookup_data. */
+ It searches by name for a symbol in the block given by BLOCK_INDEX of the
+ given OBJFILE. The arguments for the search are passed via CB_DATA, which
+ in reality is a pointer to struct global_or_static_sym_lookup_data. */
static int
-lookup_symbol_global_iterator_cb (struct objfile *objfile,
- void *cb_data)
+lookup_symbol_global_or_static_iterator_cb (struct objfile *objfile,
+ void *cb_data)
{
- struct global_sym_lookup_data *data =
- (struct global_sym_lookup_data *) cb_data;
+ struct global_or_static_sym_lookup_data *data =
+ (struct global_or_static_sym_lookup_data *) cb_data;
gdb_assert (data->result.symbol == NULL
&& data->result.block == NULL);
- data->result = lookup_symbol_in_objfile (objfile, GLOBAL_BLOCK,
+ data->result = lookup_symbol_in_objfile (objfile, data->block_index,
data->name, data->domain);
/* If we found a match, tell the iterator to stop. Otherwise,
return (data->result.symbol != NULL);
}
-/* See symtab.h. */
+/* This function contains the common code of lookup_{global,static}_symbol.
+ OBJFILE is only used if BLOCK_INDEX is GLOBAL_SCOPE, in which case it is
+ the objfile to start the lookup in. */
-struct block_symbol
-lookup_global_symbol (const char *name,
- const struct block *block,
- const domain_enum domain)
+static struct block_symbol
+lookup_global_or_static_symbol (const char *name,
+ enum block_enum block_index,
+ struct objfile *objfile,
+ const domain_enum domain)
{
struct symbol_cache *cache = get_symbol_cache (current_program_space);
struct block_symbol result;
- struct objfile *objfile;
- struct global_sym_lookup_data lookup_data;
+ struct global_or_static_sym_lookup_data lookup_data;
struct block_symbol_cache *bsc;
struct symbol_cache_slot *slot;
- objfile = lookup_objfile_from_block (block);
+ gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
+ gdb_assert (objfile == nullptr || block_index == GLOBAL_BLOCK);
/* First see if we can find the symbol in the cache.
This works because we use the current objfile to qualify the lookup. */
- result = symbol_cache_lookup (cache, objfile, GLOBAL_BLOCK, name, domain,
+ result = symbol_cache_lookup (cache, objfile, block_index, name, domain,
&bsc, &slot);
if (result.symbol != NULL)
{
{
memset (&lookup_data, 0, sizeof (lookup_data));
lookup_data.name = name;
+ lookup_data.block_index = block_index;
lookup_data.domain = domain;
gdbarch_iterate_over_objfiles_in_search_order
(objfile != NULL ? get_objfile_arch (objfile) : target_gdbarch (),
- lookup_symbol_global_iterator_cb, &lookup_data, objfile);
+ lookup_symbol_global_or_static_iterator_cb, &lookup_data, objfile);
result = lookup_data.result;
}
return result;
}
+/* See symtab.h. */
+
+struct block_symbol
+lookup_static_symbol (const char *name, const domain_enum domain)
+{
+ return lookup_global_or_static_symbol (name, STATIC_BLOCK, nullptr, domain);
+}
+
+/* See symtab.h. */
+
+struct block_symbol
+lookup_global_symbol (const char *name,
+ const struct block *block,
+ const domain_enum domain)
+{
+ struct objfile *objfile = lookup_objfile_from_block (block);
+ return lookup_global_or_static_symbol (name, GLOBAL_BLOCK, objfile, domain);
+}
+
int
symbol_matches_domain (enum language symbol_language,
domain_enum symbol_domain,
return (struct type *) 0;
}
-/* Iterate over the symbols named NAME, matching DOMAIN, in BLOCK.
-
- For each symbol that matches, CALLBACK is called. The symbol is
- passed to the callback.
-
- If CALLBACK returns false, the iteration ends. Otherwise, the
- search continues. */
+/* See symtab.h. */
-void
+bool
iterate_over_symbols (const struct block *block,
const lookup_name_info &name,
const domain_enum domain,
struct block_symbol block_sym = {sym, block};
if (!callback (&block_sym))
- return;
+ return false;
}
}
+ return true;
+}
+
+/* See symtab.h. */
+
+bool
+iterate_over_symbols_terminated
+ (const struct block *block,
+ const lookup_name_info &name,
+ const domain_enum domain,
+ gdb::function_view<symbol_found_callback_ftype> callback)
+{
+ if (!iterate_over_symbols (block, name, domain, callback))
+ return false;
+ struct block_symbol block_sym = {nullptr, block};
+ return callback (&block_sym);
}
/* Find the compunit symtab associated with PC and SECTION.
struct filename_partial_match_opts
{
/* Only match the directory name part. */
- int dirname = false;
+ bool dirname = false;
/* Only match the basename part. */
- int basename = false;
+ bool basename = false;
};
/* Data structure to maintain printing state for output_source_filename. */
Within each file the results are sorted locally; each symtab's global and
static blocks are separately alphabetized.
- Duplicate entries are removed. */
+ Duplicate entries are removed.
+
+ When EXCLUDE_MINSYMS is false then matching minsyms are also returned,
+ otherwise they are excluded. */
std::vector<symbol_search>
search_symbols (const char *regexp, enum search_domain kind,
const char *t_regexp,
- int nfiles, const char *files[])
+ int nfiles, const char *files[],
+ bool exclude_minsyms)
{
const struct blockvector *bv;
const struct block *b;
|| treg_matches_sym_type_name (*treg,
sym)))
|| (kind == TYPES_DOMAIN
- && SYMBOL_CLASS (sym) == LOC_TYPEDEF))))
+ && SYMBOL_CLASS (sym) == LOC_TYPEDEF
+ && SYMBOL_DOMAIN (sym) != MODULE_DOMAIN))))
{
/* match */
result.emplace_back (i, sym);
as we assume that a minimal symbol does not have a type. */
if ((found_misc || (nfiles == 0 && kind != FUNCTIONS_DOMAIN))
+ && !exclude_minsyms
&& !treg.has_value ())
{
for (objfile *objfile : current_program_space->objfiles ())
matches. */
static void
-symtab_symbol_info (bool quiet,
+symtab_symbol_info (bool quiet, bool exclude_minsyms,
const char *regexp, enum search_domain kind,
const char *t_regexp, int from_tty)
{
/* Must make sure that if we're interrupted, symbols gets freed. */
std::vector<symbol_search> symbols = search_symbols (regexp, kind,
- t_regexp, 0, NULL);
+ t_regexp, 0, NULL,
+ exclude_minsyms);
if (!quiet)
{
}
}
+/* Structure to hold the values of the options used by the 'info variables'
+ and 'info functions' commands. These correspond to the -q, -t, and -n
+ options. */
+
+struct info_print_options
+{
+ bool quiet = false;
+ bool exclude_minsyms = false;
+ char *type_regexp = nullptr;
+
+ ~info_print_options ()
+ {
+ xfree (type_regexp);
+ }
+};
+
+/* The options used by the 'info variables' and 'info functions'
+ commands. */
+
+static const gdb::option::option_def info_print_options_defs[] = {
+ gdb::option::boolean_option_def<info_print_options> {
+ "q",
+ [] (info_print_options *opt) { return &opt->quiet; },
+ nullptr, /* show_cmd_cb */
+ nullptr /* set_doc */
+ },
+
+ gdb::option::boolean_option_def<info_print_options> {
+ "n",
+ [] (info_print_options *opt) { return &opt->exclude_minsyms; },
+ nullptr, /* show_cmd_cb */
+ nullptr /* set_doc */
+ },
+
+ gdb::option::string_option_def<info_print_options> {
+ "t",
+ [] (info_print_options *opt) { return &opt->type_regexp; },
+ nullptr, /* show_cmd_cb */
+ nullptr /* set_doc */
+ }
+};
+
+/* Returns the option group used by 'info variables' and 'info
+ functions'. */
+
+static gdb::option::option_def_group
+make_info_print_options_def_group (info_print_options *opts)
+{
+ return {{info_print_options_defs}, opts};
+}
+
+/* Command completer for 'info variables' and 'info functions'. */
+
+static void
+info_print_command_completer (struct cmd_list_element *ignore,
+ completion_tracker &tracker,
+ const char *text, const char * /* word */)
+{
+ const auto group
+ = make_info_print_options_def_group (nullptr);
+ if (gdb::option::complete_options
+ (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, group))
+ return;
+
+ const char *word = advance_to_expression_complete_word_point (tracker, text);
+ symbol_completer (ignore, tracker, text, word);
+}
+
/* Implement the 'info variables' command. */
static void
info_variables_command (const char *args, int from_tty)
{
info_print_options opts;
- extract_info_print_options (&opts, &args);
+ auto grp = make_info_print_options_def_group (&opts);
+ gdb::option::process_options
+ (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
+ if (args != nullptr && *args == '\0')
+ args = nullptr;
- symtab_symbol_info (opts.quiet, args, VARIABLES_DOMAIN,
+ symtab_symbol_info (opts.quiet, opts.exclude_minsyms, args, VARIABLES_DOMAIN,
opts.type_regexp, from_tty);
}
info_functions_command (const char *args, int from_tty)
{
info_print_options opts;
- extract_info_print_options (&opts, &args);
+ auto grp = make_info_print_options_def_group (&opts);
+ gdb::option::process_options
+ (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
+ if (args != nullptr && *args == '\0')
+ args = nullptr;
- symtab_symbol_info (opts.quiet, args, FUNCTIONS_DOMAIN,
- opts.type_regexp, from_tty);
+ symtab_symbol_info (opts.quiet, opts.exclude_minsyms, args,
+ FUNCTIONS_DOMAIN, opts.type_regexp, from_tty);
}
/* Holds the -q option for the 'info types' command. */
struct info_types_options
{
- int quiet = false;
+ bool quiet = false;
};
/* The options used by the 'info types' command. */
(&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
if (args != nullptr && *args == '\0')
args = nullptr;
- symtab_symbol_info (opts.quiet, args, TYPES_DOMAIN, NULL, from_tty);
+ symtab_symbol_info (opts.quiet, false, args, TYPES_DOMAIN, NULL, from_tty);
}
/* Command completer for 'info types' command. */
std::vector<symbol_search> symbols = search_symbols (regexp,
FUNCTIONS_DOMAIN,
NULL,
- nfiles, files);
+ nfiles, files,
+ false);
scoped_rbreak_breakpoints finalize;
for (const symbol_search &p : symbols)
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\
+Usage: info variables [-q] [-n] [-t TYPEREGEXP] [NAMEREGEXP]\n\
Prints the global and static variables.\n"),
- _("global and static variables")));
+ _("global and static variables"),
+ true));
set_cmd_completer_handle_brkchars (c, info_print_command_completer);
if (dbx_commands)
{
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\
+Usage: whereis [-q] [-n] [-t TYPEREGEXP] [NAMEREGEXP]\n\
Prints the global and static variables.\n"),
- _("global and static variables")));
+ _("global and static variables"),
+ true));
set_cmd_completer_handle_brkchars (c, info_print_command_completer);
}
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\
+Usage: info functions [-q] [-n] [-t TYPEREGEXP] [NAMEREGEXP]\n\
Prints the functions.\n"),
- _("functions")));
+ _("functions"),
+ true));
set_cmd_completer_handle_brkchars (c, info_print_command_completer);
c = add_info ("types", info_types_command, _("\
add_setshow_enum_cmd ("multiple-symbols", no_class,
multiple_symbols_modes, &multiple_symbols_mode,
_("\
-Set the debugger behavior when more than one symbol are possible matches\n\
-in an expression."), _("\
+Set how the debugger handles ambiguities in expressions."), _("\
Show how the debugger handles ambiguities in expressions."), _("\
Valid values are \"ask\", \"all\", \"cancel\", and the default is \"all\"."),
NULL, NULL, &setlist, &showlist);