31#include "readline/tilde.h"
32#include "gdbsupport/gdb_regex.h"
39#include "gdbsupport/buildargv.h"
60 while (iter !=
nullptr)
105 if (section ==
nullptr)
108 if (msymbol.
minsym == NULL)
118 for (tpst = pst; tpst != NULL; tpst = tpst->
next)
153 if (this_addr > best_addr)
155 best_addr = this_addr;
172 if (pc >= pst->text_low (
objfile) && pc < pst->text_high (
objfile))
178 if (best_pst != NULL)
206(Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
226 gdb_assert (psymtab != NULL);
229 best_pc = (textlow != 0) ? textlow - 1 : 0;
239 && (p->address (
objfile) > best_pc
241 && best_pc == 0 && p->address (
objfile) == 0)))
249 best_pc = p->address (
objfile);
259 && (p->address (
objfile) > best_pc
261 && best_pc == 0 && p->address (
objfile) == 0)))
284 bool *symbol_found_p)
286 *symbol_found_p =
false;
301 *symbol_found_p =
true;
340 int do_linear_search = 1;
349 if (global && ordered_compare)
351 do_linear_search = 0;
360 top = start + length - 1;
364 center = bottom + (top - bottom) / 2;
365 gdb_assert (center < top);
367 enum language lang = (*center)->ginfo.language ();
368 const char *lang_ln =
name.language_lookup_name (lang);
370 if (ordered_compare ((*center)->ginfo.search_name (),
376 gdb_assert (top == bottom);
378 while (top <= real_top
391 if (do_linear_search)
393 for (psym = start; psym < start + length; psym++)
420 int do_linear_search = 1;
431 do_linear_search = 0;
440 top = start + length - 1;
444 center = bottom + (top - bottom) / 2;
446 gdb_assert (center < top);
449 lookup_name.
c_str ()) >= 0)
459 gdb_assert (top == bottom);
483 if (do_linear_search)
485 for (psym = start; psym < start + length; psym++)
508 while (pst->
user != NULL)
522 gdb_printf (_(
"Reading in symbols for %s...\n"),
544 int len = strlen (
name);
546 if (!(len > 2 && (strcmp (&
name[len - 2],
".h") == 0
547 || strcmp (
name,
"<<C++-namespaces>>") == 0)))
555 internal_error (_(
"select_source_symtab: "
556 "readin pst found and no symtabs."));
578 if (pst->fullname != NULL)
580 xfree (pst->fullname);
581 pst->fullname = NULL;
588 const std::vector<partial_symbol *> &symbols,
589 const char *what,
struct ui_file *outfile)
591 gdb_printf (outfile,
" %s partial symbols:\n", what);
595 gdb_printf (outfile,
" `%s'", p->ginfo.linkage_name ());
596 if (p->ginfo.demangled_name () != NULL)
599 p->ginfo.demangled_name ());
605 gdb_puts (
"undefined domain, ", outfile);
611 gdb_puts (
"struct domain, ", outfile);
614 gdb_puts (
"module domain, ", outfile);
617 gdb_puts (
"label domain, ", outfile);
620 gdb_puts (
"common block domain, ", outfile);
623 gdb_puts (
"<invalid domain>, ", outfile);
641 gdb_puts (
"pass by value", outfile);
644 gdb_puts (
"pass by reference", outfile);
647 gdb_puts (
"register address parameter", outfile);
650 gdb_puts (
"stack parameter", outfile);
662 gdb_puts (
"constant bytes", outfile);
668 gdb_puts (
"optimized out", outfile);
671 gdb_puts (
"computed at runtime", outfile);
674 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))
1114 unrelocated_addr textlow)
1134 return strcmp_iw_ordered (s1->ginfo.search_name (),
1135 s2->ginfo.search_name ()) < 0;
1144 unsigned long h = 0;
1147 unsigned int domain = psymbol->
domain;
1148 unsigned int theclass = psymbol->
aclass;
1151 h = fast_hash (&lang,
sizeof (
unsigned int), h);
1152 h = fast_hash (&domain,
sizeof (
unsigned int), h);
1153 h = fast_hash (&theclass,
sizeof (
unsigned int), h);
1201 std::vector<partial_symbol *> &list
1205 list.push_back (psym);
1216 unrelocated_addr coreaddr,
1222 memset (&psymbol, 0,
sizeof (psymbol));
1227 psymbol.
aclass = theclass;
1251 static std::string last_bfd_name;
1252 const char *this_bfd_name
1253 = bfd_get_filename (objfile_per_bfd->
get_bfd ());
1255 if (last_bfd_name.empty () || last_bfd_name != this_bfd_name)
1257 last_bfd_name = this_bfd_name;
1264 host_address_to_string (
this),
filename);
1309 while ((*prev_pst) != pst)
1310 prev_pst = &((*prev_pst)->next);
1311 (*prev_pst) = pst->
next;
1321 char *address_arg = NULL, *source_arg = NULL, *objfile_arg = NULL;
1322 int i, outfile_idx, found;
1328 gdb_argv argv (args);
1330 for (i = 0; argv != NULL && argv[i] != NULL; ++i)
1332 if (strcmp (argv[i],
"-pc") == 0)
1334 if (argv[i + 1] == NULL)
1335 error (_(
"Missing pc value"));
1336 address_arg = argv[++i];
1338 else if (strcmp (argv[i],
"-source") == 0)
1340 if (argv[i + 1] == NULL)
1341 error (_(
"Missing source file"));
1342 source_arg = argv[++i];
1344 else if (strcmp (argv[i],
"-objfile") == 0)
1346 if (argv[i + 1] == NULL)
1347 error (_(
"Missing objfile name"));
1348 objfile_arg = argv[++i];
1350 else if (strcmp (argv[i],
"--") == 0)
1356 else if (argv[i][0] ==
'-')
1359 error (_(
"Unknown option: %s"), argv[i]);
1366 if (address_arg != NULL && source_arg != NULL)
1367 error (_(
"Must specify at most one of -pc and -source"));
1371 if (argv != NULL && argv[outfile_idx] != NULL)
1373 if (argv[outfile_idx + 1] != NULL)
1374 error (_(
"Junk at end of command"));
1375 gdb::unique_xmalloc_ptr<char> outfile_name
1376 (tilde_expand (argv[outfile_idx]));
1377 if (!arg_outfile.
open (outfile_name.get (), FOPEN_WT))
1378 perror_with_name (outfile_name.get ());
1379 outfile = &arg_outfile;
1382 if (address_arg != NULL)
1392 int printed_objfile_header = 0;
1393 int print_for_objfile = 1;
1396 if (objfile_arg != NULL)
1400 if (!print_for_objfile)
1410 if (address_arg != NULL)
1420 if (!printed_objfile_header)
1422 outfile->
printf (
"\nPartial symtabs for objfile %s\n",
1424 printed_objfile_header = 1;
1434 int print_for_source = 0;
1437 if (source_arg != NULL)
1443 if (source_arg == NULL
1444 || print_for_source)
1446 if (!printed_objfile_header)
1448 outfile->
printf (
"\nPartial symtabs for objfile %s\n",
1450 printed_objfile_header = 1;
1461 if (address_arg != NULL)
1462 error (_(
"No partial symtab for address: %s"), address_arg);
1463 if (source_arg != NULL)
1464 error (_(
"No partial symtab for source file: %s"), source_arg);
1483 int printed_objfile_start = 0;
1496 || re_exec (psymtab->filename))
1498 if (! printed_objfile_start)
1503 host_address_to_string (
objfile));
1504 printed_objfile_start = 1;
1507 gdb_printf (
" { psymtab %s ", psymtab->filename);
1509 gdb_printf (
"((struct partial_symtab *) %s)\n",
1510 host_address_to_string (psymtab));
1513 psymtab->readin_p (
objfile) ?
"yes" :
"no");
1516 ? psymtab->fullname :
"(null)");
1519 psymtab->text_low (
objfile)));
1522 psymtab->text_high (
objfile)));
1525 if (!psymtab->global_psymbols.empty ())
1527 (
"(* (struct partial_symbol **) %s @ %d)\n",
1528 host_address_to_string (psymtab->global_psymbols.data ()),
1529 (
int) psymtab->global_psymbols.size ());
1533 if (!psymtab->static_psymbols.empty ())
1535 (
"(* (struct partial_symbol **) %s @ %d)\n",
1536 host_address_to_string (psymtab->static_psymbols.data ()),
1537 (
int) psymtab->static_psymbols.size ());
1542 "((struct partial_symtab *) %s)\n",
1543 psymtab->user->filename,
1544 host_address_to_string (psymtab->user));
1546 if (psymtab->number_of_dependencies)
1551 for (i = 0; i < psymtab->number_of_dependencies; i++)
1558 "((struct partial_symtab *) %s)\n",
1560 host_address_to_string (dep));
1571 if (printed_objfile_start)
1584 const struct block *b;
1602 cust = ps->get_compunit_symtab (
objfile);
1627 && psym->ginfo.value_address () == 0)
1636 gdb_puts (psym->ginfo.linkage_name ());
1651 gdb_puts (psym->ginfo.linkage_name ());
1657 if (ps->unrelocated_text_high () != unrelocated_addr (0)
1683Print dump of current partial symbol definitions.\n\
1684Usage: mt print psymbols [-objfile OBJFILE] [-pc ADDRESS] [--] [OUTFILE]\n\
1685 mt print psymbols [-objfile OBJFILE] [-source SOURCE] [--] [OUTFILE]\n\
1686Entries in the partial symbol table are dumped to file OUTFILE,\n\
1687or the terminal if OUTFILE is unspecified.\n\
1688If ADDRESS is provided, dump only the symbols for the file with code at that address.\n\
1689If SOURCE is provided, dump only that file's symbols.\n\
1690If OBJFILE is provided, dump only that object file's symbols."),
1694List the partial symbol tables for all object files.\n\
1695This does not include information about individual partial symbols,\n\
1696just the symbol table structures themselves."),
1701Check 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
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)
@ PST_SEARCHED_AND_NOT_FOUND
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)
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
union general_symbol_info::@182 m_value
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
void set_unrelocated_address(unrelocated_addr addr)
__extension__ enum domain_enum domain
CORE_ADDR address(const struct objfile *objfile) const
struct general_symbol_info ginfo
__extension__ enum address_class aclass
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
unrelocated_addr unrelocated_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_high(unrelocated_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 set_text_low(unrelocated_addr addr)
void add_psymbol(gdb::string_view name, bool copy_name, domain_enum domain, enum address_class theclass, short section, psymbol_placement where, unrelocated_addr coreaddr, enum language language, psymtab_storage *partial_symtabs, struct objfile *objfile)
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
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)
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,...)
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)