/* Support for GDB maintenance commands.
- Copyright (C) 1992-2017 Free Software Foundation, Inc.
+ Copyright (C) 1992-2019 Free Software Foundation, Inc.
Written by Fred Fish at Cygnus Support.
#include "value.h"
#include "top.h"
#include "maint.h"
-#include "selftest.h"
+#include "common/selftest.h"
#include "cli/cli-decode.h"
#include "cli/cli-utils.h"
#include "cli/cli-setshow.h"
-static void maintenance_command (char *, int);
-
-static void maintenance_internal_error (char *args, int from_tty);
-
-static void maintenance_space_display (char *, int);
-
-static void maintenance_info_command (char *, int);
-
-static void maintenance_print_command (char *, int);
-
static void maintenance_do_deprecate (const char *, int);
-/* Set this to the maximum number of seconds to wait instead of waiting forever
- in target_wait(). If this timer times out, then it generates an error and
- the command is aborted. This replaces most of the need for timeouts in the
- GDB test suite, and makes it possible to distinguish between a hung target
- and one with slow communications. */
-
-int watchdog = 0;
-static void
-show_watchdog (struct ui_file *file, int from_tty,
- struct cmd_list_element *c, const char *value)
-{
- fprintf_filtered (file, _("Watchdog timer is %s.\n"), value);
-}
-
/* Access the maintenance subcommands. */
static void
-maintenance_command (char *args, int from_tty)
+maintenance_command (const char *args, int from_tty)
{
printf_unfiltered (_("\"maintenance\" must be followed by "
"the name of a maintenance command.\n"));
GDB. */
static void
-maintenance_internal_error (char *args, int from_tty)
+maintenance_internal_error (const char *args, int from_tty)
{
internal_error (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
}
GDB. */
static void
-maintenance_internal_warning (char *args, int from_tty)
+maintenance_internal_warning (const char *args, int from_tty)
{
internal_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
}
demangler problem is detected. Allows testing of the mechanism. */
static void
-maintenance_demangler_warning (char *args, int from_tty)
+maintenance_demangler_warning (const char *args, int from_tty)
{
demangler_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
}
}
static void
-maintenance_space_display (char *args, int from_tty)
+maintenance_space_display (const char *args, int from_tty)
{
if (args == NULL || *args == '\0')
printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
"maintenance info" with no args. */
static void
-maintenance_info_command (char *arg, int from_tty)
+maintenance_info_command (const char *arg, int from_tty)
{
printf_unfiltered (_("\"maintenance info\" must be followed "
"by the name of an info command.\n"));
"maintenance check" with no args. */
static void
-maintenance_check_command (char *arg, int from_tty)
+maintenance_check_command (const char *arg, int from_tty)
{
printf_unfiltered (_("\"maintenance check\" must be followed "
"by the name of a check command.\n"));
printf_filtered (_("file type %s.\n"), bfd_get_target (exec_bfd));
if (arg && *arg && match_substring (arg, "ALLOBJ"))
{
- struct objfile *ofile;
struct obj_section *osect;
/* Only this function cares about the 'ALLOBJ' argument;
if (strcmp (arg, "ALLOBJ") == 0)
arg = NULL;
- ALL_OBJFILES (ofile)
+ for (objfile *ofile : current_program_space->objfiles ())
{
printf_filtered (_(" Object file: %s\n"),
bfd_get_filename (ofile->obfd));
}
static void
-maintenance_print_architecture (char *args, int from_tty)
+maintenance_print_architecture (const char *args, int from_tty)
{
struct gdbarch *gdbarch = get_current_arch ();
"maintenance print" with no args. */
static void
-maintenance_print_command (char *arg, int from_tty)
+maintenance_print_command (const char *arg, int from_tty)
{
printf_unfiltered (_("\"maintenance print\" must be followed "
"by the name of a print command.\n"));
or maintenance translate-address <addr>. */
static void
-maintenance_translate_address (char *arg, int from_tty)
+maintenance_translate_address (const char *arg, int from_tty)
{
CORE_ADDR address;
struct obj_section *sect;
- char *p;
+ const char *p;
struct bound_minimal_symbol sym;
- struct objfile *objfile;
if (arg == NULL || *arg == 0)
error (_("requires argument (address or section + address)"));
while (*p && !isspace (*p)) /* Find end of section name. */
p++;
if (*p == '\000') /* End of command? */
- error (_("Need to specify <section-name> and <address>"));
- *p++ = '\000';
- p = skip_spaces (p);
+ error (_("Need to specify section name and address"));
- ALL_OBJSECTIONS (objfile, sect)
- {
- if (strcmp (sect->the_bfd_section->name, arg) == 0)
- break;
- }
+ int arg_len = p - arg;
+ p = skip_spaces (p + 1);
- if (!objfile)
- error (_("Unknown section %s."), arg);
+ for (objfile *objfile : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile, sect)
+ {
+ if (strncmp (sect->the_bfd_section->name, arg, arg_len) == 0)
+ goto found;
+ }
+
+ error (_("Unknown section %s."), arg);
+ found: ;
}
address = parse_and_eval_address (p);
struct cmd_list_element *maintenance_show_cmdlist;
static void
-maintenance_set_cmd (char *args, int from_tty)
+maintenance_set_cmd (const char *args, int from_tty)
{
printf_unfiltered (_("\"maintenance set\" must be followed "
"by the name of a set command.\n"));
}
static void
-maintenance_show_cmd (char *args, int from_tty)
+maintenance_show_cmd (const char *args, int from_tty)
{
cmd_show_list (maintenance_show_cmdlist, from_tty, "");
}
extern int main ();
static void
-maintenance_set_profile_cmd (char *args, int from_tty,
+maintenance_set_profile_cmd (const char *args, int from_tty,
struct cmd_list_element *c)
{
if (maintenance_profile_p == profiling_state)
}
#else
static void
-maintenance_set_profile_cmd (char *args, int from_tty,
+maintenance_set_profile_cmd (const char *args, int from_tty,
struct cmd_list_element *c)
{
error (_("Profiling support is not available on this system."));
count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
int *nr_blocks_ptr)
{
- struct objfile *o;
- struct compunit_symtab *cu;
- struct symtab *s;
int nr_symtabs = 0;
int nr_compunit_symtabs = 0;
int nr_blocks = 0;
current_program_space may be NULL. */
if (current_program_space != NULL)
{
- ALL_COMPUNITS (o, cu)
+ for (objfile *o : current_program_space->objfiles ())
{
- ++nr_compunit_symtabs;
- nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
- ALL_COMPUNIT_FILETABS (cu, s)
- ++nr_symtabs;
+ for (compunit_symtab *cu : o->compunits ())
+ {
+ ++nr_compunit_symtabs;
+ nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
+ nr_symtabs += std::distance (compunit_filetabs (cu).begin (),
+ compunit_filetabs (cu).end ());
+ }
}
}
if (m_time_enabled && per_command_time)
{
+ print_time (_("command finished"));
+
using namespace std::chrono;
run_time_clock::duration cmd_time
if (m_space_enabled && per_command_space)
{
-#ifdef HAVE_SBRK
+#ifdef HAVE_USEFUL_SBRK
char *lim = (char *) sbrk (0);
long space_now = lim - lim_at_start;
{
if (!m_msg_type || per_command_space)
{
-#ifdef HAVE_SBRK
+#ifdef HAVE_USEFUL_SBRK
char *lim = (char *) sbrk (0);
m_start_space = lim - lim_at_start;
m_space_enabled = 1;
m_start_cpu_time = run_time_clock::now ();
m_start_wall_time = steady_clock::now ();
m_time_enabled = 1;
+
+ if (per_command_time)
+ print_time (_("command started"));
}
else
m_time_enabled = 0;
reset_prompt_for_continue_wait_time ();
}
+/* See maint.h. */
+
+void
+scoped_command_stats::print_time (const char *msg)
+{
+ using namespace std::chrono;
+
+ auto now = system_clock::now ();
+ auto ticks = now.time_since_epoch ().count () / (1000 * 1000);
+ auto millis = ticks % 1000;
+
+ std::time_t as_time = system_clock::to_time_t (now);
+ struct tm *tm = localtime (&as_time);
+
+ char out[100];
+ strftime (out, sizeof (out), "%F %H:%M:%S", tm);
+
+ printf_unfiltered ("%s.%03d - %s\n", out, (int) millis, msg);
+}
+
/* Handle unknown "mt set per-command" arguments.
In this case have "mt set per-command on|off" affect every setting. */
static void
-set_per_command_cmd (char *args, int from_tty)
+set_per_command_cmd (const char *args, int from_tty)
{
struct cmd_list_element *list;
int val;
"show per-command " settings. */
static void
-show_per_command_cmd (char *args, int from_tty)
+show_per_command_cmd (const char *args, int from_tty)
{
cmd_show_list (per_command_showlist, from_tty, "");
}
static void
maintenance_selftest (const char *args, int from_tty)
{
+#if GDB_SELF_TEST
selftests::run_tests (args);
+#else
+ printf_filtered (_("\
+Selftests have been disabled for this build.\n"));
+#endif
}
static void
-maintenance_info_selftests (char *arg, int from_tty)
+maintenance_info_selftests (const char *arg, int from_tty)
{
+#if GDB_SELF_TEST
printf_filtered ("Registered selftests:\n");
selftests::for_each_selftest ([] (const std::string &name) {
printf_filtered (" - %s\n", name.c_str ());
});
+#else
+ printf_filtered (_("\
+Selftests have been disabled for this build.\n"));
+#endif
}
\f
add_prefix_cmd ("per-command", class_maintenance, set_per_command_cmd, _("\
Per-command statistics settings."),
- &per_command_setlist, "set per-command ",
+ &per_command_setlist, "maintenance set per-command ",
1/*allow-unknown*/, &maintenance_set_cmdlist);
add_prefix_cmd ("per-command", class_maintenance, show_per_command_cmd, _("\
Show per-command statistics settings."),
- &per_command_showlist, "show per-command ",
+ &per_command_showlist, "maintenance show per-command ",
0/*allow-unknown*/, &maintenance_show_cmdlist);
add_setshow_boolean_cmd ("time", class_maintenance,
add_cmd ("selftests", class_maintenance, maintenance_info_selftests,
_("List the registered selftests."), &maintenanceinfolist);
- add_setshow_zinteger_cmd ("watchdog", class_maintenance, &watchdog, _("\
-Set watchdog timer."), _("\
-Show watchdog timer."), _("\
-When non-zero, this timeout is used instead of waiting forever for a target\n\
-to finish a low-level step or continue operation. If the specified amount\n\
-of time passes without a response from the target, an error occurs."),
- NULL,
- show_watchdog,
- &setlist, &showlist);
-
add_setshow_boolean_cmd ("profile", class_maintenance,
&maintenance_profile_p, _("\
Set internal profiling."), _("\