42#include "gdbsupport/selftest.h"
44#include "gdbsupport/thread-pool.h"
57 if (
query (_(
"Should GDB dump core? ")))
61 signal (SIGABRT, SIG_DFL);
62 kill (getpid (), SIGABRT);
64 signal (SIGQUIT, SIG_DFL);
65 kill (getpid (), SIGQUIT);
79 internal_error (
"%s", (args == NULL ?
"" : args));
90 internal_warning (
"%s", (args == NULL ?
"" : args));
109 gdb_printf (_(
"This command has been moved to \"demangle\".\n"));
115 if (args == NULL || *args ==
'\0')
116 gdb_printf (_(
"\"maintenance time\" takes a numeric argument.\n"));
124 if (args == NULL || *args ==
'\0')
125 gdb_printf (
"\"maintenance space\" takes a numeric argument.\n");
135 int substr_len = strlen (substr);
138 while ((tok = strstr (
string, substr)) != NULL)
146 if (tok[substr_len] ==
' '
147 || tok[substr_len] ==
'\t'
148 || tok[substr_len] ==
'\0')
178 {
"ALLOC", SEC_ALLOC },
179 {
"LOAD", SEC_LOAD },
180 {
"RELOC", SEC_RELOC },
181 {
"READONLY", SEC_READONLY },
182 {
"CODE", SEC_CODE },
183 {
"DATA", SEC_DATA },
185 {
"CONSTRUCTOR", SEC_CONSTRUCTOR },
186 {
"HAS_CONTENTS", SEC_HAS_CONTENTS },
187 {
"NEVER_LOAD", SEC_NEVER_LOAD },
188 {
"COFF_SHARED_LIBRARY", SEC_COFF_SHARED_LIBRARY },
189 {
"IS_COMMON", SEC_IS_COMMON }
199 gdb_assert (
string !=
nullptr);
226 CORE_ADDR addr, CORE_ADDR endaddr,
227 unsigned long filepos,
int addr_size)
229 gdb_printf (
" %s", hex_string_custom (addr, addr_size));
230 gdb_printf (
"->%s", hex_string_custom (endaddr, addr_size));
232 hex_string_custom ((
unsigned long) filepos, 8));
246 return ((
int) log10 ((
float) count)) + 1;
276 flagword
flags = bfd_section_flags (asect);
277 const char *
name = bfd_section_name (asect);
279 if (arg == NULL || *arg ==
'\0'
285 CORE_ADDR addr, endaddr;
287 addr = bfd_section_vma (asect);
288 endaddr = addr + bfd_section_size (asect);
291 asect->filepos, addr_size);
310 if (arg == NULL || *arg ==
'\0'
365 gdb_printf (
"`%s', ", bfd_get_filename (abfd));
367 gdb_printf (_(
"file type %s.\n"), bfd_get_target (abfd));
385 if (osect ==
nullptr)
405 N_(
"Display information from all loaded object files."),
423 const char *text,
const char * )
434 std::vector<const char *>
flags;
437 flags.push_back (
nullptr);
457 else if (opts.all_objects)
475 if (table ==
nullptr)
480 if (abfd ==
nullptr || sec.the_bfd_section->owner != abfd)
482 abfd = sec.the_bfd_section->owner;
493 if (sec.the_bfd_section->owner != abfd)
495 abfd = sec.the_bfd_section->owner;
500 bfd_get_filename (abfd), bfd_get_target (abfd));
508 gdb_printf (
"%*sStart: %s, End: %s, Owner token: %p\n",
510 hex_string_custom (sec.addr, addr_size),
511 hex_string_custom (sec.endaddr, addr_size),
533 if (!file.open (args,
"w"))
534 perror_with_name (_(
"maintenance print architecture"));
552 if (arg == NULL || *arg == 0)
553 error (_(
"requires argument (address or section + address)"));
560 while (*p && !isspace (*p))
563 error (_(
"Need to specify section name and address"));
565 int arg_len = p - arg;
566 p = skip_spaces (p + 1);
571 if (strncmp (iter->the_bfd_section->name, arg, arg_len) == 0)
575 error (_(
"Unknown section %s."), arg);
589 const char *symbol_offset
595 const char *section_name;
596 const char *obj_name;
605 gdb_printf (_(
"%s + %s in section %s of %s\n"),
606 symbol_name, symbol_offset,
607 section_name, obj_name);
610 symbol_name, symbol_offset, section_name);
613 gdb_printf (_(
"%s + %s\n"), symbol_name, symbol_offset);
619 gdb_printf (_(
"no symbol at %s\n"), hex_string (address));
632 if (args == NULL || *args ==
'\0')
634 gdb_printf (_(
"\"maintenance deprecate\" takes an argument,\n\
635the command you want to deprecate, and optionally the replacement command\n\
636enclosed in quotes.\n"));
646 if (args == NULL || *args ==
'\0')
648 gdb_printf (_(
"\"maintenance undeprecate\" takes an argument, \n\
649the command you want to undeprecate.\n"));
669 const char *start_ptr = NULL;
670 const char *end_ptr = NULL;
679 gdb_printf (_(
"Can't find command '%s' to deprecate.\n"), text);
686 start_ptr = strchr (text,
'\"');
687 if (start_ptr != NULL)
690 end_ptr = strrchr (start_ptr,
'\"');
693 len = end_ptr - start_ptr;
699 if (!start_ptr || !end_ptr)
710 if (
alias->malloced_replacement)
715 alias->deprecated_warn_user = 1;
716 alias->cmd_deprecated = 1;
720 alias->deprecated_warn_user = 0;
721 alias->cmd_deprecated = 0;
724 alias->malloced_replacement = 1;
767 const char *text,
const char * )
784#define TEXTEND &_etext
785#elif defined (HAVE_ETEXT)
787#define TEXTEND &etext
790#if defined (HAVE_MONSTARTUP) && defined (HAVE__MCLEANUP) && defined (TEXTEND)
792static int profiling_state;
794EXTERN_C
void _mcleanup (
void);
797mcleanup_wrapper (
void)
803EXTERN_C
void monstartup (
unsigned long,
unsigned long);
804extern int main (
int,
char **);
817 static int profiling_initialized;
819 if (!profiling_initialized)
821 atexit (mcleanup_wrapper);
822 profiling_initialized = 1;
827 monstartup ((
unsigned long) &
main, (
unsigned long) TEXTEND);
831 extern void _mcleanup (
void);
841 error (_(
"Profiling support is not available on this system."));
855 n_threads = std::thread::hardware_concurrency ();
857 gdb::thread_pool::g_thread_pool->set_thread_count (n_threads);
876 gdb_printf (file, _(
"The number of worker threads GDB "
877 "can use is unlimited (currently %zu).\n"),
883 int report_threads = 0;
887 gdb_printf (file, _(
"The number of worker threads GDB "
935 int nr_compunit_symtabs = 0;
947 ++nr_compunit_symtabs;
948 nr_blocks += cu->blockvector ()->num_blocks ();
949 nr_symtabs += std::distance (cu->filetabs ().begin (),
950 cu->filetabs ().end ());
955 *nr_symtabs_ptr = nr_symtabs;
956 *nr_compunit_symtabs_ptr = nr_compunit_symtabs;
957 *nr_blocks_ptr = nr_blocks;
982 using namespace std::chrono;
984 run_time_clock::duration cmd_time
987 steady_clock::duration wall_time
994 ? _(
"Startup time: %.6f (cpu), %.6f (wall)\n")
995 : _(
"Command execution time: %.6f (cpu), %.6f (wall)\n"),
996 duration<double> (cmd_time).count (),
997 duration<double> (wall_time).count ());
1002#ifdef HAVE_USEFUL_SBRK
1003 char *lim = (
char *) sbrk (0);
1010 ? _(
"Space used: %ld (%s%ld during startup)\n")
1011 : _(
"Space used: %ld (%s%ld for this command)\n"),
1013 (space_diff >= 0 ?
"+" :
""),
1020 int nr_symtabs, nr_compunit_symtabs, nr_blocks;
1024 _(
"#symtabs: %d (+%d),"
1025 " #compunits: %d (+%d),"
1026 " #blocks: %d (+%d)\n"),
1029 nr_compunit_symtabs,
1030 (nr_compunit_symtabs
1038: m_msg_type (msg_type)
1042#ifdef HAVE_USEFUL_SBRK
1043 char *lim = (
char *) sbrk (0);
1053 using namespace std::chrono;
1067 int nr_symtabs, nr_compunit_symtabs, nr_blocks;
1087 using namespace std::chrono;
1089 auto now = system_clock::now ();
1090 auto ticks = now.time_since_epoch ().count () / (1000 * 1000);
1091 auto millis = ticks % 1000;
1093 std::time_t as_time = system_clock::to_time_t (now);
1095 localtime_r (&as_time, &tm);
1098 strftime (out,
sizeof (out),
"%F %H:%M:%S", &tm);
1114 error (_(
"Bad value for 'mt set per-command no'."));
1136 N_(
"Set whether selftests run in verbose mode."),
1137 N_(
"Show whether selftests run in verbose mode."),
1139When on, selftests may print verbose information."),
1145static std::array<gdb::option::option_def_group, 1>
1163 const gdb_argv argv (args);
1164 selftests::run_tests (argv.as_array_view (), opts.verbose);
1167Selftests have been disabled for this build.\n"));
1186 for (
const auto &test : selftests::all_selftests ())
1188 if (startswith (test.name.c_str (), text))
1189 tracker.
add_completion (make_unique_xstrdup (test.name.c_str ()));
1199 for (
const auto &test : selftests::all_selftests ())
1203Selftests have been disabled for this build.\n"));
1216Commands for use by GDB maintainers.\n\
1217Includes commands to dump specific internal GDB structures in\n\
1218a human readable form, to cause GDB to deliberately dump core, etc."),
1226Commands for showing internal info about the program being debugged."),
1233 static std::string maint_info_sections_command_help
1235List the BFD sections of the exec and core files.\n\
1237Usage: maintenance info sections [-all-objects] [FILTERS]\n\
1239FILTERS is a list of words, each word is either:\n\
1240 + A section name - any section with this name will be printed, or\n\
1241 + A section flag - any section with this flag will be printed. The\n\
1243 ALLOC LOAD RELOC READONLY CODE DATA ROM CONSTRUCTOR\n\
1244 HAS_CONTENTS NEVER_LOAD COFF_SHARED_LIBRARY IS_COMMON\n\
1246Sections matching any of the FILTERS will be listed (no FILTERS implies\n\
1247all sections should be printed).\n\
1252 maint_info_sections_command_help.c_str (),
1258List GDB's internal section table.\n\
1260Print the current targets section list. This is a sub-set of all\n\
1261sections, from all objects currently loaded. Usually the ALLOC\n\
1266 _(
"Maintenance command for printing GDB internal state."),
1271 _(
"Maintenance command for flushing GDB internal caches."),
1276Set GDB internal variables used by the GDB maintainer.\n\
1277Configure variables internal to GDB that aid in GDB's maintenance"),
1283Show GDB internal variables used by the GDB maintainer.\n\
1284Configure variables internal to GDB that aid in GDB's maintenance"),
1290Like \"with\", but works with \"maintenance set\" variables.\n\
1291Usage: maintenance with SETTING [VALUE] [-- COMMAND]\n\
1292With no COMMAND, repeats the last executed command.\n\
1293SETTING is any setting you can change with the \"maintenance set\"\n\
1300Get fatal error; make debugger dump its core.\n\
1301GDB sets its handling of SIGQUIT back to SIG_DFL and then sends\n\
1302itself a SIGQUIT signal."),
1308Give GDB an internal error.\n\
1309Cause GDB to behave as if an internal error was detected."),
1314Give GDB an internal warning.\n\
1315Cause GDB to behave as if an internal warning was reported."),
1320Give GDB a demangler warning.\n\
1321Cause GDB to behave as if a demangler warning was reported."),
1325This command has been moved to \"demangle\"."),
1330Per-command statistics settings."),
1335Show per-command statistics settings."),
1341Set whether to display per-command execution time."), _(
"\
1342Show whether to display per-command execution time."),
1344If enabled, the execution time for each command will be\n\
1345displayed following the command's output."),
1351Set whether to display per-command space usage."), _(
"\
1352Show whether to display per-command space usage."),
1354If enabled, the space usage for each command will be\n\
1355displayed following the command's output."),
1361Set whether to display per-command symtab statistics."), _(
"\
1362Show whether to display per-command symtab statistics."),
1364If enabled, the basic symtab statistics for each command will be\n\
1365displayed following the command's output."),
1372Set the display of time usage.\n\
1373If nonzero, will cause the execution time for each command to be\n\
1374displayed, following the command's output."),
1380Set the display of space usage.\n\
1381If nonzero, will cause the execution space for each command to be\n\
1382displayed, following the command's output."),
1386Print a type chain for a given symbol.\n\
1387For each node in a type chain, print the raw data for each member of\n\
1388the type structure, and the interpretation of the data."),
1393 _(
"Print statistics about internal gdb state."),
1398Print the internal architecture configuration.\n\
1399Takes an optional file parameter."),
1403Commands for checking internal gdb state."),
1409 _(
"Translate a section name and address to a symbol."),
1413Deprecate a command (for testing purposes).\n\
1414Usage: maintenance deprecate COMMANDNAME [\"REPLACEMENT\"]\n\
1415This is used by the testsuite to check the command deprecator.\n\
1416You probably shouldn't use this,\n\
1417rather you should use the C function deprecate_cmd()."), &
maintenancelist);
1420Undeprecate a command (for testing purposes).\n\
1421Usage: maintenance undeprecate COMMANDNAME\n\
1422This is used by the testsuite to check the command deprecator.\n\
1423You probably shouldn't use this."),
1428Run gdb's unit tests.\n\
1429Usage: maintenance selftest [FILTER]\n\
1430This will run any unit tests that were built in to gdb.\n\
1431If a filter is given, only the tests with that value in their name will ran."),
1441Set internal profiling."), _(
"\
1442Show internal profiling."), _(
"\
1443When enabled GDB is profiled."),
1452Set the number of worker threads GDB can use."), _(
"\
1453Show the number of worker threads GDB can use."), _(
"\
1454GDB may use multiple threads to speed up certain CPU-intensive operations,\n\
1455such as demangling symbol names."),
1466 _(
"Self tests-related settings."),
1467 _(
"Self tests-related settings."),
1468 &set_selftest_cmdlist, &show_selftest_cmdlist,
1475 &set_selftest_cmdlist,
1476 &show_selftest_cmdlist);
struct gdbarch * gdbarch_from_bfd(bfd *abfd)
struct gdbarch * get_current_arch(void)
void add_completion(gdb::unique_xmalloc_ptr< char > name, completion_match_for_lcd *match_for_lcd=NULL, const char *text=NULL, const char *word=NULL)
std::chrono::steady_clock::time_point m_start_wall_time
void print_time(const char *msg)
run_time_clock::time_point m_start_cpu_time
int m_start_nr_compunit_symtabs
scoped_command_stats(bool msg_type)
struct cmd_list_element * maintenanceprintlist
struct cmd_list_element * maintenancechecklist
struct cmd_list_element * cmdlist
struct cmd_list_element * maintenanceflushlist
struct cmd_list_element * maintenancelist
void with_command_completer_1(const char *set_cmd_prefix, completion_tracker &tracker, const char *text)
void with_command_1(const char *set_cmd_prefix, cmd_list_element *setlist, const char *args, int from_tty)
struct cmd_list_element * maintenanceinfolist
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
void set_cmd_completer_handle_brkchars(struct cmd_list_element *cmd, completer_handle_brkchars_ftype *func)
cmd_list_element * add_com_alias(const char *name, cmd_list_element *target, command_class theclass, int abbrev_flag)
void set_cmd_completer(struct cmd_list_element *cmd, completer_ftype *completer)
struct cmd_list_element * add_show_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
set_show_commands add_setshow_zuinteger_unlimited_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * deprecate_cmd(struct cmd_list_element *cmd, const char *replacement)
set_show_commands add_setshow_prefix_cmd(const char *name, command_class theclass, const char *set_doc, const char *show_doc, cmd_list_element **set_subcommands_list, cmd_list_element **show_subcommands_list, cmd_list_element **set_list, cmd_list_element **show_list)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_simple_func_ftype *fun, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
int lookup_cmd_composition(const char *text, struct cmd_list_element **alias, struct cmd_list_element **prefix_cmd, struct cmd_list_element **cmd)
void complete_on_enum(completion_tracker &tracker, const char *const *enumlist, const char *text, const char *word)
struct cmd_list_element * add_basic_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
void do_set_command(const char *arg, int from_tty, struct cmd_list_element *c)
int parse_cli_boolean_value(const char **arg)
void expression_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *word)
const char * advance_to_expression_complete_word_point(completion_tracker &tracker, const char *text)
CORE_ADDR parse_and_eval_address(const char *exp)
int gdb_bfd_section_index(bfd *abfd, asection *section)
int gdb_bfd_count_sections(bfd *abfd)
static gdb_bfd_section_range gdb_bfd_sections(bfd *abfd)
int gdbarch_addr_bit(struct gdbarch *gdbarch)
void gdbarch_dump(struct gdbarch *gdbarch, struct ui_file *file)
int thread_count(process_stratum_target *proc_target)
void maintenance_print_type(const char *, int)
mach_port_t kern_return_t mach_port_t mach_msg_type_name_t msgportsPoly mach_port_t kern_return_t pid_t pid mach_port_t kern_return_t mach_port_t task mach_port_t kern_return_t int flags
struct inferior * current_inferior(void)
static void maintenance_info_sections(const char *arg, int from_tty)
static void maintenance_internal_warning(const char *args, int from_tty)
static void maintenance_info_selftests(const char *arg, int from_tty)
static struct cmd_list_element * per_command_showlist
static bool maintenance_profile_p
static void maintenance_selftest_completer(cmd_list_element *cmd, completion_tracker &tracker, const char *text, const char *word)
struct cmd_list_element * maintenance_show_cmdlist
static void print_objfile_section_info(bfd *abfd, struct obj_section *asect, const char *arg, int index_digits)
static std::array< gdb::option::option_def_group, 1 > make_maintenance_selftest_option_group(maintenance_selftest_options *opts)
static void print_bfd_flags(flagword flags)
static void maintenance_translate_address(const char *arg, int from_tty)
static void maintenance_dump_me(const char *args, int from_tty)
static void maintenance_deprecate(const char *args, int from_tty)
static void maintenance_selftest(const char *args, int from_tty)
static void maint_info_sections_completer(struct cmd_list_element *cmd, completion_tracker &tracker, const char *text, const char *)
void _initialize_maint_cmds()
static void maintenance_set_worker_threads(const char *args, int from_tty, struct cmd_list_element *c)
static const single_bfd_flag_info bfd_flag_info[]
static bool per_command_symtab
static void maintenance_demangler_warning(const char *args, int from_tty)
static void maintenance_show_worker_threads(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static void update_thread_pool_size()
static void maintenance_print_architecture(const char *args, int from_tty)
static void set_per_command_cmd(const char *args, int from_tty)
static bool match_substring(const char *string, const char *substr)
static void maintenance_demangle(const char *args, int from_tty)
static void maintenance_info_target_sections(const char *arg, int from_tty)
static void maintenance_undeprecate(const char *args, int from_tty)
static void print_bfd_section_info(bfd *abfd, asection *asect, const char *arg, int index_digits)
static void maintenance_with_cmd(const char *args, int from_tty)
static void maint_print_all_sections(const char *header, bfd *abfd, objfile *objfile, const char *arg)
static void maintenance_with_cmd_completer(struct cmd_list_element *ignore, completion_tracker &tracker, const char *text, const char *)
static const gdb::option::option_def maint_info_sections_option_defs[]
static const gdb::option::option_def maintenance_selftest_option_defs[]
struct cmd_list_element * maintenance_set_cmdlist
void set_per_command_space(int new_value)
static void maintenance_time_display(const char *args, int from_tty)
static void maintenance_print_statistics(const char *args, int from_tty)
static int n_worker_threads
static void show_maintenance_profile_p(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static int index_digits(int count)
static gdb::option::option_def_group make_maint_info_sections_options_def_group(maint_info_sections_opts *cc_opts)
void set_per_command_time(int new_value)
static void maintenance_set_profile_cmd(const char *args, int from_tty, struct cmd_list_element *c)
static void maint_print_section_info(const char *name, flagword flags, CORE_ADDR addr, CORE_ADDR endaddr, unsigned long filepos, int addr_size)
struct maintenance_selftest_options user_maintenance_selftest_options
static bool per_command_space
static void count_symtabs_and_blocks(int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr, int *nr_blocks_ptr)
obj_section * maint_obj_section_from_bfd_section(bfd *abfd, asection *asection, objfile *ofile)
static bool match_bfd_flags(const char *string, flagword flags)
static void maintenance_internal_error(const char *args, int from_tty)
static void print_section_index(bfd *abfd, asection *asect, int index_digits)
static struct cmd_list_element * per_command_setlist
static void maintenance_space_display(const char *args, int from_tty)
static bool per_command_time
static void maintenance_do_deprecate(const char *, int)
bound_minimal_symbol lookup_minimal_symbol_by_pc_section(CORE_ADDR pc_in, struct obj_section *section, lookup_msym_prefer prefer, bound_minimal_symbol *previous)
struct bound_minimal_symbol lookup_minimal_symbol_by_pc(CORE_ADDR pc)
bool process_options(const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
@ PROCESS_OPTIONS_UNKNOWN_IS_ERROR
std::string build_help(const char *help_tmpl, gdb::array_view< const option_def_group > options_group)
bool complete_options(completion_tracker &tracker, const char **args, process_options_mode mode, gdb::array_view< const option_def_group > options_group)
void add_setshow_cmds_for_options(command_class cmd_class, void *data, gdb::array_view< const option_def > options, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
const char * objfile_name(const struct objfile *objfile)
void print_objfile_statistics(void)
struct program_space * current_program_space
CORE_ADDR value_address() const
struct minimal_symbol * minsym
struct obj_section * obj_section() const
gdb::optional< setting > var
unsigned int cmd_deprecated
unsigned int deprecated_warn_user
__extension__ enum cmd_types type
struct cmd_list_element * next
unsigned int malloced_replacement
const char * print_name() const
CORE_ADDR endaddr() const
struct bfd_section * the_bfd_section
struct obj_section * sections_start
iterator_range< section_iterator > sections()
struct obj_section * sections_end
objfiles_range objfiles()
bool multi_objfile_p() const
std::vector< target_section > target_section_table
const target_section_table * target_get_section_table(struct target_ops *target)
void demangler_warning(const char *file, int line, const char *string,...)
std::chrono::steady_clock::duration get_prompt_for_continue_wait_time()
int query(const char *ctlstr,...)
void reset_prompt_for_continue_wait_time(void)
void gdb_printf(struct ui_file *stream, const char *format,...)
void gdb_puts(const char *linebuffer, struct ui_file *stream)