/* Symbol table lookup for the GNU debugger, GDB.
- Copyright (C) 1986-2021 Free Software Foundation, Inc.
+ Copyright (C) 1986-2022 Free Software Foundation, Inc.
This file is part of GDB.
#include "symfile.h"
#include "objfiles.h"
#include "gdbcmd.h"
-#include "gdb_regex.h"
+#include "gdbsupport/gdb_regex.h"
#include "expression.h"
#include "language.h"
#include "demangle.h"
#include "hashtab.h"
#include "typeprint.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
#include "block.h"
#include "dictionary.h"
/* See symtab.h. */
+call_site *
+compunit_symtab::find_call_site (CORE_ADDR pc) const
+{
+ if (m_call_site_htab == nullptr)
+ return nullptr;
+
+ CORE_ADDR delta
+ = this->objfile->section_offsets[COMPUNIT_BLOCK_LINE_SECTION (this)];
+ CORE_ADDR unrelocated_pc = pc - delta;
+
+ struct call_site call_site_local (unrelocated_pc, nullptr, nullptr);
+ void **slot
+ = htab_find_slot (m_call_site_htab, &call_site_local, NO_INSERT);
+ if (slot == nullptr)
+ return nullptr;
+
+ return (call_site *) *slot;
+}
+
+/* See symtab.h. */
+
+void
+compunit_symtab::set_call_site_htab (htab_t call_site_htab)
+{
+ gdb_assert (m_call_site_htab == nullptr);
+ m_call_site_htab = call_site_htab;
+}
+
+/* See symtab.h. */
+
struct symtab *
compunit_primary_filetab (const struct compunit_symtab *cust)
{
/* See symtab.h */
-char *
+gdb::unique_xmalloc_ptr<char>
symbol_find_demangled_name (struct general_symbol_info *gsymbol,
const char *mangled)
{
- char *demangled = NULL;
+ gdb::unique_xmalloc_ptr<char> demangled;
int i;
if (gsymbol->language () == language_unknown)
linkage_name_copy = linkage_name;
if (demangled_name.get () == nullptr)
- demangled_name.reset
- (symbol_find_demangled_name (this, linkage_name_copy.data ()));
+ demangled_name
+ = symbol_find_demangled_name (this, linkage_name_copy.data ());
/* Suppose we have demangled_name==NULL, copy_name==0, and
linkage_name_copy==linkage_name. In this case, we already have the
lookup, so we can always binary search. */
if (lang == language_cplus)
{
- char *demangled_name = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS);
+ gdb::unique_xmalloc_ptr<char> demangled_name
+ = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS);
if (demangled_name != NULL)
- return storage.set_malloc_ptr (demangled_name);
+ return storage.set_malloc_ptr (std::move (demangled_name));
/* If we were given a non-mangled name, canonicalize it
according to the language (so far only for C++). */
}
else if (lang == language_d)
{
- char *demangled_name = d_demangle (name, 0);
+ gdb::unique_xmalloc_ptr<char> demangled_name = d_demangle (name, 0);
if (demangled_name != NULL)
- return storage.set_malloc_ptr (demangled_name);
+ return storage.set_malloc_ptr (std::move (demangled_name));
}
else if (lang == language_go)
{
- char *demangled_name
+ gdb::unique_xmalloc_ptr<char> demangled_name
= language_def (language_go)->demangle_symbol (name, 0);
if (demangled_name != NULL)
- return storage.set_malloc_ptr (demangled_name);
+ return storage.set_malloc_ptr (std::move (demangled_name));
}
return name;
for (i = type->num_fields () - 1; i >= TYPE_N_BASECLASSES (type); i--)
{
- const char *t_field_name = TYPE_FIELD_NAME (type, i);
+ const char *t_field_name = type->field (i).name ();
if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
{
/* I'm not really sure that type of this can ever
be typedefed; just be safe. */
t = check_typedef (t);
- if (t->code () == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
+ if (t->is_pointer_or_reference ())
t = TYPE_TARGET_TYPE (t);
if (t->code () != TYPE_CODE_STRUCT
enum search_domain kind = m_kind;
bool found_msymbol = false;
+ auto do_file_match = [&] (const char *filename, bool basenames)
+ {
+ return file_matches (filename, filenames, basenames);
+ };
+ gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher = nullptr;
+ if (!filenames.empty ())
+ file_matcher = do_file_match;
+
objfile->expand_symtabs_matching
- ([&] (const char *filename, bool basenames)
- {
- return file_matches (filename, filenames, basenames);
- },
+ (file_matcher,
&lookup_name_info::match_any (),
[&] (const char *symname)
{
{
bool quiet = false;
bool exclude_minsyms = false;
- char *type_regexp = nullptr;
-
- ~info_vars_funcs_options ()
- {
- xfree (type_regexp);
- }
+ std::string type_regexp;
};
/* The options used by the 'info variables' and 'info functions'
gdb::option::string_option_def<info_vars_funcs_options> {
"t",
- [] (info_vars_funcs_options *opt) { return &opt->type_regexp;
- },
+ [] (info_vars_funcs_options *opt) { return &opt->type_regexp; },
nullptr, /* show_cmd_cb */
nullptr /* set_doc */
}
if (args != nullptr && *args == '\0')
args = nullptr;
- symtab_symbol_info (opts.quiet, opts.exclude_minsyms, args, VARIABLES_DOMAIN,
- opts.type_regexp, from_tty);
+ symtab_symbol_info
+ (opts.quiet, opts.exclude_minsyms, args, VARIABLES_DOMAIN,
+ opts.type_regexp.empty () ? nullptr : opts.type_regexp.c_str (),
+ from_tty);
}
/* Implement the 'info functions' command. */
if (args != nullptr && *args == '\0')
args = nullptr;
- symtab_symbol_info (opts.quiet, opts.exclude_minsyms, args,
- FUNCTIONS_DOMAIN, opts.type_regexp, from_tty);
+ symtab_symbol_info
+ (opts.quiet, opts.exclude_minsyms, args, FUNCTIONS_DOMAIN,
+ opts.type_regexp.empty () ? nullptr : opts.type_regexp.c_str (),
+ from_tty);
}
/* Holds the -q option for the 'info types' command. */
if (c == TYPE_CODE_UNION || c == TYPE_CODE_STRUCT)
for (j = TYPE_N_BASECLASSES (t); j < t->num_fields (); j++)
- if (TYPE_FIELD_NAME (t, j))
+ if (t->field (j).name ())
completion_list_add_name (tracker, sym->language (),
- TYPE_FIELD_NAME (t, j),
+ t->field (j).name (),
lookup_name, text, word);
}
}
"ARM/Thumb C/C++ Compiler, RVCT",
"ARM C/C++ Compiler, RVCT"
};
- int i;
if (producer == NULL)
return false;
- for (i = 0; i < ARRAY_SIZE (arm_idents); i++)
- if (startswith (producer, arm_idents[i]))
+ for (const char *ident : arm_idents)
+ if (startswith (producer, ident))
return true;
return false;
struct info_modules_var_func_options
{
bool quiet = false;
- char *type_regexp = nullptr;
- char *module_regexp = nullptr;
-
- ~info_modules_var_func_options ()
- {
- xfree (type_regexp);
- xfree (module_regexp);
- }
+ std::string type_regexp;
+ std::string module_regexp;
};
/* The options used by 'info module variables' and 'info module functions'
if (args != nullptr && *args == '\0')
args = nullptr;
- info_module_subcommand (opts.quiet, opts.module_regexp, args,
- opts.type_regexp, FUNCTIONS_DOMAIN);
+ info_module_subcommand
+ (opts.quiet,
+ opts.module_regexp.empty () ? nullptr : opts.module_regexp.c_str (), args,
+ opts.type_regexp.empty () ? nullptr : opts.type_regexp.c_str (),
+ FUNCTIONS_DOMAIN);
}
/* Implements the 'info module variables' command. */
if (args != nullptr && *args == '\0')
args = nullptr;
- info_module_subcommand (opts.quiet, opts.module_regexp, args,
- opts.type_regexp, VARIABLES_DOMAIN);
+ info_module_subcommand
+ (opts.quiet,
+ opts.module_regexp.empty () ? nullptr : opts.module_regexp.c_str (), args,
+ opts.type_regexp.empty () ? nullptr : opts.type_regexp.c_str (),
+ VARIABLES_DOMAIN);
}
/* Command completer for 'info module ...' sub-commands. */