diff options
Diffstat (limited to 'gdb/maint.c')
-rw-r--r-- | gdb/maint.c | 135 |
1 files changed, 109 insertions, 26 deletions
diff --git a/gdb/maint.c b/gdb/maint.c index f5977ec..8484793 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -21,7 +21,6 @@ #include "arch-utils.h" -#include <ctype.h> #include <cmath> #include <signal.h> #include "command.h" @@ -39,6 +38,8 @@ #include "inferior.h" #include "gdbsupport/thread-pool.h" #include "event-top.h" +#include "cp-support.h" +#include "gdbcore.h" #include "cli/cli-decode.h" #include "cli/cli-utils.h" @@ -108,6 +109,18 @@ maintenance_demangle (const char *args, int from_tty) styled_string (command_style.style (), "demangle")); } +/* Print the canonical form of a name. */ + +static void +maintenance_canonicalize (const char *args, int from_tty) +{ + gdb::unique_xmalloc_ptr<char> canon = cp_canonicalize_string (args); + if (canon == nullptr) + gdb_printf ("No change.\n"); + else + gdb_printf ("canonical = %s\n", canon.get ()); +} + static void maintenance_time_display (const char *args, int from_tty) { @@ -452,19 +465,19 @@ maintenance_info_sections (const char *arg, int from_tty) gdb::option::process_options (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group); - for (objfile *ofile : current_program_space->objfiles ()) + for (objfile &ofile : current_program_space->objfiles ()) { - if (ofile->obfd == current_program_space->exec_bfd ()) - maint_print_all_sections (_("Exec file: "), ofile->obfd.get (), - ofile, arg); + if (ofile.obfd == current_program_space->exec_bfd ()) + maint_print_all_sections (_("Exec file: "), ofile.obfd.get (), + &ofile, arg); else if (opts.all_objects) - maint_print_all_sections (_("Object file: "), ofile->obfd.get (), - ofile, arg); + maint_print_all_sections (_("Object file: "), ofile.obfd.get (), + &ofile, arg); } - if (current_program_space->core_bfd () != nullptr) - maint_print_all_sections (_("Core file: "), - current_program_space->core_bfd (), nullptr, arg); + bfd *cbfd = get_inferior_core_bfd (current_inferior ()); + if (cbfd != nullptr) + maint_print_all_sections (_("Core file: "), cbfd, nullptr, arg); } /* Implement the "maintenance info target-sections" command. */ @@ -558,9 +571,9 @@ maintenance_translate_address (const char *arg, int from_tty) sect = NULL; p = arg; - if (!isdigit (*p)) + if (!c_isdigit (*p)) { /* See if we have a valid section name. */ - while (*p && !isspace (*p)) /* Find end of section name. */ + while (*p && !c_isspace (*p)) /* Find end of section name. */ p++; if (*p == '\000') /* End of command? */ error (_("Need to specify section name and address")); @@ -568,10 +581,10 @@ maintenance_translate_address (const char *arg, int from_tty) int arg_len = p - arg; p = skip_spaces (p + 1); - for (objfile *objfile : current_program_space->objfiles ()) - for (obj_section *iter : objfile->sections ()) + for (objfile &objfile : current_program_space->objfiles ()) + for (obj_section &iter : objfile.sections ()) { - if (strncmp (iter->the_bfd_section->name, arg, arg_len) == 0) + if (strncmp (iter.the_bfd_section->name, arg, arg_len) == 0) goto found; } @@ -907,9 +920,9 @@ maintenance_show_worker_threads (struct ui_file *file, int from_tty, } -/* If true, display time usage both at startup and for each command. */ +/* See maint.h. */ -static bool per_command_time; +bool per_command_time; /* If true, display space usage both at startup and for each command. */ @@ -957,14 +970,14 @@ count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr, current_program_space may be NULL. */ if (current_program_space != NULL) { - for (objfile *o : current_program_space->objfiles ()) + for (objfile &o : current_program_space->objfiles ()) { - for (compunit_symtab *cu : o->compunits ()) + for (compunit_symtab &cu : o.compunits ()) { ++nr_compunit_symtabs; - nr_blocks += cu->blockvector ()->num_blocks (); - nr_symtabs += std::distance (cu->filetabs ().begin (), - cu->filetabs ().end ()); + nr_blocks += cu.blockvector ()->num_blocks (); + nr_symtabs += std::distance (cu.filetabs ().begin (), + cu.filetabs ().end ()); } } } @@ -1138,6 +1151,72 @@ set_per_command_cmd (const char *args, int from_tty) } } +/* Handle "mt set per-command time". Warn if per-thread run time + information is not possible. */ + +static void +maintenance_set_command_time_cmd (const char *args, int from_tty, + cmd_list_element *c) +{ + /* No point warning if this platform can't use multiple threads at + all. */ +#if CXX_STD_THREAD + static bool already_warned = false; + if (per_command_time + && !get_run_time_thread_scope_available () + && !already_warned) + { + warning (_("\ +per-thread run time information not available on this platform")); + already_warned = true; + } +#endif +} + +/* See maint.h. */ + +scoped_time_it::scoped_time_it (const char *what, bool enabled) + : m_enabled (enabled), + m_what (what), + m_start_wall (m_enabled + ? std::chrono::steady_clock::now () + : std::chrono::steady_clock::time_point ()) +{ + if (m_enabled) + get_run_time (m_start_user, m_start_sys, run_time_scope::thread); +} + +/* See maint.h. */ + +scoped_time_it::~scoped_time_it () +{ + if (!m_enabled) + return; + + namespace chr = std::chrono; + auto end_wall = chr::steady_clock::now (); + + user_cpu_time_clock::time_point end_user; + system_cpu_time_clock::time_point end_sys; + get_run_time (end_user, end_sys, run_time_scope::thread); + + auto user = end_user - m_start_user; + auto sys = end_sys - m_start_sys; + auto wall = end_wall - m_start_wall; + auto user_ms = chr::duration_cast<chr::milliseconds> (user).count (); + auto sys_ms = chr::duration_cast<chr::milliseconds> (sys).count (); + auto wall_ms = chr::duration_cast<chr::milliseconds> (wall).count (); + auto user_plus_sys_ms = user_ms + sys_ms; + + auto str + = string_printf ("Time for \"%s\": wall %.03f, user %.03f, sys %.03f, " + "user+sys %.03f, %.01f %% CPU\n", + m_what, wall_ms / 1000.0, user_ms / 1000.0, + sys_ms / 1000.0, user_plus_sys_ms / 1000.0, + user_plus_sys_ms * 100.0 / wall_ms); + gdb_stdlog->write_async_safe (str.data (), str.size ()); +} + /* Options affecting the "maintenance selftest" command. */ struct maintenance_selftest_options @@ -1222,9 +1301,7 @@ Selftests have been disabled for this build.\n")); } -void _initialize_maint_cmds (); -void -_initialize_maint_cmds () +INIT_GDB_FILE (maint_cmds) { struct cmd_list_element *cmd; @@ -1343,6 +1420,12 @@ This command has been moved to \"demangle\"."), &maintenancelist); deprecate_cmd (cmd, "demangle"); + cmd = add_cmd ("canonicalize", class_maintenance, maintenance_canonicalize, + _("\ +Show the canonical form of a C++ name.\n\ +Usage: maintenance canonicalize NAME"), + &maintenancelist); + add_prefix_cmd ("per-command", class_maintenance, set_per_command_cmd, _("\ Per-command statistics settings."), &per_command_setlist, @@ -1360,7 +1443,7 @@ Show whether to display per-command execution time."), _("\ If enabled, the execution time for each command will be\n\ displayed following the command's output."), - NULL, NULL, + maintenance_set_command_time_cmd, NULL, &per_command_setlist, &per_command_showlist); add_setshow_boolean_cmd ("space", class_maintenance, |