#include <array>
#include <vector>
#include <string>
-#include "common/gdb_vecs.h"
+#include "gdbsupport/gdb_vecs.h"
#include "gdbtypes.h"
#include "gdb_regex.h"
-#include "common/enum-flags.h"
-#include "common/function-view.h"
-#include "common/gdb_optional.h"
-#include "common/next-iterator.h"
+#include "gdbsupport/enum-flags.h"
+#include "gdbsupport/function-view.h"
+#include "gdbsupport/gdb_optional.h"
+#include "gdbsupport/next-iterator.h"
#include "completer.h"
/* Opaque declarations. */
extern CORE_ADDR symbol_overlayed_address (CORE_ADDR, struct obj_section *);
+/* Return the address of SYM. The MAYBE_COPIED flag must be set on
+ SYM. If SYM appears in the main program's minimal symbols, then
+ that minsym's address is returned; otherwise, SYM's address is
+ returned. This should generally only be used via the
+ SYMBOL_VALUE_ADDRESS macro. */
+
+extern CORE_ADDR get_symbol_address (const struct symbol *sym);
+
/* Note that all the following SYMBOL_* macros are used with the
SYMBOL argument being either a partial symbol or
a full symbol. Both types have a ginfo field. In particular
field only, instead of the SYMBOL parameter. */
#define SYMBOL_VALUE(symbol) (symbol)->ginfo.value.ivalue
-#define SYMBOL_VALUE_ADDRESS(symbol) (symbol)->ginfo.value.address
+#define SYMBOL_VALUE_ADDRESS(symbol) \
+ (((symbol)->maybe_copied) ? get_symbol_address (symbol) \
+ : ((symbol)->ginfo.value.address))
+#define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value) \
+ ((symbol)->ginfo.value.address = (new_value))
#define SYMBOL_VALUE_BYTES(symbol) (symbol)->ginfo.value.bytes
#define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->ginfo.value.common_block
#define SYMBOL_BLOCK_VALUE(symbol) (symbol)->ginfo.value.block
symbol_set_names (&(symbol)->ginfo, linkage_name, len, copy_name, \
(objfile)->per_bfd)
extern void symbol_set_names (struct general_symbol_info *symbol,
- 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);
/* Now come lots of name accessor macros. Short version as to when to
#define SYMBOL_PRINT_NAME(symbol) \
(demangle ? SYMBOL_NATURAL_NAME (symbol) : SYMBOL_LINKAGE_NAME (symbol))
-extern int demangle;
+extern bool demangle;
/* Macro that returns the name to be used when sorting and searching symbols.
In C++, we search for the demangled form of a name,
between names and addresses, and vice versa. They are also sometimes
used to figure out what full symbol table entries need to be read in. */
-struct minimal_symbol
+struct minimal_symbol : public general_symbol_info
{
-
- /* The general symbol info required for all types of symbols.
-
- The SYMBOL_VALUE_ADDRESS contains the address that this symbol
- corresponds to. */
-
- struct general_symbol_info mginfo;
-
/* Size of this symbol. dbx_end_psymtab in dbxread.c uses this
information to calculate the end of the partial symtab based on the
address of the last symbol plus the size of the last symbol. */
the object file format may not carry that piece of information. */
unsigned int has_size : 1;
+ /* For data symbols only, if this is set, then the symbol might be
+ subject to copy relocation. In this case, a minimal symbol
+ matching the symbol's linkage name is first looked for in the
+ main objfile. If found, then that address is used; otherwise the
+ address in this symbol is used. */
+
+ unsigned maybe_copied : 1;
+
/* Minimal symbols with the same hash key are kept on a linked
list. This is the link. */
struct minimal_symbol *demangled_hash_next;
-/* True if this symbol is of some data type. */
+ /* True if this symbol is of some data type. */
bool data_p () const;
bool text_p () const;
};
+/* Return the address of MINSYM, which comes from OBJF. The
+ MAYBE_COPIED flag must be set on MINSYM. If MINSYM appears in the
+ main program's minimal symbols, then that minsym's address is
+ returned; otherwise, MINSYM's address is returned. This should
+ generally only be used via the MSYMBOL_VALUE_ADDRESS macro. */
+
+extern CORE_ADDR get_msymbol_address (struct objfile *objf,
+ const struct minimal_symbol *minsym);
+
#define MSYMBOL_TARGET_FLAG_1(msymbol) (msymbol)->target_flag_1
#define MSYMBOL_TARGET_FLAG_2(msymbol) (msymbol)->target_flag_2
#define MSYMBOL_SIZE(msymbol) ((msymbol)->size + 0)
#define MSYMBOL_HAS_SIZE(msymbol) ((msymbol)->has_size + 0)
#define MSYMBOL_TYPE(msymbol) (msymbol)->type
-#define MSYMBOL_VALUE(symbol) (symbol)->mginfo.value.ivalue
+#define MSYMBOL_VALUE(symbol) (symbol)->value.ivalue
/* The unrelocated address of the minimal symbol. */
-#define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->mginfo.value.address + 0)
+#define MSYMBOL_VALUE_RAW_ADDRESS(symbol) ((symbol)->value.address + 0)
/* The relocated address of the minimal symbol, using the section
offsets from OBJFILE. */
#define MSYMBOL_VALUE_ADDRESS(objfile, symbol) \
- ((symbol)->mginfo.value.address \
- + ANOFFSET ((objfile)->section_offsets, ((symbol)->mginfo.section)))
+ (((symbol)->maybe_copied) ? get_msymbol_address (objfile, symbol) \
+ : ((symbol)->value.address \
+ + ANOFFSET ((objfile)->section_offsets, ((symbol)->section))))
/* For a bound minsym, we can easily compute the address directly. */
#define BMSYMBOL_VALUE_ADDRESS(symbol) \
MSYMBOL_VALUE_ADDRESS ((symbol).objfile, (symbol).minsym)
#define SET_MSYMBOL_VALUE_ADDRESS(symbol, new_value) \
- ((symbol)->mginfo.value.address = (new_value))
-#define MSYMBOL_VALUE_BYTES(symbol) (symbol)->mginfo.value.bytes
-#define MSYMBOL_BLOCK_VALUE(symbol) (symbol)->mginfo.value.block
-#define MSYMBOL_VALUE_CHAIN(symbol) (symbol)->mginfo.value.chain
-#define MSYMBOL_LANGUAGE(symbol) (symbol)->mginfo.language
-#define MSYMBOL_SECTION(symbol) (symbol)->mginfo.section
+ ((symbol)->value.address = (new_value))
+#define MSYMBOL_VALUE_BYTES(symbol) (symbol)->value.bytes
+#define MSYMBOL_BLOCK_VALUE(symbol) (symbol)->value.block
+#define MSYMBOL_VALUE_CHAIN(symbol) (symbol)->value.chain
+#define MSYMBOL_LANGUAGE(symbol) (symbol)->language
+#define MSYMBOL_SECTION(symbol) (symbol)->section
#define MSYMBOL_OBJ_SECTION(objfile, symbol) \
- (((symbol)->mginfo.section >= 0) \
- ? (&(((objfile)->sections)[(symbol)->mginfo.section])) \
+ (((symbol)->section >= 0) \
+ ? (&(((objfile)->sections)[(symbol)->section])) \
: NULL)
#define MSYMBOL_NATURAL_NAME(symbol) \
- (symbol_natural_name (&(symbol)->mginfo))
-#define MSYMBOL_LINKAGE_NAME(symbol) (symbol)->mginfo.name
+ (symbol_natural_name (symbol))
+#define MSYMBOL_LINKAGE_NAME(symbol) (symbol)->name
#define MSYMBOL_PRINT_NAME(symbol) \
(demangle ? MSYMBOL_NATURAL_NAME (symbol) : MSYMBOL_LINKAGE_NAME (symbol))
#define MSYMBOL_DEMANGLED_NAME(symbol) \
- (symbol_demangled_name (&(symbol)->mginfo))
-#define MSYMBOL_SET_LANGUAGE(symbol,language,obstack) \
- (symbol_set_language (&(symbol)->mginfo, (language), (obstack)))
+ (symbol_demangled_name (symbol))
#define MSYMBOL_SEARCH_NAME(symbol) \
- (symbol_search_name (&(symbol)->mginfo))
-#define MSYMBOL_SET_NAMES(symbol,linkage_name,len,copy_name,objfile) \
- symbol_set_names (&(symbol)->mginfo, linkage_name, len, copy_name, \
- (objfile)->per_bfd)
+ (symbol_search_name (symbol))
#include "minsyms.h"
/* Whether this is an inlined function (class LOC_BLOCK only). */
unsigned is_inlined : 1;
+ /* For LOC_STATIC only, if this is set, then the symbol might be
+ subject to copy relocation. In this case, a minimal symbol
+ matching the symbol's linkage name is first looked for in the
+ main objfile. If found, then that address is used; otherwise the
+ address in this symbol is used. */
+
+ unsigned maybe_copied : 1;
+
/* The concrete type of this symbol. */
ENUM_BITFIELD (symbol_subclass_kind) subclass : 2;
extern const struct symbol_impl *symbol_impls;
-/* For convenience. All fields are NULL. This means "there is no
- symbol". */
-extern const struct block_symbol null_block_symbol;
-
/* Note: There is no accessor macro for symbol.owner because it is
"private". */
const char *filename;
- /* Total number of lines found in source file. */
-
- int nlines;
-
- /* line_charpos[N] is the position of the (N-1)th line of the
- source file. "position" means something we can lseek() to; it
- is not guaranteed to be useful any other way. */
-
- int *line_charpos;
-
/* Language of this source file. */
enum language language;
const char *multiple_symbols_select_mode (void);
-int symbol_matches_domain (enum language symbol_language,
- domain_enum symbol_domain,
- domain_enum domain);
+bool symbol_matches_domain (enum language symbol_language,
+ domain_enum symbol_domain,
+ domain_enum domain);
/* lookup a symbol table by source file name. */
nullptr is used as a return value for *BLOCK if no block is found.
This function either succeeds or fails (not halfway succeeds). If
it succeeds, it sets *NAME, *ADDRESS, and *ENDADDR to real
- information and returns 1. If it fails, it sets *NAME, *ADDRESS
- and *ENDADDR to zero and returns 0.
+ information and returns true. If it fails, it sets *NAME, *ADDRESS
+ and *ENDADDR to zero and returns false.
If the function in question occupies non-contiguous ranges,
*ADDRESS and *ENDADDR are (subject to the conditions noted above) set
containing the entry pc should instead call
find_function_entry_range_from_pc. */
-extern int find_pc_partial_function (CORE_ADDR pc, const char **name,
- CORE_ADDR *address, CORE_ADDR *endaddr,
- const struct block **block = nullptr);
+extern bool find_pc_partial_function (CORE_ADDR pc, const char **name,
+ CORE_ADDR *address, CORE_ADDR *endaddr,
+ const struct block **block = nullptr);
/* Like find_pc_partial_function, above, but *ADDRESS and *ENDADDR are
set to start and end addresses of the range containing the entry pc.
extern struct compunit_symtab *
find_pc_sect_compunit_symtab (CORE_ADDR, struct obj_section *);
-extern int find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
+extern bool find_pc_line_pc_range (CORE_ADDR, CORE_ADDR *, CORE_ADDR *);
extern void reread_symbols (void);
#define GCC2_COMPILED_FLAG_SYMBOL "gcc2_compiled."
#endif
-extern int in_gnu_ifunc_stub (CORE_ADDR pc);
+extern bool in_gnu_ifunc_stub (CORE_ADDR pc);
/* Functions for resolving STT_GNU_IFUNC symbols which are implemented only
for ELF symbol files. */
CORE_ADDR (*gnu_ifunc_resolve_addr) (struct gdbarch *gdbarch, CORE_ADDR pc);
/* See elf_gnu_ifunc_resolve_name for its real implementation. */
- int (*gnu_ifunc_resolve_name) (const char *function_name,
+ bool (*gnu_ifunc_resolve_name) (const char *function_name,
CORE_ADDR *function_address_p);
/* See elf_gnu_ifunc_resolver_stop for its real implementation. */
/* Given a symtab and line number, return the pc there. */
-extern int find_line_pc (struct symtab *, int, CORE_ADDR *);
+extern bool find_line_pc (struct symtab *, int, CORE_ADDR *);
-extern int find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
- CORE_ADDR *);
+extern bool find_line_pc_range (struct symtab_and_line, CORE_ADDR *,
+ CORE_ADDR *);
extern void resolve_sal_pc (struct symtab_and_line *);
/* symtab.c */
-int matching_obj_sections (struct obj_section *, struct obj_section *);
+bool matching_obj_sections (struct obj_section *, struct obj_section *);
-extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
+extern struct symtab *find_line_symtab (struct symtab *, int, int *, bool *);
/* Given a function symbol SYM, find the symtab and line for the start
of the function. If FUNFIRSTLINE is true, we want the first line
enum search_domain,
const char *,
int,
- const char **);
+ const char **,
+ bool);
extern bool treg_matches_sym_type_name (const compiled_regex &treg,
const struct symbol *sym);
-/* The name of the ``main'' function.
- FIXME: cagney/2001-03-20: Can't make main_name() const since some
- of the calling code currently assumes that the string isn't
- const. */
-extern /*const */ char *main_name (void);
+/* The name of the ``main'' function. */
+extern const char *main_name ();
extern enum language main_language (void);
-/* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global blocks.
+/* Lookup symbol NAME from DOMAIN in MAIN_OBJFILE's global or static blocks,
+ as specified by BLOCK_INDEX.
This searches MAIN_OBJFILE as well as any associated separate debug info
objfiles of MAIN_OBJFILE.
+ BLOCK_INDEX can be GLOBAL_BLOCK or STATIC_BLOCK.
Upon success fixes up the symbol's section if necessary. */
extern struct block_symbol
lookup_global_symbol_from_objfile (struct objfile *main_objfile,
+ enum block_enum block_index,
const char *name,
const domain_enum domain);
/* Return 1 if the supplied producer string matches the ARM RealView
compiler (armcc). */
-int producer_is_realview (const char *producer);
+bool producer_is_realview (const char *producer);
void fixup_section (struct general_symbol_info *ginfo,
CORE_ADDR addr, struct objfile *objfile);
extern unsigned int symbol_lookup_debug;
-extern int basenames_may_differ;
+extern bool basenames_may_differ;
-int compare_filenames_for_search (const char *filename,
- const char *search_name);
+bool compare_filenames_for_search (const char *filename,
+ const char *search_name);
-int compare_glob_filenames_for_search (const char *filename,
- const char *search_name);
+bool compare_glob_filenames_for_search (const char *filename,
+ const char *search_name);
bool iterate_over_some_symtabs (const char *name,
const char *real_path,
typedef bool (symbol_found_callback_ftype) (struct block_symbol *bsym);
-void iterate_over_symbols (const struct block *block,
+/* 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 and this function
+ returns false. Otherwise, the search continues, and the function
+ eventually returns true. */
+
+bool iterate_over_symbols (const struct block *block,
const lookup_name_info &name,
const domain_enum domain,
gdb::function_view<symbol_found_callback_ftype> callback);
+/* Like iterate_over_symbols, but if all calls to CALLBACK return
+ true, then calls CALLBACK one additional time with a block_symbol
+ that has a valid block but a NULL symbol. */
+
+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);
+
/* Storage type used by demangle_for_lookup. demangle_for_lookup
either returns a const char * pointer that points to either of the
fields of this type, or a pointer to the input NAME. This is done