31#include "readline/tilde.h"
32#include "gdbsupport/gdb_regex.h"
39#include "gdbsupport/buildargv.h"
60 while (iter !=
nullptr)
109 if (msymbol.
minsym == NULL)
119 for (tpst = pst; tpst != NULL; tpst = tpst->
next)
154 if (this_addr > best_addr)
156 best_addr = this_addr;
173 if (pc >= pst->text_low (
objfile) && pc < pst->text_high (
objfile))
179 if (best_pst != NULL)
207(Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
227 gdb_assert (psymtab != NULL);
230 best_pc = (textlow != 0) ? textlow - 1 : 0;
240 && (p->address (
objfile) > best_pc
242 && best_pc == 0 && p->address (
objfile) == 0)))
250 best_pc = p->address (
objfile);
260 && (p->address (
objfile) > best_pc
262 && best_pc == 0 && p->address (
objfile) == 0)))
285 bool *symbol_found_p)
287 *symbol_found_p =
false;
302 *symbol_found_p =
true;
341 int do_linear_search = 1;
350 if (global && ordered_compare)
352 do_linear_search = 0;
361 top = start + length - 1;
365 center = bottom + (top - bottom) / 2;
366 gdb_assert (center < top);
368 enum language lang = (*center)->ginfo.language ();
369 const char *lang_ln =
name.language_lookup_name (lang);
371 if (ordered_compare ((*center)->ginfo.search_name (),
377 gdb_assert (top == bottom);
379 while (top <= real_top
392 if (do_linear_search)
394 for (psym = start; psym < start + length; psym++)
421 int do_linear_search = 1;
432 do_linear_search = 0;
441 top = start + length - 1;
445 center = bottom + (top - bottom) / 2;
447 gdb_assert (center < top);
450 lookup_name.
c_str ()) >= 0)
460 gdb_assert (top == bottom);
484 if (do_linear_search)
486 for (psym = start; psym < start + length; psym++)
509 while (pst->
user != NULL)
523 gdb_printf (_(
"Reading in symbols for %s...\n"),
544 const char *
name = ps->filename;
545 int len = strlen (
name);
547 if (!(len > 2 && (strcmp (&
name[len - 2],
".h") == 0
548 || strcmp (
name,
"<<C++-namespaces>>") == 0)))
556 internal_error (_(
"select_source_symtab: "
557 "readin pst found and no symtabs."));
579 if (pst->fullname != NULL)
581 xfree (pst->fullname);
582 pst->fullname = NULL;
589 const std::vector<partial_symbol *> &symbols,
590 const char *what,
struct ui_file *outfile)
592 gdb_printf (outfile,
" %s partial symbols:\n", what);
596 gdb_printf (outfile,
" `%s'", p->ginfo.linkage_name ());
597 if (p->ginfo.demangled_name () != NULL)
600 p->ginfo.demangled_name ());
606 gdb_puts (
"undefined domain, ", outfile);
612 gdb_puts (
"struct domain, ", outfile);
615 gdb_puts (
"module domain, ", outfile);
618 gdb_puts (
"label domain, ", outfile);
621 gdb_puts (
"common block domain, ", outfile);
624 gdb_puts (
"<invalid domain>, ", outfile);
642 gdb_puts (
"pass by value", outfile);
645 gdb_puts (
"pass by reference", outfile);
648 gdb_puts (
"register address parameter", outfile);
651 gdb_puts (
"stack parameter", outfile);
663 gdb_puts (
"constant bytes", outfile);
669 gdb_puts (
"optimized out", outfile);
672 gdb_puts (
"computed at runtime", outfile);
675 gdb_puts (
"<invalid location>", outfile);
693 gdb_printf (outfile,
"\nAnonymous partial symtab (%s) ",
698 gdb_printf (outfile,
"\nPartial symtab for source file %s ",
702 host_address_to_string (psymtab));
703 gdb_printf (outfile,
" Read from object file %s (%s)\n",
705 host_address_to_string (
objfile));
710 " Full symtab was read (at %s)\n",
713 gdb_printf (outfile,
" Symbols cover text addresses ");
718 gdb_printf (outfile,
" Depends on %d other partial symtabs.\n",
723 if (psymtab->
user != NULL)
724 gdb_printf (outfile,
" Shared partial symtab with user %s\n",
725 host_address_to_string (psymtab->
user));
749 count += pst->global_psymbols.size ();
750 count += pst->static_psymbols.size ();
767 gdb_printf (_(
" Number of \"partial\" symbols read: %d\n"),
776 gdb_printf (_(
" Number of psym tables (not yet expanded): %d\n"),
778 gdb_printf (_(
" Total memory used for psymbol cache: %d\n"),
783 gdb_printf (_(
"Psymbol byte cache statistics:\n"));
785 (
"partial symbol cache");
802 psymtab = psymtab->
next)
805 host_address_to_string (psymtab));
826 gdb::function_view<symbol_filename_ftype> fun,
831 const char *fullname;
838 if (ps->user != NULL)
850 fun (ps->filename, fullname);
872 gdb::unique_xmalloc_ptr<char>
fullname
909 block_search_flags search_flags,
913 gdb::function_view<expand_symtabs_symbol_matcher_ftype> sym_matcher)
933 objfile, search_flags, domain, search,
934 lookup_name, sym_matcher);
983 (*psym)->domain, domain))
995 && (sym_matcher == NULL
996 || sym_matcher ((*psym)->ginfo.search_name ())))
1016 gdb::function_view<expand_symtabs_file_matcher_ftype> file_matcher,
1018 gdb::function_view<expand_symtabs_symbol_matcher_ftype> symbol_matcher,
1019 gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
1020 block_search_flags search_flags,
1028 gdb::optional<lookup_name_info> psym_lookup_name;
1029 if (lookup_name !=
nullptr)
1033 gdb_assert (lookup_name !=
nullptr || symbol_matcher ==
nullptr);
1049 match = file_matcher (ps->filename,
false);
1055 || file_matcher (lbasename (ps->filename),
true))
1062 if (lookup_name ==
nullptr
1070 if (cust !=
nullptr && expansion_notify !=
nullptr)
1071 if (!expansion_notify (cust))
1096 if (psymtab->readin_p (
objfile))
1113 std::set<CORE_ADDR> *seen_addrs,
1114 const std::vector<partial_symbol *> &symbols)
1120 CORE_ADDR addr = psym->address (
objfile);
1121 if (seen_addrs->find (addr) == seen_addrs->end ())
1123 seen_addrs->insert (addr);
1139 std::set<CORE_ADDR> seen_addrs;
1145 pst->global_psymbols);
1148 pst->static_psymbols);
1154 [] (
const std::pair<CORE_ADDR, partial_symtab *> &a,
1155 const std::pair<CORE_ADDR, partial_symtab *> &b)
1157 return a.first < b.first;
1161 auto iter = std::lower_bound
1163 [] (
const std::pair<CORE_ADDR, partial_symtab *> &a,
1203 return strcmp_iw_ordered (s1->ginfo.search_name (),
1204 s2->ginfo.search_name ()) < 0;
1213 unsigned long h = 0;
1216 unsigned int domain = psymbol->
domain;
1217 unsigned int theclass = psymbol->
aclass;
1220 h =
fast_hash (&lang,
sizeof (
unsigned int), h);
1221 h =
fast_hash (&domain,
sizeof (
unsigned int), h);
1222 h =
fast_hash (&theclass,
sizeof (
unsigned int), h);
1270 std::vector<partial_symbol *> &list
1274 list.push_back (psym);
1291 memset (&psymbol, 0,
sizeof (psymbol));
1296 psymbol.
aclass = theclass;
1320 static std::string last_bfd_name;
1321 const char *this_bfd_name
1322 = bfd_get_filename (objfile_per_bfd->
get_bfd ());
1324 if (last_bfd_name.empty () || last_bfd_name != this_bfd_name)
1326 last_bfd_name = this_bfd_name;
1333 host_address_to_string (
this),
filename);
1378 while ((*prev_pst) != pst)
1379 prev_pst = &((*prev_pst)->next);
1380 (*prev_pst) = pst->
next;
1390 char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL;
1391 int i, outfile_idx, found;
1397 gdb_argv argv (args);
1399 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
1401 if (strcmp (argv[i],
"-pc") == 0)
1403 if (argv[i + 1] == NULL)
1404 error (_(
"Missing pc value"));
1405 address_arg = argv[++i];
1407 else if (strcmp (argv[i],
"-source") == 0)
1409 if (argv[i + 1] == NULL)
1410 error (_(
"Missing source file"));
1411 source_arg = argv[++i];
1413 else if (strcmp (argv[i],
"-objfile") == 0)
1415 if (argv[i + 1] == NULL)
1416 error (_(
"Missing objfile name"));
1417 objfile_arg = argv[++i];
1419 else if (strcmp (argv[i],
"--") == 0)
1425 else if (argv[i][0] ==
'-')
1428 error (_(
"Unknown option: %s"), argv[i]);
1435 if (address_arg != NULL && source_arg != NULL)
1436 error (_(
"Must specify at most one of -pc and -source"));
1440 if (argv != NULL && argv[outfile_idx] != NULL)
1442 if (argv[outfile_idx + 1] != NULL)
1443 error (_(
"Junk at end of command"));
1444 gdb::unique_xmalloc_ptr<char> outfile_name
1445 (tilde_expand (argv[outfile_idx]));
1446 if (!arg_outfile.
open (outfile_name.get (), FOPEN_WT))
1448 outfile = &arg_outfile;
1451 if (address_arg != NULL)
1461 int printed_objfile_header = 0;
1462 int print_for_objfile = 1;
1465 if (objfile_arg != NULL)
1469 if (!print_for_objfile)
1479 if (address_arg != NULL)
1489 if (!printed_objfile_header)
1491 outfile->
printf (
"\nPartial symtabs for objfile %s\n",
1493 printed_objfile_header = 1;
1503 int print_for_source = 0;
1506 if (source_arg != NULL)
1512 if (source_arg == NULL
1513 || print_for_source)
1515 if (!printed_objfile_header)
1517 outfile->
printf (
"\nPartial symtabs for objfile %s\n",
1519 printed_objfile_header = 1;
1530 if (address_arg != NULL)
1531 error (_(
"No partial symtab for address: %s"), address_arg);
1532 if (source_arg != NULL)
1533 error (_(
"No partial symtab for source file: %s"), source_arg);
1552 int printed_objfile_start = 0;
1565 || re_exec (psymtab->filename))
1567 if (! printed_objfile_start)
1572 host_address_to_string (
objfile));
1573 printed_objfile_start = 1;
1576 gdb_printf (
" { psymtab %s ", psymtab->filename);
1578 gdb_printf (
"((struct partial_symtab *) %s)\n",
1579 host_address_to_string (psymtab));
1582 psymtab->readin_p (
objfile) ?
"yes" :
"no");
1585 ? psymtab->fullname :
"(null)");
1588 psymtab->text_low (
objfile)));
1591 psymtab->text_high (
objfile)));
1594 if (!psymtab->global_psymbols.empty ())
1596 (
"(* (struct partial_symbol **) %s @ %d)\n",
1597 host_address_to_string (psymtab->global_psymbols.data ()),
1598 (
int) psymtab->global_psymbols.size ());
1602 if (!psymtab->static_psymbols.empty ())
1604 (
"(* (struct partial_symbol **) %s @ %d)\n",
1605 host_address_to_string (psymtab->static_psymbols.data ()),
1606 (
int) psymtab->static_psymbols.size ());
1611 "((struct partial_symtab *) %s)\n",
1612 psymtab->user->filename,
1613 host_address_to_string (psymtab->user));
1615 if (psymtab->number_of_dependencies)
1620 for (i = 0; i < psymtab->number_of_dependencies; i++)
1627 "((struct partial_symtab *) %s)\n",
1629 host_address_to_string (dep));
1640 if (printed_objfile_start)
1653 const struct block *b;
1671 cust = ps->get_compunit_symtab (
objfile);
1696 && psym->ginfo.value_address () == 0)
1705 gdb_puts (psym->ginfo.linkage_name ());
1720 gdb_puts (psym->ginfo.linkage_name ());
1726 if (ps->raw_text_high () != 0
1752Print dump of current partial symbol definitions.\n\
1753Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
1754 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1755Entries in the partial symbol table are dumped to file OUTFILE,\n\
1756or the terminal if OUTFILE is unspecified.\n\
1757If ADDRESS is provided, dump only the file for that address.\n\
1758If SOURCE is provided, dump only that file's symbols.\n\
1759If OBJFILE is provided, dump only that file's minimal symbols."),
1763List the partial symbol tables for all object files.\n\
1764This does not include information about individual partial symbols,\n\
1765just the symbol table structures themselves."),
1770Check consistency of currently expanded psymtabs versus symtabs."),
constexpr std::string_view s1
constexpr std::string_view s2
struct symbol * block_lookup_symbol(const struct block *block, const char *name, symbol_name_match_type match_type, const domain_enum domain)
const char * c_str() const
lookup_name_info make_ignore_params() const
struct partial_symtab * psymtabs
void discard_psymtab(struct partial_symtab *pst)
void install_psymtab(partial_symtab *pst)
next_range< partial_symtab > partial_symtab_range
struct obstack * obstack()
psymbol_bcache psymbol_cache
bool open(const char *name, const char *mode)
void printf(const char *,...) ATTRIBUTE_PRINTF(2
struct cmd_list_element * maintenanceprintlist
struct cmd_list_element * maintenancelist
struct cmd_list_element * maintenanceinfolist
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
EXTERN_C char * re_comp(const char *)
CORE_ADDR parse_and_eval_address(const char *exp)
static void keep_going(struct execution_control_state *ecs)
const struct language_defn * language_def(enum language lang)
struct obj_section * find_pc_section(CORE_ADDR pc)
const char * objfile_name(const struct objfile *objfile)
std::string copy_name(struct stoken token)
struct program_space * current_program_space
std::vector< struct program_space * > program_spaces
@ PST_SEARCHED_AND_NOT_FOUND
static struct compunit_symtab * psymtab_to_symtab(struct objfile *objfile, struct partial_symtab *pst)
static struct partial_symbol * match_partial_symbol(struct objfile *objfile, struct partial_symtab *pst, int global, const lookup_name_info &name, domain_enum domain, symbol_compare_ftype *ordered_compare)
static void print_partial_symbols(struct gdbarch *gdbarch, struct objfile *objfile, const std::vector< partial_symbol * > &symbols, const char *what, struct ui_file *outfile)
void _initialize_psymtab()
static bool recursively_search_psymtabs(struct partial_symtab *ps, struct objfile *objfile, block_search_flags search_flags, domain_enum domain, enum search_domain search, const lookup_name_info &lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > sym_matcher)
static void dump_psymtab(struct objfile *objfile, struct partial_symtab *psymtab, struct ui_file *outfile)
static bool psymbol_name_matches(partial_symbol *psym, const lookup_name_info &lookup_name)
static void maintenance_check_psymtabs(const char *ignore, int from_tty)
static struct partial_symbol * find_pc_sect_psymbol(struct objfile *, struct partial_symtab *, CORE_ADDR, struct obj_section *)
static void maintenance_info_psymtabs(const char *regexp, int from_tty)
static struct partial_symtab * find_pc_sect_psymtab_closer(struct objfile *objfile, CORE_ADDR pc, struct obj_section *section, struct partial_symtab *pst, struct bound_minimal_symbol msymbol)
static struct partial_symbol * lookup_partial_symbol(struct objfile *, struct partial_symtab *, const lookup_name_info &, int, domain_enum)
static void maintenance_print_psymbols(const char *args, int from_tty)
static const char * psymtab_to_fullname(struct partial_symtab *ps)
int() symbol_compare_ftype(const char *string1, const char *string2)
gdb::unique_xmalloc_ptr< char > find_source_or_rewrite(const char *filename, const char *dirname)
struct block * static_block()
struct block * global_block()
CORE_ADDR value_address() const
struct minimal_symbol * minsym
symtab * primary_filetab() const
struct blockvector * blockvector()
const void * insert(const void *addr, int length, bool *added=nullptr)
union general_symbol_info::@177 m_value
void set_section_index(short idx)
void compute_and_set_names(gdb::string_view linkage_name, bool copy_name, struct objfile_per_bfd_storage *per_bfd, gdb::optional< hashval_t > hash=gdb::optional< hashval_t >())
const char * search_name() const
enum language language() const
void set_language(enum language language, struct obstack *obstack)
const char * linkage_name() const
symbol_name_matcher_ftype * get_symbol_name_matcher(const lookup_name_info &lookup_name) const
const char * intern(const char *str)
const struct sym_fns * sf
struct gdbarch * arch() const
struct objfile_per_bfd_storage * per_bfd
std::forward_list< quick_symbol_functions_up > qf
__extension__ enum domain_enum domain
CORE_ADDR address(const struct objfile *objfile) const
struct general_symbol_info ginfo
__extension__ enum address_class aclass
void set_unrelocated_address(CORE_ADDR addr)
struct partial_symtab * user
virtual struct compunit_symtab * get_compunit_symtab(struct objfile *) const =0
struct partial_symtab ** dependencies
std::vector< partial_symbol * > static_psymbols
CORE_ADDR raw_text_low() const
partial_symtab(const char *filename, psymtab_storage *partial_symtabs, objfile_per_bfd_storage *objfile_per_bfd) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
__extension__ enum psymtab_search_status searched_flag
virtual bool readin_p(struct objfile *) const =0
void set_text_low(CORE_ADDR addr)
virtual void expand_psymtab(struct objfile *)=0
std::vector< partial_symbol * > global_psymbols
int number_of_dependencies
virtual void read_symtab(struct objfile *)=0
struct partial_symtab * next
CORE_ADDR text_high(struct objfile *objfile) const
void expand_dependencies(struct objfile *)
void add_psymbol(gdb::string_view name, bool copy_name, domain_enum domain, enum address_class theclass, short section, psymbol_placement where, CORE_ADDR coreaddr, enum language language, psymtab_storage *partial_symtabs, struct objfile *objfile)
void set_text_high(CORE_ADDR addr)
CORE_ADDR text_low(struct objfile *objfile) const
objfiles_range objfiles()
unsigned long hash(const void *addr, int length) override
int compare(const void *left, const void *right, int length) override
enum language lookup_global_symbol_language(struct objfile *objfile, const char *name, domain_enum domain, bool *symbol_found_p) override
struct compunit_symtab * find_pc_sect_compunit_symtab(struct objfile *objfile, struct bound_minimal_symbol msymbol, CORE_ADDR pc, struct obj_section *section, int warn_if_readin) override
void dump(struct objfile *objfile) override
void print_stats(struct objfile *objfile, bool print_bcache) override
void expand_matching_symbols(struct objfile *, const lookup_name_info &lookup_name, domain_enum domain, int global, symbol_compare_ftype *ordered_compare) override
struct compunit_symtab * find_compunit_symtab_by_address(struct objfile *objfile, CORE_ADDR address) override
void fill_psymbol_map(struct objfile *objfile, struct partial_symtab *psymtab, std::set< CORE_ADDR > *seen_addrs, const std::vector< partial_symbol * > &symbols)
void expand_all_symtabs(struct objfile *objfile) override
psymtab_storage::partial_symtab_range partial_symbols(struct objfile *objfile)
void forget_cached_source_info(struct objfile *objfile) override
void map_symbol_filenames(struct objfile *objfile, gdb::function_view< symbol_filename_ftype > fun, bool need_fullname) override
struct symtab * find_last_source_symtab(struct objfile *objfile) override
std::shared_ptr< psymtab_storage > m_partial_symtabs
bool has_unexpanded_symtabs(struct objfile *objfile) override
struct partial_symtab * find_pc_sect_psymtab(struct objfile *objfile, CORE_ADDR pc, struct obj_section *section, struct bound_minimal_symbol msymbol)
std::vector< std::pair< CORE_ADDR, partial_symtab * > > m_psymbol_map
bool expand_symtabs_matching(struct objfile *objfile, gdb::function_view< expand_symtabs_file_matcher_ftype > file_matcher, const lookup_name_info *lookup_name, gdb::function_view< expand_symtabs_symbol_matcher_ftype > symbol_matcher, gdb::function_view< expand_symtabs_exp_notify_ftype > expansion_notify, block_search_flags search_flags, domain_enum domain, enum search_domain kind) override
bool has_symbols(struct objfile *objfile) override
scoped_restore_tmpl< int > increment_reading_symtab(void)
bool symbol_matches_search_name(const struct general_symbol_info *gsymbol, const lookup_name_info &name)
bool compare_filenames_for_search(const char *filename, const char *search_name)
bool basenames_may_differ
bool matching_obj_sections(struct obj_section *obj_first, struct obj_section *obj_second)
bool symbol_matches_domain(enum language symbol_language, domain_enum symbol_domain, domain_enum domain)
unsigned int symtab_create_debug
bool() symbol_name_matcher_ftype(const char *symbol_search_name, const lookup_name_info &lookup_name, completion_match_result *comp_match_res)
#define symtab_create_debug_printf(fmt,...)
void perror_with_name(const char *string)
const char * paddress(struct gdbarch *gdbarch, CORE_ADDR addr)
int strcmp_iw_ordered(const char *string1, const char *string2)
void gdb_printf(struct ui_file *stream, const char *format,...)
void gdb_flush(struct ui_file *stream)
void gdb_puts(const char *linebuffer, struct ui_file *stream)
static unsigned int fast_hash(const void *ptr, size_t len, unsigned int start_value=0)