Home | History | Annotate | Line # | Download | only in gdb
maint.c revision 1.1.1.4
      1      1.1  christos /* Support for GDB maintenance commands.
      2      1.1  christos 
      3  1.1.1.4  christos    Copyright (C) 1992-2016 Free Software Foundation, Inc.
      4      1.1  christos 
      5      1.1  christos    Written by Fred Fish at Cygnus Support.
      6      1.1  christos 
      7      1.1  christos    This file is part of GDB.
      8      1.1  christos 
      9      1.1  christos    This program is free software; you can redistribute it and/or modify
     10      1.1  christos    it under the terms of the GNU General Public License as published by
     11      1.1  christos    the Free Software Foundation; either version 3 of the License, or
     12      1.1  christos    (at your option) any later version.
     13      1.1  christos 
     14      1.1  christos    This program is distributed in the hope that it will be useful,
     15      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17      1.1  christos    GNU General Public License for more details.
     18      1.1  christos 
     19      1.1  christos    You should have received a copy of the GNU General Public License
     20      1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     21      1.1  christos 
     22      1.1  christos 
     23      1.1  christos #include "defs.h"
     24      1.1  christos #include "arch-utils.h"
     25      1.1  christos #include <ctype.h>
     26      1.1  christos #include <signal.h>
     27  1.1.1.4  christos #include "gdb_sys_time.h"
     28      1.1  christos #include <time.h>
     29      1.1  christos #include "command.h"
     30      1.1  christos #include "gdbcmd.h"
     31      1.1  christos #include "symtab.h"
     32      1.1  christos #include "block.h"
     33      1.1  christos #include "gdbtypes.h"
     34      1.1  christos #include "demangle.h"
     35      1.1  christos #include "gdbcore.h"
     36      1.1  christos #include "expression.h"		/* For language.h */
     37      1.1  christos #include "language.h"
     38      1.1  christos #include "symfile.h"
     39      1.1  christos #include "objfiles.h"
     40      1.1  christos #include "value.h"
     41      1.1  christos #include "top.h"
     42      1.1  christos #include "timeval-utils.h"
     43      1.1  christos #include "maint.h"
     44  1.1.1.4  christos #include "selftest.h"
     45      1.1  christos 
     46      1.1  christos #include "cli/cli-decode.h"
     47      1.1  christos #include "cli/cli-utils.h"
     48      1.1  christos #include "cli/cli-setshow.h"
     49      1.1  christos 
     50      1.1  christos extern void _initialize_maint_cmds (void);
     51      1.1  christos 
     52      1.1  christos static void maintenance_command (char *, int);
     53      1.1  christos 
     54      1.1  christos static void maintenance_internal_error (char *args, int from_tty);
     55      1.1  christos 
     56      1.1  christos static void maintenance_demangle (char *, int);
     57      1.1  christos 
     58      1.1  christos static void maintenance_time_display (char *, int);
     59      1.1  christos 
     60      1.1  christos static void maintenance_space_display (char *, int);
     61      1.1  christos 
     62      1.1  christos static void maintenance_info_command (char *, int);
     63      1.1  christos 
     64      1.1  christos static void maintenance_info_sections (char *, int);
     65      1.1  christos 
     66      1.1  christos static void maintenance_print_command (char *, int);
     67      1.1  christos 
     68      1.1  christos static void maintenance_do_deprecate (char *, int);
     69      1.1  christos 
     70      1.1  christos /* Set this to the maximum number of seconds to wait instead of waiting forever
     71      1.1  christos    in target_wait().  If this timer times out, then it generates an error and
     72      1.1  christos    the command is aborted.  This replaces most of the need for timeouts in the
     73      1.1  christos    GDB test suite, and makes it possible to distinguish between a hung target
     74      1.1  christos    and one with slow communications.  */
     75      1.1  christos 
     76      1.1  christos int watchdog = 0;
     77      1.1  christos static void
     78      1.1  christos show_watchdog (struct ui_file *file, int from_tty,
     79      1.1  christos 	       struct cmd_list_element *c, const char *value)
     80      1.1  christos {
     81      1.1  christos   fprintf_filtered (file, _("Watchdog timer is %s.\n"), value);
     82      1.1  christos }
     83      1.1  christos 
     84      1.1  christos /* Access the maintenance subcommands.  */
     85      1.1  christos 
     86      1.1  christos static void
     87      1.1  christos maintenance_command (char *args, int from_tty)
     88      1.1  christos {
     89      1.1  christos   printf_unfiltered (_("\"maintenance\" must be followed by "
     90      1.1  christos 		       "the name of a maintenance command.\n"));
     91  1.1.1.2  christos   help_list (maintenancelist, "maintenance ", all_commands, gdb_stdout);
     92      1.1  christos }
     93      1.1  christos 
     94      1.1  christos #ifndef _WIN32
     95      1.1  christos static void
     96      1.1  christos maintenance_dump_me (char *args, int from_tty)
     97      1.1  christos {
     98      1.1  christos   if (query (_("Should GDB dump core? ")))
     99      1.1  christos     {
    100      1.1  christos #ifdef __DJGPP__
    101      1.1  christos       /* SIGQUIT by default is ignored, so use SIGABRT instead.  */
    102      1.1  christos       signal (SIGABRT, SIG_DFL);
    103      1.1  christos       kill (getpid (), SIGABRT);
    104      1.1  christos #else
    105      1.1  christos       signal (SIGQUIT, SIG_DFL);
    106      1.1  christos       kill (getpid (), SIGQUIT);
    107      1.1  christos #endif
    108      1.1  christos     }
    109      1.1  christos }
    110      1.1  christos #endif
    111      1.1  christos 
    112      1.1  christos /* Stimulate the internal error mechanism that GDB uses when an
    113      1.1  christos    internal problem is detected.  Allows testing of the mechanism.
    114      1.1  christos    Also useful when the user wants to drop a core file but not exit
    115      1.1  christos    GDB.  */
    116      1.1  christos 
    117      1.1  christos static void
    118      1.1  christos maintenance_internal_error (char *args, int from_tty)
    119      1.1  christos {
    120      1.1  christos   internal_error (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
    121      1.1  christos }
    122      1.1  christos 
    123      1.1  christos /* Stimulate the internal error mechanism that GDB uses when an
    124      1.1  christos    internal problem is detected.  Allows testing of the mechanism.
    125      1.1  christos    Also useful when the user wants to drop a core file but not exit
    126      1.1  christos    GDB.  */
    127      1.1  christos 
    128      1.1  christos static void
    129      1.1  christos maintenance_internal_warning (char *args, int from_tty)
    130      1.1  christos {
    131      1.1  christos   internal_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
    132      1.1  christos }
    133      1.1  christos 
    134  1.1.1.2  christos /* Stimulate the internal error mechanism that GDB uses when an
    135  1.1.1.2  christos    demangler problem is detected.  Allows testing of the mechanism.  */
    136      1.1  christos 
    137      1.1  christos static void
    138  1.1.1.2  christos maintenance_demangler_warning (char *args, int from_tty)
    139      1.1  christos {
    140  1.1.1.2  christos   demangler_warning (__FILE__, __LINE__, "%s", (args == NULL ? "" : args));
    141  1.1.1.2  christos }
    142      1.1  christos 
    143  1.1.1.2  christos /* Old command to demangle a string.  The command has been moved to "demangle".
    144  1.1.1.2  christos    It is kept for now because otherwise "mt demangle" gets interpreted as
    145  1.1.1.2  christos    "mt demangler-warning" which artificially creates an internal gdb error.  */
    146  1.1.1.2  christos 
    147  1.1.1.2  christos static void
    148  1.1.1.2  christos maintenance_demangle (char *args, int from_tty)
    149  1.1.1.2  christos {
    150  1.1.1.2  christos   printf_filtered (_("This command has been moved to \"demangle\".\n"));
    151      1.1  christos }
    152      1.1  christos 
    153      1.1  christos static void
    154      1.1  christos maintenance_time_display (char *args, int from_tty)
    155      1.1  christos {
    156      1.1  christos   if (args == NULL || *args == '\0')
    157      1.1  christos     printf_unfiltered (_("\"maintenance time\" takes a numeric argument.\n"));
    158      1.1  christos   else
    159      1.1  christos     set_per_command_time (strtol (args, NULL, 10));
    160      1.1  christos }
    161      1.1  christos 
    162      1.1  christos static void
    163      1.1  christos maintenance_space_display (char *args, int from_tty)
    164      1.1  christos {
    165      1.1  christos   if (args == NULL || *args == '\0')
    166      1.1  christos     printf_unfiltered ("\"maintenance space\" takes a numeric argument.\n");
    167      1.1  christos   else
    168      1.1  christos     set_per_command_space (strtol (args, NULL, 10));
    169      1.1  christos }
    170      1.1  christos 
    171      1.1  christos /* The "maintenance info" command is defined as a prefix, with
    172      1.1  christos    allow_unknown 0.  Therefore, its own definition is called only for
    173      1.1  christos    "maintenance info" with no args.  */
    174      1.1  christos 
    175      1.1  christos static void
    176      1.1  christos maintenance_info_command (char *arg, int from_tty)
    177      1.1  christos {
    178      1.1  christos   printf_unfiltered (_("\"maintenance info\" must be followed "
    179      1.1  christos 		       "by the name of an info command.\n"));
    180  1.1.1.2  christos   help_list (maintenanceinfolist, "maintenance info ", all_commands,
    181  1.1.1.2  christos 	     gdb_stdout);
    182      1.1  christos }
    183      1.1  christos 
    184      1.1  christos /* Mini tokenizing lexer for 'maint info sections' command.  */
    185      1.1  christos 
    186      1.1  christos static int
    187      1.1  christos match_substring (const char *string, const char *substr)
    188      1.1  christos {
    189      1.1  christos   int substr_len = strlen(substr);
    190      1.1  christos   const char *tok;
    191      1.1  christos 
    192      1.1  christos   while ((tok = strstr (string, substr)) != NULL)
    193      1.1  christos     {
    194      1.1  christos       /* Got a partial match.  Is it a whole word?  */
    195      1.1  christos       if (tok == string
    196      1.1  christos 	  || tok[-1] == ' '
    197      1.1  christos 	  || tok[-1] == '\t')
    198      1.1  christos       {
    199      1.1  christos 	/* Token is delimited at the front...  */
    200      1.1  christos 	if (tok[substr_len] == ' '
    201      1.1  christos 	    || tok[substr_len] == '\t'
    202      1.1  christos 	    || tok[substr_len] == '\0')
    203      1.1  christos 	{
    204      1.1  christos 	  /* Token is delimited at the rear.  Got a whole-word match.  */
    205      1.1  christos 	  return 1;
    206      1.1  christos 	}
    207      1.1  christos       }
    208      1.1  christos       /* Token didn't match as a whole word.  Advance and try again.  */
    209      1.1  christos       string = tok + 1;
    210      1.1  christos     }
    211      1.1  christos   return 0;
    212      1.1  christos }
    213      1.1  christos 
    214      1.1  christos static int
    215  1.1.1.2  christos match_bfd_flags (const char *string, flagword flags)
    216      1.1  christos {
    217      1.1  christos   if (flags & SEC_ALLOC)
    218      1.1  christos     if (match_substring (string, "ALLOC"))
    219      1.1  christos       return 1;
    220      1.1  christos   if (flags & SEC_LOAD)
    221      1.1  christos     if (match_substring (string, "LOAD"))
    222      1.1  christos       return 1;
    223      1.1  christos   if (flags & SEC_RELOC)
    224      1.1  christos     if (match_substring (string, "RELOC"))
    225      1.1  christos       return 1;
    226      1.1  christos   if (flags & SEC_READONLY)
    227      1.1  christos     if (match_substring (string, "READONLY"))
    228      1.1  christos       return 1;
    229      1.1  christos   if (flags & SEC_CODE)
    230      1.1  christos     if (match_substring (string, "CODE"))
    231      1.1  christos       return 1;
    232      1.1  christos   if (flags & SEC_DATA)
    233      1.1  christos     if (match_substring (string, "DATA"))
    234      1.1  christos       return 1;
    235      1.1  christos   if (flags & SEC_ROM)
    236      1.1  christos     if (match_substring (string, "ROM"))
    237      1.1  christos       return 1;
    238      1.1  christos   if (flags & SEC_CONSTRUCTOR)
    239      1.1  christos     if (match_substring (string, "CONSTRUCTOR"))
    240      1.1  christos       return 1;
    241      1.1  christos   if (flags & SEC_HAS_CONTENTS)
    242      1.1  christos     if (match_substring (string, "HAS_CONTENTS"))
    243      1.1  christos       return 1;
    244      1.1  christos   if (flags & SEC_NEVER_LOAD)
    245      1.1  christos     if (match_substring (string, "NEVER_LOAD"))
    246      1.1  christos       return 1;
    247      1.1  christos   if (flags & SEC_COFF_SHARED_LIBRARY)
    248      1.1  christos     if (match_substring (string, "COFF_SHARED_LIBRARY"))
    249      1.1  christos       return 1;
    250      1.1  christos   if (flags & SEC_IS_COMMON)
    251      1.1  christos     if (match_substring (string, "IS_COMMON"))
    252      1.1  christos       return 1;
    253      1.1  christos 
    254      1.1  christos   return 0;
    255      1.1  christos }
    256      1.1  christos 
    257      1.1  christos static void
    258      1.1  christos print_bfd_flags (flagword flags)
    259      1.1  christos {
    260      1.1  christos   if (flags & SEC_ALLOC)
    261      1.1  christos     printf_filtered (" ALLOC");
    262      1.1  christos   if (flags & SEC_LOAD)
    263      1.1  christos     printf_filtered (" LOAD");
    264      1.1  christos   if (flags & SEC_RELOC)
    265      1.1  christos     printf_filtered (" RELOC");
    266      1.1  christos   if (flags & SEC_READONLY)
    267      1.1  christos     printf_filtered (" READONLY");
    268      1.1  christos   if (flags & SEC_CODE)
    269      1.1  christos     printf_filtered (" CODE");
    270      1.1  christos   if (flags & SEC_DATA)
    271      1.1  christos     printf_filtered (" DATA");
    272      1.1  christos   if (flags & SEC_ROM)
    273      1.1  christos     printf_filtered (" ROM");
    274      1.1  christos   if (flags & SEC_CONSTRUCTOR)
    275      1.1  christos     printf_filtered (" CONSTRUCTOR");
    276      1.1  christos   if (flags & SEC_HAS_CONTENTS)
    277      1.1  christos     printf_filtered (" HAS_CONTENTS");
    278      1.1  christos   if (flags & SEC_NEVER_LOAD)
    279      1.1  christos     printf_filtered (" NEVER_LOAD");
    280      1.1  christos   if (flags & SEC_COFF_SHARED_LIBRARY)
    281      1.1  christos     printf_filtered (" COFF_SHARED_LIBRARY");
    282      1.1  christos   if (flags & SEC_IS_COMMON)
    283      1.1  christos     printf_filtered (" IS_COMMON");
    284      1.1  christos }
    285      1.1  christos 
    286      1.1  christos static void
    287      1.1  christos maint_print_section_info (const char *name, flagword flags,
    288      1.1  christos 			  CORE_ADDR addr, CORE_ADDR endaddr,
    289      1.1  christos 			  unsigned long filepos, int addr_size)
    290      1.1  christos {
    291      1.1  christos   printf_filtered ("    %s", hex_string_custom (addr, addr_size));
    292      1.1  christos   printf_filtered ("->%s", hex_string_custom (endaddr, addr_size));
    293      1.1  christos   printf_filtered (" at %s",
    294      1.1  christos 		   hex_string_custom ((unsigned long) filepos, 8));
    295      1.1  christos   printf_filtered (": %s", name);
    296      1.1  christos   print_bfd_flags (flags);
    297      1.1  christos   printf_filtered ("\n");
    298      1.1  christos }
    299      1.1  christos 
    300      1.1  christos static void
    301      1.1  christos print_bfd_section_info (bfd *abfd,
    302      1.1  christos 			asection *asect,
    303  1.1.1.2  christos 			void *datum)
    304      1.1  christos {
    305      1.1  christos   flagword flags = bfd_get_section_flags (abfd, asect);
    306      1.1  christos   const char *name = bfd_section_name (abfd, asect);
    307  1.1.1.4  christos   const char *arg = (const char *) datum;
    308      1.1  christos 
    309  1.1.1.2  christos   if (arg == NULL || *arg == '\0'
    310  1.1.1.2  christos       || match_substring (arg, name)
    311  1.1.1.2  christos       || match_bfd_flags (arg, flags))
    312      1.1  christos     {
    313      1.1  christos       struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
    314      1.1  christos       int addr_size = gdbarch_addr_bit (gdbarch) / 8;
    315      1.1  christos       CORE_ADDR addr, endaddr;
    316      1.1  christos 
    317      1.1  christos       addr = bfd_section_vma (abfd, asect);
    318      1.1  christos       endaddr = addr + bfd_section_size (abfd, asect);
    319      1.1  christos       printf_filtered (" [%d] ", gdb_bfd_section_index (abfd, asect));
    320      1.1  christos       maint_print_section_info (name, flags, addr, endaddr,
    321      1.1  christos 				asect->filepos, addr_size);
    322      1.1  christos     }
    323      1.1  christos }
    324      1.1  christos 
    325      1.1  christos static void
    326      1.1  christos print_objfile_section_info (bfd *abfd,
    327      1.1  christos 			    struct obj_section *asect,
    328  1.1.1.2  christos 			    const char *string)
    329      1.1  christos {
    330      1.1  christos   flagword flags = bfd_get_section_flags (abfd, asect->the_bfd_section);
    331      1.1  christos   const char *name = bfd_section_name (abfd, asect->the_bfd_section);
    332      1.1  christos 
    333      1.1  christos   if (string == NULL || *string == '\0'
    334      1.1  christos       || match_substring (string, name)
    335      1.1  christos       || match_bfd_flags (string, flags))
    336      1.1  christos     {
    337      1.1  christos       struct gdbarch *gdbarch = gdbarch_from_bfd (abfd);
    338      1.1  christos       int addr_size = gdbarch_addr_bit (gdbarch) / 8;
    339      1.1  christos 
    340      1.1  christos       maint_print_section_info (name, flags,
    341      1.1  christos 				obj_section_addr (asect),
    342      1.1  christos 				obj_section_endaddr (asect),
    343      1.1  christos 				asect->the_bfd_section->filepos,
    344      1.1  christos 				addr_size);
    345      1.1  christos     }
    346      1.1  christos }
    347      1.1  christos 
    348      1.1  christos static void
    349      1.1  christos maintenance_info_sections (char *arg, int from_tty)
    350      1.1  christos {
    351      1.1  christos   if (exec_bfd)
    352      1.1  christos     {
    353      1.1  christos       printf_filtered (_("Exec file:\n"));
    354      1.1  christos       printf_filtered ("    `%s', ", bfd_get_filename (exec_bfd));
    355      1.1  christos       wrap_here ("        ");
    356      1.1  christos       printf_filtered (_("file type %s.\n"), bfd_get_target (exec_bfd));
    357      1.1  christos       if (arg && *arg && match_substring (arg, "ALLOBJ"))
    358      1.1  christos 	{
    359      1.1  christos 	  struct objfile *ofile;
    360      1.1  christos 	  struct obj_section *osect;
    361      1.1  christos 
    362      1.1  christos 	  /* Only this function cares about the 'ALLOBJ' argument;
    363      1.1  christos 	     if 'ALLOBJ' is the only argument, discard it rather than
    364      1.1  christos 	     passing it down to print_objfile_section_info (which
    365      1.1  christos 	     wouldn't know how to handle it).  */
    366      1.1  christos 	  if (strcmp (arg, "ALLOBJ") == 0)
    367      1.1  christos 	    arg = NULL;
    368      1.1  christos 
    369      1.1  christos 	  ALL_OBJFILES (ofile)
    370      1.1  christos 	    {
    371      1.1  christos 	      printf_filtered (_("  Object file: %s\n"),
    372      1.1  christos 			       bfd_get_filename (ofile->obfd));
    373      1.1  christos 	      ALL_OBJFILE_OSECTIONS (ofile, osect)
    374      1.1  christos 		{
    375      1.1  christos 		  print_objfile_section_info (ofile->obfd, osect, arg);
    376      1.1  christos 		}
    377      1.1  christos 	    }
    378      1.1  christos 	}
    379      1.1  christos       else
    380      1.1  christos 	bfd_map_over_sections (exec_bfd, print_bfd_section_info, arg);
    381      1.1  christos     }
    382      1.1  christos 
    383      1.1  christos   if (core_bfd)
    384      1.1  christos     {
    385      1.1  christos       printf_filtered (_("Core file:\n"));
    386      1.1  christos       printf_filtered ("    `%s', ", bfd_get_filename (core_bfd));
    387      1.1  christos       wrap_here ("        ");
    388      1.1  christos       printf_filtered (_("file type %s.\n"), bfd_get_target (core_bfd));
    389      1.1  christos       bfd_map_over_sections (core_bfd, print_bfd_section_info, arg);
    390      1.1  christos     }
    391      1.1  christos }
    392      1.1  christos 
    393      1.1  christos static void
    394      1.1  christos maintenance_print_statistics (char *args, int from_tty)
    395      1.1  christos {
    396      1.1  christos   print_objfile_statistics ();
    397      1.1  christos   print_symbol_bcache_statistics ();
    398      1.1  christos }
    399      1.1  christos 
    400      1.1  christos static void
    401      1.1  christos maintenance_print_architecture (char *args, int from_tty)
    402      1.1  christos {
    403      1.1  christos   struct gdbarch *gdbarch = get_current_arch ();
    404      1.1  christos 
    405      1.1  christos   if (args == NULL)
    406      1.1  christos     gdbarch_dump (gdbarch, gdb_stdout);
    407      1.1  christos   else
    408      1.1  christos     {
    409      1.1  christos       struct cleanup *cleanups;
    410      1.1  christos       struct ui_file *file = gdb_fopen (args, "w");
    411      1.1  christos 
    412      1.1  christos       if (file == NULL)
    413      1.1  christos 	perror_with_name (_("maintenance print architecture"));
    414      1.1  christos       cleanups = make_cleanup_ui_file_delete (file);
    415      1.1  christos       gdbarch_dump (gdbarch, file);
    416      1.1  christos       do_cleanups (cleanups);
    417      1.1  christos     }
    418      1.1  christos }
    419      1.1  christos 
    420      1.1  christos /* The "maintenance print" command is defined as a prefix, with
    421      1.1  christos    allow_unknown 0.  Therefore, its own definition is called only for
    422      1.1  christos    "maintenance print" with no args.  */
    423      1.1  christos 
    424      1.1  christos static void
    425      1.1  christos maintenance_print_command (char *arg, int from_tty)
    426      1.1  christos {
    427      1.1  christos   printf_unfiltered (_("\"maintenance print\" must be followed "
    428      1.1  christos 		       "by the name of a print command.\n"));
    429  1.1.1.2  christos   help_list (maintenanceprintlist, "maintenance print ", all_commands,
    430  1.1.1.2  christos 	     gdb_stdout);
    431      1.1  christos }
    432      1.1  christos 
    433      1.1  christos /* The "maintenance translate-address" command converts a section and address
    434      1.1  christos    to a symbol.  This can be called in two ways:
    435      1.1  christos    maintenance translate-address <secname> <addr>
    436      1.1  christos    or   maintenance translate-address <addr>.  */
    437      1.1  christos 
    438      1.1  christos static void
    439      1.1  christos maintenance_translate_address (char *arg, int from_tty)
    440      1.1  christos {
    441      1.1  christos   CORE_ADDR address;
    442      1.1  christos   struct obj_section *sect;
    443      1.1  christos   char *p;
    444      1.1  christos   struct bound_minimal_symbol sym;
    445      1.1  christos   struct objfile *objfile;
    446      1.1  christos 
    447      1.1  christos   if (arg == NULL || *arg == 0)
    448      1.1  christos     error (_("requires argument (address or section + address)"));
    449      1.1  christos 
    450      1.1  christos   sect = NULL;
    451      1.1  christos   p = arg;
    452      1.1  christos 
    453      1.1  christos   if (!isdigit (*p))
    454      1.1  christos     {				/* See if we have a valid section name.  */
    455      1.1  christos       while (*p && !isspace (*p))	/* Find end of section name.  */
    456      1.1  christos 	p++;
    457      1.1  christos       if (*p == '\000')		/* End of command?  */
    458      1.1  christos 	error (_("Need to specify <section-name> and <address>"));
    459      1.1  christos       *p++ = '\000';
    460      1.1  christos       p = skip_spaces (p);
    461      1.1  christos 
    462      1.1  christos       ALL_OBJSECTIONS (objfile, sect)
    463      1.1  christos       {
    464      1.1  christos 	if (strcmp (sect->the_bfd_section->name, arg) == 0)
    465      1.1  christos 	  break;
    466      1.1  christos       }
    467      1.1  christos 
    468      1.1  christos       if (!objfile)
    469      1.1  christos 	error (_("Unknown section %s."), arg);
    470      1.1  christos     }
    471      1.1  christos 
    472      1.1  christos   address = parse_and_eval_address (p);
    473      1.1  christos 
    474      1.1  christos   if (sect)
    475      1.1  christos     sym = lookup_minimal_symbol_by_pc_section (address, sect);
    476      1.1  christos   else
    477      1.1  christos     sym = lookup_minimal_symbol_by_pc (address);
    478      1.1  christos 
    479      1.1  christos   if (sym.minsym)
    480      1.1  christos     {
    481  1.1.1.2  christos       const char *symbol_name = MSYMBOL_PRINT_NAME (sym.minsym);
    482      1.1  christos       const char *symbol_offset
    483  1.1.1.2  christos 	= pulongest (address - BMSYMBOL_VALUE_ADDRESS (sym));
    484      1.1  christos 
    485  1.1.1.2  christos       sect = MSYMBOL_OBJ_SECTION(sym.objfile, sym.minsym);
    486      1.1  christos       if (sect != NULL)
    487      1.1  christos 	{
    488      1.1  christos 	  const char *section_name;
    489      1.1  christos 	  const char *obj_name;
    490      1.1  christos 
    491      1.1  christos 	  gdb_assert (sect->the_bfd_section && sect->the_bfd_section->name);
    492      1.1  christos 	  section_name = sect->the_bfd_section->name;
    493      1.1  christos 
    494      1.1  christos 	  gdb_assert (sect->objfile && objfile_name (sect->objfile));
    495      1.1  christos 	  obj_name = objfile_name (sect->objfile);
    496      1.1  christos 
    497      1.1  christos 	  if (MULTI_OBJFILE_P ())
    498      1.1  christos 	    printf_filtered (_("%s + %s in section %s of %s\n"),
    499      1.1  christos 			     symbol_name, symbol_offset,
    500      1.1  christos 			     section_name, obj_name);
    501      1.1  christos 	  else
    502      1.1  christos 	    printf_filtered (_("%s + %s in section %s\n"),
    503      1.1  christos 			     symbol_name, symbol_offset, section_name);
    504      1.1  christos 	}
    505      1.1  christos       else
    506      1.1  christos 	printf_filtered (_("%s + %s\n"), symbol_name, symbol_offset);
    507      1.1  christos     }
    508      1.1  christos   else if (sect)
    509      1.1  christos     printf_filtered (_("no symbol at %s:%s\n"),
    510      1.1  christos 		     sect->the_bfd_section->name, hex_string (address));
    511      1.1  christos   else
    512      1.1  christos     printf_filtered (_("no symbol at %s\n"), hex_string (address));
    513      1.1  christos 
    514      1.1  christos   return;
    515      1.1  christos }
    516      1.1  christos 
    517      1.1  christos 
    518      1.1  christos /* When a command is deprecated the user will be warned the first time
    519      1.1  christos    the command is used.  If possible, a replacement will be
    520      1.1  christos    offered.  */
    521      1.1  christos 
    522      1.1  christos static void
    523      1.1  christos maintenance_deprecate (char *args, int from_tty)
    524      1.1  christos {
    525      1.1  christos   if (args == NULL || *args == '\0')
    526      1.1  christos     {
    527      1.1  christos       printf_unfiltered (_("\"maintenance deprecate\" takes an argument,\n\
    528      1.1  christos the command you want to deprecate, and optionally the replacement command\n\
    529      1.1  christos enclosed in quotes.\n"));
    530      1.1  christos     }
    531      1.1  christos 
    532      1.1  christos   maintenance_do_deprecate (args, 1);
    533      1.1  christos 
    534      1.1  christos }
    535      1.1  christos 
    536      1.1  christos 
    537      1.1  christos static void
    538      1.1  christos maintenance_undeprecate (char *args, int from_tty)
    539      1.1  christos {
    540      1.1  christos   if (args == NULL || *args == '\0')
    541      1.1  christos     {
    542      1.1  christos       printf_unfiltered (_("\"maintenance undeprecate\" takes an argument, \n\
    543      1.1  christos the command you want to undeprecate.\n"));
    544      1.1  christos     }
    545      1.1  christos 
    546      1.1  christos   maintenance_do_deprecate (args, 0);
    547      1.1  christos 
    548      1.1  christos }
    549      1.1  christos 
    550      1.1  christos /* You really shouldn't be using this.  It is just for the testsuite.
    551      1.1  christos    Rather, you should use deprecate_cmd() when the command is created
    552      1.1  christos    in _initialize_blah().
    553      1.1  christos 
    554      1.1  christos    This function deprecates a command and optionally assigns it a
    555      1.1  christos    replacement.  */
    556      1.1  christos 
    557      1.1  christos static void
    558      1.1  christos maintenance_do_deprecate (char *text, int deprecate)
    559      1.1  christos {
    560      1.1  christos   struct cmd_list_element *alias = NULL;
    561      1.1  christos   struct cmd_list_element *prefix_cmd = NULL;
    562      1.1  christos   struct cmd_list_element *cmd = NULL;
    563      1.1  christos 
    564      1.1  christos   char *start_ptr = NULL;
    565      1.1  christos   char *end_ptr = NULL;
    566      1.1  christos   int len;
    567      1.1  christos   char *replacement = NULL;
    568      1.1  christos 
    569      1.1  christos   if (text == NULL)
    570      1.1  christos     return;
    571      1.1  christos 
    572      1.1  christos   if (!lookup_cmd_composition (text, &alias, &prefix_cmd, &cmd))
    573      1.1  christos     {
    574      1.1  christos       printf_filtered (_("Can't find command '%s' to deprecate.\n"), text);
    575      1.1  christos       return;
    576      1.1  christos     }
    577      1.1  christos 
    578      1.1  christos   if (deprecate)
    579      1.1  christos     {
    580      1.1  christos       /* Look for a replacement command.  */
    581      1.1  christos       start_ptr = strchr (text, '\"');
    582      1.1  christos       if (start_ptr != NULL)
    583      1.1  christos 	{
    584      1.1  christos 	  start_ptr++;
    585      1.1  christos 	  end_ptr = strrchr (start_ptr, '\"');
    586      1.1  christos 	  if (end_ptr != NULL)
    587      1.1  christos 	    {
    588      1.1  christos 	      len = end_ptr - start_ptr;
    589      1.1  christos 	      start_ptr[len] = '\0';
    590      1.1  christos 	      replacement = xstrdup (start_ptr);
    591      1.1  christos 	    }
    592      1.1  christos 	}
    593      1.1  christos     }
    594      1.1  christos 
    595      1.1  christos   if (!start_ptr || !end_ptr)
    596      1.1  christos     replacement = NULL;
    597      1.1  christos 
    598      1.1  christos 
    599      1.1  christos   /* If they used an alias, we only want to deprecate the alias.
    600      1.1  christos 
    601      1.1  christos      Note the MALLOCED_REPLACEMENT test.  If the command's replacement
    602      1.1  christos      string was allocated at compile time we don't want to free the
    603      1.1  christos      memory.  */
    604      1.1  christos   if (alias)
    605      1.1  christos     {
    606  1.1.1.2  christos       if (alias->malloced_replacement)
    607  1.1.1.2  christos 	xfree ((char *) alias->replacement);
    608      1.1  christos 
    609      1.1  christos       if (deprecate)
    610  1.1.1.2  christos 	{
    611  1.1.1.2  christos 	  alias->deprecated_warn_user = 1;
    612  1.1.1.2  christos 	  alias->cmd_deprecated = 1;
    613  1.1.1.2  christos 	}
    614      1.1  christos       else
    615  1.1.1.2  christos 	{
    616  1.1.1.2  christos 	  alias->deprecated_warn_user = 0;
    617  1.1.1.2  christos 	  alias->cmd_deprecated = 0;
    618  1.1.1.2  christos 	}
    619      1.1  christos       alias->replacement = replacement;
    620  1.1.1.2  christos       alias->malloced_replacement = 1;
    621      1.1  christos       return;
    622      1.1  christos     }
    623      1.1  christos   else if (cmd)
    624      1.1  christos     {
    625  1.1.1.2  christos       if (cmd->malloced_replacement)
    626  1.1.1.2  christos 	xfree ((char *) cmd->replacement);
    627      1.1  christos 
    628      1.1  christos       if (deprecate)
    629  1.1.1.2  christos 	{
    630  1.1.1.2  christos 	  cmd->deprecated_warn_user = 1;
    631  1.1.1.2  christos 	  cmd->cmd_deprecated = 1;
    632  1.1.1.2  christos 	}
    633      1.1  christos       else
    634  1.1.1.2  christos 	{
    635  1.1.1.2  christos 	  cmd->deprecated_warn_user = 0;
    636  1.1.1.2  christos 	  cmd->cmd_deprecated = 0;
    637  1.1.1.2  christos 	}
    638      1.1  christos       cmd->replacement = replacement;
    639  1.1.1.2  christos       cmd->malloced_replacement = 1;
    640      1.1  christos       return;
    641      1.1  christos     }
    642      1.1  christos   xfree (replacement);
    643      1.1  christos }
    644      1.1  christos 
    645      1.1  christos /* Maintenance set/show framework.  */
    646      1.1  christos 
    647      1.1  christos struct cmd_list_element *maintenance_set_cmdlist;
    648      1.1  christos struct cmd_list_element *maintenance_show_cmdlist;
    649      1.1  christos 
    650      1.1  christos static void
    651      1.1  christos maintenance_set_cmd (char *args, int from_tty)
    652      1.1  christos {
    653      1.1  christos   printf_unfiltered (_("\"maintenance set\" must be followed "
    654      1.1  christos 		       "by the name of a set command.\n"));
    655  1.1.1.2  christos   help_list (maintenance_set_cmdlist, "maintenance set ", all_commands,
    656  1.1.1.2  christos 	     gdb_stdout);
    657      1.1  christos }
    658      1.1  christos 
    659      1.1  christos static void
    660      1.1  christos maintenance_show_cmd (char *args, int from_tty)
    661      1.1  christos {
    662      1.1  christos   cmd_show_list (maintenance_show_cmdlist, from_tty, "");
    663      1.1  christos }
    664      1.1  christos 
    665      1.1  christos /* Profiling support.  */
    666      1.1  christos 
    667      1.1  christos static int maintenance_profile_p;
    668      1.1  christos static void
    669      1.1  christos show_maintenance_profile_p (struct ui_file *file, int from_tty,
    670      1.1  christos 			    struct cmd_list_element *c, const char *value)
    671      1.1  christos {
    672      1.1  christos   fprintf_filtered (file, _("Internal profiling is %s.\n"), value);
    673      1.1  christos }
    674      1.1  christos 
    675      1.1  christos #ifdef HAVE__ETEXT
    676      1.1  christos extern char _etext;
    677      1.1  christos #define TEXTEND &_etext
    678      1.1  christos #elif defined (HAVE_ETEXT)
    679      1.1  christos extern char etext;
    680      1.1  christos #define TEXTEND &etext
    681      1.1  christos #endif
    682      1.1  christos 
    683      1.1  christos #if defined (HAVE_MONSTARTUP) && defined (HAVE__MCLEANUP) && defined (TEXTEND)
    684      1.1  christos 
    685      1.1  christos static int profiling_state;
    686      1.1  christos 
    687  1.1.1.3  christos EXTERN_C void _mcleanup (void);
    688  1.1.1.3  christos 
    689      1.1  christos static void
    690      1.1  christos mcleanup_wrapper (void)
    691      1.1  christos {
    692      1.1  christos   if (profiling_state)
    693      1.1  christos     _mcleanup ();
    694      1.1  christos }
    695      1.1  christos 
    696  1.1.1.3  christos EXTERN_C void monstartup (unsigned long, unsigned long);
    697  1.1.1.3  christos extern int main ();
    698  1.1.1.3  christos 
    699      1.1  christos static void
    700      1.1  christos maintenance_set_profile_cmd (char *args, int from_tty,
    701      1.1  christos 			     struct cmd_list_element *c)
    702      1.1  christos {
    703      1.1  christos   if (maintenance_profile_p == profiling_state)
    704      1.1  christos     return;
    705      1.1  christos 
    706      1.1  christos   profiling_state = maintenance_profile_p;
    707      1.1  christos 
    708      1.1  christos   if (maintenance_profile_p)
    709      1.1  christos     {
    710      1.1  christos       static int profiling_initialized;
    711      1.1  christos 
    712      1.1  christos       if (!profiling_initialized)
    713      1.1  christos 	{
    714      1.1  christos 	  atexit (mcleanup_wrapper);
    715      1.1  christos 	  profiling_initialized = 1;
    716      1.1  christos 	}
    717      1.1  christos 
    718      1.1  christos       /* "main" is now always the first function in the text segment, so use
    719      1.1  christos 	 its address for monstartup.  */
    720      1.1  christos       monstartup ((unsigned long) &main, (unsigned long) TEXTEND);
    721      1.1  christos     }
    722      1.1  christos   else
    723      1.1  christos     {
    724      1.1  christos       extern void _mcleanup (void);
    725      1.1  christos 
    726      1.1  christos       _mcleanup ();
    727      1.1  christos     }
    728      1.1  christos }
    729      1.1  christos #else
    730      1.1  christos static void
    731      1.1  christos maintenance_set_profile_cmd (char *args, int from_tty,
    732      1.1  christos 			     struct cmd_list_element *c)
    733      1.1  christos {
    734      1.1  christos   error (_("Profiling support is not available on this system."));
    735      1.1  christos }
    736      1.1  christos #endif
    737      1.1  christos 
    738      1.1  christos /* If nonzero, display time usage both at startup and for each command.  */
    740      1.1  christos 
    741      1.1  christos static int per_command_time;
    742      1.1  christos 
    743      1.1  christos /* If nonzero, display space usage both at startup and for each command.  */
    744      1.1  christos 
    745      1.1  christos static int per_command_space;
    746      1.1  christos 
    747      1.1  christos /* If nonzero, display basic symtab stats for each command.  */
    748      1.1  christos 
    749      1.1  christos static int per_command_symtab;
    750      1.1  christos 
    751      1.1  christos /* mt per-command commands.  */
    752      1.1  christos 
    753      1.1  christos static struct cmd_list_element *per_command_setlist;
    754      1.1  christos static struct cmd_list_element *per_command_showlist;
    755      1.1  christos 
    756      1.1  christos /* Records a run time and space usage to be used as a base for
    757      1.1  christos    reporting elapsed time or change in space.  */
    758      1.1  christos 
    759      1.1  christos struct cmd_stats
    760      1.1  christos {
    761      1.1  christos   /* Zero if the saved time is from the beginning of GDB execution.
    762      1.1  christos      One if from the beginning of an individual command execution.  */
    763      1.1  christos   int msg_type;
    764      1.1  christos   /* Track whether the stat was enabled at the start of the command
    765      1.1  christos      so that we can avoid printing anything if it gets turned on by
    766      1.1  christos      the current command.  */
    767      1.1  christos   int time_enabled : 1;
    768      1.1  christos   int space_enabled : 1;
    769      1.1  christos   int symtab_enabled : 1;
    770      1.1  christos   long start_cpu_time;
    771      1.1  christos   struct timeval start_wall_time;
    772      1.1  christos   long start_space;
    773      1.1  christos   /* Total number of symtabs (over all objfiles).  */
    774  1.1.1.2  christos   int start_nr_symtabs;
    775  1.1.1.2  christos   /* A count of the compunits.  */
    776      1.1  christos   int start_nr_compunit_symtabs;
    777      1.1  christos   /* Total number of blocks.  */
    778      1.1  christos   int start_nr_blocks;
    779      1.1  christos };
    780      1.1  christos 
    781      1.1  christos /* Set whether to display time statistics to NEW_VALUE
    782      1.1  christos    (non-zero means true).  */
    783      1.1  christos 
    784      1.1  christos void
    785      1.1  christos set_per_command_time (int new_value)
    786      1.1  christos {
    787      1.1  christos   per_command_time = new_value;
    788      1.1  christos }
    789      1.1  christos 
    790      1.1  christos /* Set whether to display space statistics to NEW_VALUE
    791      1.1  christos    (non-zero means true).  */
    792      1.1  christos 
    793      1.1  christos void
    794      1.1  christos set_per_command_space (int new_value)
    795      1.1  christos {
    796      1.1  christos   per_command_space = new_value;
    797      1.1  christos }
    798      1.1  christos 
    799      1.1  christos /* Count the number of symtabs and blocks.  */
    800      1.1  christos 
    801  1.1.1.2  christos static void
    802      1.1  christos count_symtabs_and_blocks (int *nr_symtabs_ptr, int *nr_compunit_symtabs_ptr,
    803      1.1  christos 			  int *nr_blocks_ptr)
    804      1.1  christos {
    805  1.1.1.2  christos   struct objfile *o;
    806      1.1  christos   struct compunit_symtab *cu;
    807      1.1  christos   struct symtab *s;
    808  1.1.1.2  christos   int nr_symtabs = 0;
    809      1.1  christos   int nr_compunit_symtabs = 0;
    810      1.1  christos   int nr_blocks = 0;
    811  1.1.1.2  christos 
    812  1.1.1.2  christos   /* When collecting statistics during startup, this is called before
    813  1.1.1.2  christos      pretty much anything in gdb has been initialized, and thus
    814  1.1.1.2  christos      current_program_space may be NULL.  */
    815      1.1  christos   if (current_program_space != NULL)
    816  1.1.1.2  christos     {
    817      1.1  christos       ALL_COMPUNITS (o, cu)
    818  1.1.1.2  christos 	{
    819  1.1.1.2  christos 	  ++nr_compunit_symtabs;
    820  1.1.1.2  christos 	  nr_blocks += BLOCKVECTOR_NBLOCKS (COMPUNIT_BLOCKVECTOR (cu));
    821  1.1.1.2  christos 	  ALL_COMPUNIT_FILETABS (cu, s)
    822      1.1  christos 	    ++nr_symtabs;
    823      1.1  christos 	}
    824      1.1  christos     }
    825      1.1  christos 
    826  1.1.1.2  christos   *nr_symtabs_ptr = nr_symtabs;
    827      1.1  christos   *nr_compunit_symtabs_ptr = nr_compunit_symtabs;
    828      1.1  christos   *nr_blocks_ptr = nr_blocks;
    829      1.1  christos }
    830      1.1  christos 
    831      1.1  christos /* As indicated by display_time and display_space, report GDB's elapsed time
    832      1.1  christos    and space usage from the base time and space provided in ARG, which
    833      1.1  christos    must be a pointer to a struct cmd_stat.  This function is intended
    834      1.1  christos    to be called as a cleanup.  */
    835      1.1  christos 
    836      1.1  christos static void
    837      1.1  christos report_command_stats (void *arg)
    838      1.1  christos {
    839      1.1  christos   struct cmd_stats *start_stats = (struct cmd_stats *) arg;
    840      1.1  christos   int msg_type = start_stats->msg_type;
    841  1.1.1.2  christos 
    842      1.1  christos   if (start_stats->time_enabled && per_command_time)
    843      1.1  christos     {
    844      1.1  christos       long cmd_time = get_run_time () - start_stats->start_cpu_time;
    845      1.1  christos       struct timeval now_wall_time, delta_wall_time, wait_time;
    846      1.1  christos 
    847      1.1  christos       gettimeofday (&now_wall_time, NULL);
    848      1.1  christos       timeval_sub (&delta_wall_time,
    849      1.1  christos 		   &now_wall_time, &start_stats->start_wall_time);
    850      1.1  christos 
    851      1.1  christos       /* Subtract time spend in prompt_for_continue from walltime.  */
    852      1.1  christos       wait_time = get_prompt_for_continue_wait_time ();
    853      1.1  christos       timeval_sub (&delta_wall_time, &delta_wall_time, &wait_time);
    854      1.1  christos 
    855      1.1  christos       printf_unfiltered (msg_type == 0
    856      1.1  christos 			 ? _("Startup time: %ld.%06ld (cpu), %ld.%06ld (wall)\n")
    857      1.1  christos 			 : _("Command execution time: %ld.%06ld (cpu), %ld.%06ld (wall)\n"),
    858      1.1  christos 			 cmd_time / 1000000, cmd_time % 1000000,
    859      1.1  christos 			 (long) delta_wall_time.tv_sec,
    860      1.1  christos 			 (long) delta_wall_time.tv_usec);
    861      1.1  christos     }
    862  1.1.1.2  christos 
    863      1.1  christos   if (start_stats->space_enabled && per_command_space)
    864      1.1  christos     {
    865      1.1  christos #ifdef HAVE_SBRK
    866      1.1  christos       char *lim = (char *) sbrk (0);
    867      1.1  christos 
    868      1.1  christos       long space_now = lim - lim_at_start;
    869      1.1  christos       long space_diff = space_now - start_stats->start_space;
    870      1.1  christos 
    871      1.1  christos       printf_unfiltered (msg_type == 0
    872      1.1  christos 			 ? _("Space used: %ld (%s%ld during startup)\n")
    873      1.1  christos 			 : _("Space used: %ld (%s%ld for this command)\n"),
    874      1.1  christos 			 space_now,
    875      1.1  christos 			 (space_diff >= 0 ? "+" : ""),
    876      1.1  christos 			 space_diff);
    877      1.1  christos #endif
    878      1.1  christos     }
    879  1.1.1.2  christos 
    880      1.1  christos   if (start_stats->symtab_enabled && per_command_symtab)
    881  1.1.1.2  christos     {
    882      1.1  christos       int nr_symtabs, nr_compunit_symtabs, nr_blocks;
    883  1.1.1.2  christos 
    884      1.1  christos       count_symtabs_and_blocks (&nr_symtabs, &nr_compunit_symtabs, &nr_blocks);
    885  1.1.1.2  christos       printf_unfiltered (_("#symtabs: %d (+%d),"
    886      1.1  christos 			   " #compunits: %d (+%d),"
    887      1.1  christos 			   " #blocks: %d (+%d)\n"),
    888      1.1  christos 			 nr_symtabs,
    889  1.1.1.2  christos 			 nr_symtabs - start_stats->start_nr_symtabs,
    890  1.1.1.2  christos 			 nr_compunit_symtabs,
    891  1.1.1.2  christos 			 (nr_compunit_symtabs
    892      1.1  christos 			  - start_stats->start_nr_compunit_symtabs),
    893      1.1  christos 			 nr_blocks,
    894      1.1  christos 			 nr_blocks - start_stats->start_nr_blocks);
    895      1.1  christos     }
    896      1.1  christos }
    897      1.1  christos 
    898      1.1  christos /* Create a cleanup that reports time and space used since its creation.
    899      1.1  christos    MSG_TYPE is zero for gdb startup, otherwise it is one(1) to report
    900      1.1  christos    data for individual commands.  */
    901      1.1  christos 
    902      1.1  christos struct cleanup *
    903      1.1  christos make_command_stats_cleanup (int msg_type)
    904      1.1  christos {
    905      1.1  christos   struct cmd_stats *new_stat;
    906  1.1.1.2  christos 
    907  1.1.1.2  christos   /* Early exit if we're not reporting any stats.  It can be expensive to
    908  1.1.1.2  christos      compute the pre-command values so don't collect them at all if we're
    909  1.1.1.2  christos      not reporting stats.  Alas this doesn't work in the startup case because
    910  1.1.1.2  christos      we don't know yet whether we will be reporting the stats.  For the
    911  1.1.1.2  christos      startup case collect the data anyway (it should be cheap at this point),
    912  1.1.1.2  christos      and leave it to the reporter to decide whether to print them.  */
    913  1.1.1.2  christos   if (msg_type != 0
    914      1.1  christos       && !per_command_time
    915      1.1  christos       && !per_command_space
    916      1.1  christos       && !per_command_symtab)
    917      1.1  christos     return make_cleanup (null_cleanup, 0);
    918  1.1.1.2  christos 
    919      1.1  christos   new_stat = XCNEW (struct cmd_stats);
    920      1.1  christos 
    921      1.1  christos   new_stat->msg_type = msg_type;
    922  1.1.1.2  christos 
    923      1.1  christos   if (msg_type == 0 || per_command_space)
    924      1.1  christos     {
    925      1.1  christos #ifdef HAVE_SBRK
    926      1.1  christos       char *lim = (char *) sbrk (0);
    927      1.1  christos       new_stat->start_space = lim - lim_at_start;
    928      1.1  christos       new_stat->space_enabled = 1;
    929      1.1  christos #endif
    930      1.1  christos     }
    931  1.1.1.2  christos 
    932      1.1  christos   if (msg_type == 0 || per_command_time)
    933      1.1  christos     {
    934      1.1  christos       new_stat->start_cpu_time = get_run_time ();
    935      1.1  christos       gettimeofday (&new_stat->start_wall_time, NULL);
    936      1.1  christos       new_stat->time_enabled = 1;
    937      1.1  christos     }
    938  1.1.1.2  christos 
    939      1.1  christos   if (msg_type == 0 || per_command_symtab)
    940  1.1.1.2  christos     {
    941      1.1  christos       int nr_symtabs, nr_compunit_symtabs, nr_blocks;
    942  1.1.1.2  christos 
    943      1.1  christos       count_symtabs_and_blocks (&nr_symtabs, &nr_compunit_symtabs, &nr_blocks);
    944  1.1.1.2  christos       new_stat->start_nr_symtabs = nr_symtabs;
    945      1.1  christos       new_stat->start_nr_compunit_symtabs = nr_compunit_symtabs;
    946      1.1  christos       new_stat->start_nr_blocks = nr_blocks;
    947      1.1  christos       new_stat->symtab_enabled = 1;
    948      1.1  christos     }
    949      1.1  christos 
    950      1.1  christos   /* Initalize timer to keep track of how long we waited for the user.  */
    951      1.1  christos   reset_prompt_for_continue_wait_time ();
    952      1.1  christos 
    953      1.1  christos   return make_cleanup_dtor (report_command_stats, new_stat, xfree);
    954      1.1  christos }
    955      1.1  christos 
    956      1.1  christos /* Handle unknown "mt set per-command" arguments.
    957      1.1  christos    In this case have "mt set per-command on|off" affect every setting.  */
    958      1.1  christos 
    959      1.1  christos static void
    960      1.1  christos set_per_command_cmd (char *args, int from_tty)
    961      1.1  christos {
    962      1.1  christos   struct cmd_list_element *list;
    963      1.1  christos   int val;
    964      1.1  christos 
    965      1.1  christos   val = parse_cli_boolean_value (args);
    966      1.1  christos   if (val < 0)
    967      1.1  christos     error (_("Bad value for 'mt set per-command no'."));
    968      1.1  christos 
    969      1.1  christos   for (list = per_command_setlist; list != NULL; list = list->next)
    970      1.1  christos     if (list->var_type == var_boolean)
    971      1.1  christos       {
    972      1.1  christos 	gdb_assert (list->type == set_cmd);
    973      1.1  christos 	do_set_command (args, from_tty, list);
    974      1.1  christos       }
    975      1.1  christos }
    976      1.1  christos 
    977      1.1  christos /* Command "show per-command" displays summary of all the current
    978      1.1  christos    "show per-command " settings.  */
    979      1.1  christos 
    980      1.1  christos static void
    981      1.1  christos show_per_command_cmd (char *args, int from_tty)
    982      1.1  christos {
    983      1.1  christos   cmd_show_list (per_command_showlist, from_tty, "");
    984      1.1  christos }
    985  1.1.1.4  christos 
    986  1.1.1.4  christos 
    988  1.1.1.4  christos /* The "maintenance selftest" command.  */
    989  1.1.1.4  christos 
    990  1.1.1.4  christos static void
    991  1.1.1.4  christos maintenance_selftest (char *args, int from_tty)
    992  1.1.1.4  christos {
    993  1.1.1.4  christos   run_self_tests ();
    994  1.1.1.4  christos }
    995      1.1  christos 
    996      1.1  christos 
    997      1.1  christos void
    999  1.1.1.2  christos _initialize_maint_cmds (void)
   1000      1.1  christos {
   1001      1.1  christos   struct cmd_list_element *cmd;
   1002      1.1  christos 
   1003  1.1.1.2  christos   add_prefix_cmd ("maintenance", class_maintenance, maintenance_command, _("\
   1004      1.1  christos Commands for use by GDB maintainers.\n\
   1005      1.1  christos Includes commands to dump specific internal GDB structures in\n\
   1006      1.1  christos a human readable form, to cause GDB to deliberately dump core, etc."),
   1007      1.1  christos 		  &maintenancelist, "maintenance ", 0,
   1008      1.1  christos 		  &cmdlist);
   1009      1.1  christos 
   1010      1.1  christos   add_com_alias ("mt", "maintenance", class_maintenance, 1);
   1011      1.1  christos 
   1012      1.1  christos   add_prefix_cmd ("info", class_maintenance, maintenance_info_command, _("\
   1013      1.1  christos Commands for showing internal info about the program being debugged."),
   1014      1.1  christos 		  &maintenanceinfolist, "maintenance info ", 0,
   1015      1.1  christos 		  &maintenancelist);
   1016      1.1  christos   add_alias_cmd ("i", "info", class_maintenance, 1, &maintenancelist);
   1017      1.1  christos 
   1018      1.1  christos   add_cmd ("sections", class_maintenance, maintenance_info_sections, _("\
   1019      1.1  christos List the BFD sections of the exec and core files. \n\
   1020      1.1  christos Arguments may be any combination of:\n\
   1021      1.1  christos 	[one or more section names]\n\
   1022      1.1  christos 	ALLOC LOAD RELOC READONLY CODE DATA ROM CONSTRUCTOR\n\
   1023      1.1  christos 	HAS_CONTENTS NEVER_LOAD COFF_SHARED_LIBRARY IS_COMMON\n\
   1024      1.1  christos Sections matching any argument will be listed (no argument\n\
   1025      1.1  christos implies all sections).  In addition, the special argument\n\
   1026      1.1  christos 	ALLOBJ\n\
   1027      1.1  christos lists all sections from all object files, including shared libraries."),
   1028      1.1  christos 	   &maintenanceinfolist);
   1029      1.1  christos 
   1030      1.1  christos   add_prefix_cmd ("print", class_maintenance, maintenance_print_command,
   1031      1.1  christos 		  _("Maintenance command for printing GDB internal state."),
   1032      1.1  christos 		  &maintenanceprintlist, "maintenance print ", 0,
   1033      1.1  christos 		  &maintenancelist);
   1034      1.1  christos 
   1035      1.1  christos   add_prefix_cmd ("set", class_maintenance, maintenance_set_cmd, _("\
   1036      1.1  christos Set GDB internal variables used by the GDB maintainer.\n\
   1037      1.1  christos Configure variables internal to GDB that aid in GDB's maintenance"),
   1038      1.1  christos 		  &maintenance_set_cmdlist, "maintenance set ",
   1039      1.1  christos 		  0/*allow-unknown*/,
   1040      1.1  christos 		  &maintenancelist);
   1041      1.1  christos 
   1042      1.1  christos   add_prefix_cmd ("show", class_maintenance, maintenance_show_cmd, _("\
   1043      1.1  christos Show GDB internal variables used by the GDB maintainer.\n\
   1044      1.1  christos Configure variables internal to GDB that aid in GDB's maintenance"),
   1045      1.1  christos 		  &maintenance_show_cmdlist, "maintenance show ",
   1046      1.1  christos 		  0/*allow-unknown*/,
   1047      1.1  christos 		  &maintenancelist);
   1048      1.1  christos 
   1049      1.1  christos #ifndef _WIN32
   1050      1.1  christos   add_cmd ("dump-me", class_maintenance, maintenance_dump_me, _("\
   1051      1.1  christos Get fatal error; make debugger dump its core.\n\
   1052      1.1  christos GDB sets its handling of SIGQUIT back to SIG_DFL and then sends\n\
   1053      1.1  christos itself a SIGQUIT signal."),
   1054      1.1  christos 	   &maintenancelist);
   1055      1.1  christos #endif
   1056      1.1  christos 
   1057      1.1  christos   add_cmd ("internal-error", class_maintenance,
   1058      1.1  christos 	   maintenance_internal_error, _("\
   1059      1.1  christos Give GDB an internal error.\n\
   1060      1.1  christos Cause GDB to behave as if an internal error was detected."),
   1061      1.1  christos 	   &maintenancelist);
   1062      1.1  christos 
   1063      1.1  christos   add_cmd ("internal-warning", class_maintenance,
   1064      1.1  christos 	   maintenance_internal_warning, _("\
   1065      1.1  christos Give GDB an internal warning.\n\
   1066  1.1.1.2  christos Cause GDB to behave as if an internal warning was reported."),
   1067  1.1.1.2  christos 	   &maintenancelist);
   1068  1.1.1.2  christos 
   1069  1.1.1.2  christos   add_cmd ("demangler-warning", class_maintenance,
   1070      1.1  christos 	   maintenance_demangler_warning, _("\
   1071      1.1  christos Give GDB a demangler warning.\n\
   1072  1.1.1.2  christos Cause GDB to behave as if a demangler warning was reported."),
   1073  1.1.1.2  christos 	   &maintenancelist);
   1074  1.1.1.2  christos 
   1075  1.1.1.2  christos   cmd = add_cmd ("demangle", class_maintenance, maintenance_demangle, _("\
   1076  1.1.1.2  christos This command has been moved to \"demangle\"."),
   1077      1.1  christos 		 &maintenancelist);
   1078      1.1  christos   deprecate_cmd (cmd, "demangle");
   1079      1.1  christos 
   1080      1.1  christos   add_prefix_cmd ("per-command", class_maintenance, set_per_command_cmd, _("\
   1081      1.1  christos Per-command statistics settings."),
   1082      1.1  christos 		    &per_command_setlist, "set per-command ",
   1083      1.1  christos 		    1/*allow-unknown*/, &maintenance_set_cmdlist);
   1084      1.1  christos 
   1085      1.1  christos   add_prefix_cmd ("per-command", class_maintenance, show_per_command_cmd, _("\
   1086      1.1  christos Show per-command statistics settings."),
   1087      1.1  christos 		    &per_command_showlist, "show per-command ",
   1088      1.1  christos 		    0/*allow-unknown*/, &maintenance_show_cmdlist);
   1089      1.1  christos 
   1090      1.1  christos   add_setshow_boolean_cmd ("time", class_maintenance,
   1091      1.1  christos 			   &per_command_time, _("\
   1092      1.1  christos Set whether to display per-command execution time."), _("\
   1093      1.1  christos Show whether to display per-command execution time."),
   1094      1.1  christos 			   _("\
   1095      1.1  christos If enabled, the execution time for each command will be\n\
   1096      1.1  christos displayed following the command's output."),
   1097      1.1  christos 			   NULL, NULL,
   1098      1.1  christos 			   &per_command_setlist, &per_command_showlist);
   1099      1.1  christos 
   1100      1.1  christos   add_setshow_boolean_cmd ("space", class_maintenance,
   1101      1.1  christos 			   &per_command_space, _("\
   1102      1.1  christos Set whether to display per-command space usage."), _("\
   1103      1.1  christos Show whether to display per-command space usage."),
   1104      1.1  christos 			   _("\
   1105      1.1  christos If enabled, the space usage for each command will be\n\
   1106      1.1  christos displayed following the command's output."),
   1107      1.1  christos 			   NULL, NULL,
   1108      1.1  christos 			   &per_command_setlist, &per_command_showlist);
   1109      1.1  christos 
   1110      1.1  christos   add_setshow_boolean_cmd ("symtab", class_maintenance,
   1111      1.1  christos 			   &per_command_symtab, _("\
   1112      1.1  christos Set whether to display per-command symtab statistics."), _("\
   1113      1.1  christos Show whether to display per-command symtab statistics."),
   1114      1.1  christos 			   _("\
   1115      1.1  christos If enabled, the basic symtab statistics for each command will be\n\
   1116      1.1  christos displayed following the command's output."),
   1117      1.1  christos 			   NULL, NULL,
   1118      1.1  christos 			   &per_command_setlist, &per_command_showlist);
   1119      1.1  christos 
   1120      1.1  christos   /* This is equivalent to "mt set per-command time on".
   1121      1.1  christos      Kept because some people are used to typing "mt time 1".  */
   1122      1.1  christos   add_cmd ("time", class_maintenance, maintenance_time_display, _("\
   1123      1.1  christos Set the display of time usage.\n\
   1124      1.1  christos If nonzero, will cause the execution time for each command to be\n\
   1125      1.1  christos displayed, following the command's output."),
   1126      1.1  christos 	   &maintenancelist);
   1127      1.1  christos 
   1128      1.1  christos   /* This is equivalent to "mt set per-command space on".
   1129      1.1  christos      Kept because some people are used to typing "mt space 1".  */
   1130      1.1  christos   add_cmd ("space", class_maintenance, maintenance_space_display, _("\
   1131      1.1  christos Set the display of space usage.\n\
   1132      1.1  christos If nonzero, will cause the execution space for each command to be\n\
   1133      1.1  christos displayed, following the command's output."),
   1134      1.1  christos 	   &maintenancelist);
   1135      1.1  christos 
   1136      1.1  christos   add_cmd ("type", class_maintenance, maintenance_print_type, _("\
   1137      1.1  christos Print a type chain for a given symbol.\n\
   1138      1.1  christos For each node in a type chain, print the raw data for each member of\n\
   1139      1.1  christos the type structure, and the interpretation of the data."),
   1140      1.1  christos 	   &maintenanceprintlist);
   1141      1.1  christos 
   1142      1.1  christos   add_cmd ("statistics", class_maintenance, maintenance_print_statistics,
   1143      1.1  christos 	   _("Print statistics about internal gdb state."),
   1144      1.1  christos 	   &maintenanceprintlist);
   1145      1.1  christos 
   1146      1.1  christos   add_cmd ("architecture", class_maintenance,
   1147      1.1  christos 	   maintenance_print_architecture, _("\
   1148      1.1  christos Print the internal architecture configuration.\n\
   1149      1.1  christos Takes an optional file parameter."),
   1150      1.1  christos 	   &maintenanceprintlist);
   1151      1.1  christos 
   1152      1.1  christos   add_cmd ("translate-address", class_maintenance,
   1153      1.1  christos 	   maintenance_translate_address,
   1154      1.1  christos 	   _("Translate a section name and address to a symbol."),
   1155      1.1  christos 	   &maintenancelist);
   1156      1.1  christos 
   1157      1.1  christos   add_cmd ("deprecate", class_maintenance, maintenance_deprecate, _("\
   1158      1.1  christos Deprecate a command.  Note that this is just in here so the \n\
   1159      1.1  christos testsuite can check the command deprecator. You probably shouldn't use this,\n\
   1160      1.1  christos rather you should use the C function deprecate_cmd().  If you decide you \n\
   1161      1.1  christos want to use it: maintenance deprecate 'commandname' \"replacement\". The \n\
   1162      1.1  christos replacement is optional."), &maintenancelist);
   1163      1.1  christos 
   1164      1.1  christos   add_cmd ("undeprecate", class_maintenance, maintenance_undeprecate, _("\
   1165      1.1  christos Undeprecate a command.  Note that this is just in here so the \n\
   1166      1.1  christos testsuite can check the command deprecator. You probably shouldn't use this,\n\
   1167  1.1.1.4  christos If you decide you want to use it: maintenance undeprecate 'commandname'"),
   1168  1.1.1.4  christos 	   &maintenancelist);
   1169  1.1.1.4  christos 
   1170  1.1.1.4  christos   add_cmd ("selftest", class_maintenance, maintenance_selftest, _("\
   1171  1.1.1.4  christos Run gdb's unit tests.\n\
   1172  1.1.1.4  christos Usage: maintenance selftest\n\
   1173  1.1.1.4  christos This will run any unit tests that were built in to gdb.\n\
   1174      1.1  christos gdb will abort if any test fails."),
   1175      1.1  christos 	   &maintenancelist);
   1176      1.1  christos 
   1177      1.1  christos   add_setshow_zinteger_cmd ("watchdog", class_maintenance, &watchdog, _("\
   1178      1.1  christos Set watchdog timer."), _("\
   1179      1.1  christos Show watchdog timer."), _("\
   1180      1.1  christos When non-zero, this timeout is used instead of waiting forever for a target\n\
   1181      1.1  christos to finish a low-level step or continue operation.  If the specified amount\n\
   1182      1.1  christos of time passes without a response from the target, an error occurs."),
   1183      1.1  christos 			    NULL,
   1184      1.1  christos 			    show_watchdog,
   1185      1.1  christos 			    &setlist, &showlist);
   1186      1.1  christos 
   1187      1.1  christos   add_setshow_boolean_cmd ("profile", class_maintenance,
   1188      1.1  christos 			   &maintenance_profile_p, _("\
   1189      1.1  christos Set internal profiling."), _("\
   1190      1.1  christos Show internal profiling."), _("\
   1191      1.1  christos When enabled GDB is profiled."),
   1192      1.1  christos 			   maintenance_set_profile_cmd,
   1193      1.1  christos 			   show_maintenance_profile_p,
   1194                    			   &maintenance_set_cmdlist,
   1195                    			   &maintenance_show_cmdlist);
   1196                    }
   1197