+
+/* When a command is deprecated the user will be warned the first time
+ the command is used. If possible, a replacement will be
+ offered. */
+
+static void
+maintenance_deprecate (char *args, int from_tty)
+{
+ if (args == NULL || *args == '\0')
+ {
+ printf_unfiltered ("\"maintenance deprecate\" takes an argument, \n\
+the command you want to deprecate, and optionally the replacement command \n\
+enclosed in quotes.\n");
+ }
+
+ maintenance_do_deprecate (args, 1);
+
+}
+
+
+static void
+maintenance_undeprecate (char *args, int from_tty)
+{
+ if (args == NULL || *args == '\0')
+ {
+ printf_unfiltered ("\"maintenance undeprecate\" takes an argument, \n\
+the command you want to undeprecate.\n");
+ }
+
+ maintenance_do_deprecate (args, 0);
+
+}
+
+/* You really shouldn't be using this. It is just for the testsuite.
+ Rather, you should use deprecate_cmd() when the command is created
+ in _initialize_blah().
+
+ This function deprecates a command and optionally assigns it a
+ replacement. */
+
+static void
+maintenance_do_deprecate (char *text, int deprecate)
+{
+
+ struct cmd_list_element *alias = NULL;
+ struct cmd_list_element *prefix_cmd = NULL;
+ struct cmd_list_element *cmd = NULL;
+
+ char *start_ptr = NULL;
+ char *end_ptr = NULL;
+ int len;
+ char *replacement = NULL;
+
+ if (text == NULL)
+ return;
+
+ if (!lookup_cmd_composition (text, &alias, &prefix_cmd, &cmd))
+ {
+ printf_filtered ("Can't find command '%s' to deprecate.\n", text);
+ return;
+ }
+
+ if (deprecate)
+ {
+ /* look for a replacement command */
+ start_ptr = strchr (text, '\"');
+ if (start_ptr != NULL)
+ {
+ start_ptr++;
+ end_ptr = strrchr (start_ptr, '\"');
+ if (end_ptr != NULL)
+ {
+ len = end_ptr - start_ptr;
+ start_ptr[len] = '\0';
+ replacement = xstrdup (start_ptr);
+ }
+ }
+ }
+
+ if (!start_ptr || !end_ptr)
+ replacement = NULL;
+
+
+ /* If they used an alias, we only want to deprecate the alias.
+
+ Note the MALLOCED_REPLACEMENT test. If the command's replacement
+ string was allocated at compile time we don't want to free the
+ memory. */
+ if (alias)
+ {
+
+ if (alias->flags & MALLOCED_REPLACEMENT)
+ xfree (alias->replacement);
+
+ if (deprecate)
+ alias->flags |= (DEPRECATED_WARN_USER | CMD_DEPRECATED);
+ else
+ alias->flags &= ~(DEPRECATED_WARN_USER | CMD_DEPRECATED);
+ alias->replacement = replacement;
+ alias->flags |= MALLOCED_REPLACEMENT;
+ return;
+ }
+ else if (cmd)
+ {
+ if (cmd->flags & MALLOCED_REPLACEMENT)
+ xfree (cmd->replacement);
+
+ if (deprecate)
+ cmd->flags |= (DEPRECATED_WARN_USER | CMD_DEPRECATED);
+ else
+ cmd->flags &= ~(DEPRECATED_WARN_USER | CMD_DEPRECATED);
+ cmd->replacement = replacement;
+ cmd->flags |= MALLOCED_REPLACEMENT;
+ return;
+ }
+}
+
+/* Maintenance set/show framework. */
+
+static struct cmd_list_element *maintenance_set_cmdlist;
+static struct cmd_list_element *maintenance_show_cmdlist;
+
+static void
+maintenance_set_cmd (char *args, int from_tty)
+{
+ printf_unfiltered ("\"maintenance set\" must be followed by the name of a set command.\n");
+ help_list (maintenance_set_cmdlist, "maintenance set ", -1, gdb_stdout);
+}
+
+static void
+maintenance_show_cmd (char *args, int from_tty)
+{
+ cmd_show_list (maintenance_show_cmdlist, from_tty, "");
+}
+
+/* Profiling support. */
+
+static int maintenance_profile_p;
+
+#if defined (HAVE_MONSTARTUP) && defined (HAVE__MCLEANUP)
+
+static int profiling_state;
+
+static void
+mcleanup_wrapper (void)
+{
+ extern void _mcleanup (void);
+
+ if (profiling_state)
+ _mcleanup ();
+}
+
+static void
+maintenance_set_profile_cmd (char *args, int from_tty, struct cmd_list_element *c)
+{
+ if (maintenance_profile_p == profiling_state)
+ return;
+
+ profiling_state = maintenance_profile_p;
+
+ if (maintenance_profile_p)
+ {
+ static int profiling_initialized;
+
+ extern void monstartup (unsigned long, unsigned long);
+ extern char _etext;
+ extern int main();
+
+ if (!profiling_initialized)
+ {
+ atexit (mcleanup_wrapper);
+ profiling_initialized = 1;
+ }
+
+ /* "main" is now always the first function in the text segment, so use
+ its address for monstartup. */
+ monstartup ((unsigned long) &main, (unsigned long) &_etext);
+ }
+ else
+ {
+ extern void _mcleanup (void);
+ _mcleanup ();
+ }
+}
+#else
+static void
+maintenance_set_profile_cmd (char *args, int from_tty, struct cmd_list_element *c)
+{
+ error ("Profiling support is not available on this system.");
+}
+#endif