summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/monitor
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-12-18 15:25:27 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-12-18 15:25:27 +0000
commite41eaa881a1a0ba6645d4a23d1313088c8ccfb7f (patch)
tree01edbddc5c654a1fb474fbccf56654bf35eadf1b /cpukit/libmisc/monitor
parent2008-12-17 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-e41eaa881a1a0ba6645d4a23d1313088c8ccfb7f.tar.bz2
2008-12-18 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libmisc/serdbg/termios_printk.c, libmisc/serdbg/termios_printk.h: Fixed incompatible return value. * libmisc/cpuuse/cpuusagereport.c: Changed output format. * libmisc/Makefile.am, libmisc/monitor/mon-editor.c: New file. * libmisc/capture/capture-cli.c, libmisc/monitor/mon-command.c, libmisc/monitor/mon-monitor.c, libmisc/monitor/mon-object.c, libmisc/monitor/mon-prmisc.c, libmisc/monitor/mon-symbols.c, libmisc/monitor/monitor.h, libmisc/shell/cat_file.c, libmisc/shell/cmds.c, libmisc/shell/internal.h, libmisc/shell/main_help.c, libmisc/shell/shell.c, libmisc/shell/shell.h, libmisc/shell/shell_cmdset.c, libmisc/shell/shell_getchar.c, libmisc/shell/str2int.c: Various global data is now read only. Added 'const' qualifier to many pointer parameters. It is no longer possible to remove monitor commands. Moved monitor line editor into a separate file to avoid unnecessary dependencies.
Diffstat (limited to '')
-rw-r--r--cpukit/libmisc/monitor/mon-command.c610
-rw-r--r--cpukit/libmisc/monitor/mon-editor.c662
-rw-r--r--cpukit/libmisc/monitor/mon-monitor.c275
-rw-r--r--cpukit/libmisc/monitor/mon-object.c24
-rw-r--r--cpukit/libmisc/monitor/mon-prmisc.c12
-rw-r--r--cpukit/libmisc/monitor/mon-symbols.c17
-rw-r--r--cpukit/libmisc/monitor/monitor.h67
7 files changed, 829 insertions, 838 deletions
diff --git a/cpukit/libmisc/monitor/mon-command.c b/cpukit/libmisc/monitor/mon-command.c
index 3d2732121a..e5ee6aee53 100644
--- a/cpukit/libmisc/monitor/mon-command.c
+++ b/cpukit/libmisc/monitor/mon-command.c
@@ -1,29 +1,12 @@
-/*
- * Command parsing routines for RTEMS monitor
- *
- * TODO:
+/**
+ * @file
*
- * $Id$
+ * @brief Command support routines for RTEMS monitor.
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems.h>
-
-#include <rtems/monitor.h>
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <inttypes.h>
-
-#ifndef MONITOR_PROMPT
-#define MONITOR_PROMPT "rtems" /* will have '> ' appended */
-#endif
-
/*
+ * $Id$
+ *
* 2001-01-30 KJO (vac4050@cae597.rsc.raytheon.com):
* Fixed rtems_monitor_command_lookup() to accept partial
* commands to uniqeness. Added support for setting
@@ -35,554 +18,58 @@
* covered by GPL, only the RTEMS license.
*/
-/*
- * Some key labels to define special keys.
- */
-
-#define KEYS_EXTENDED (0x8000)
-#define KEYS_NORMAL_MASK (0x00ff)
-#define KEYS_INS (0)
-#define KEYS_DEL (1)
-#define KEYS_UARROW (2)
-#define KEYS_DARROW (3)
-#define KEYS_LARROW (4)
-#define KEYS_RARROW (5)
-#define KEYS_HOME (6)
-#define KEYS_END (7)
-#define KEYS_F1 (8)
-#define KEYS_F2 (9)
-#define KEYS_F3 (10)
-#define KEYS_F4 (11)
-#define KEYS_F5 (12)
-#define KEYS_F6 (13)
-#define KEYS_F7 (14)
-#define KEYS_F8 (15)
-#define KEYS_F9 (16)
-#define KEYS_F10 (17)
-
-#define RTEMS_COMMAND_BUFFER_SIZE (75)
-
-static char monitor_prompt[32];
-#ifndef RTEMS_UNIX
-static char buffer[RTEMS_COMMAND_BUFFER_SIZE];
-static int pos;
-static int logged_in;
-#endif
-/*
- * History data.
- */
-
-#define RTEMS_COMMAND_HISTORIES (20)
-
-#ifndef RTEMS_UNIX
-static char history_buffer[RTEMS_COMMAND_HISTORIES][RTEMS_COMMAND_BUFFER_SIZE];
-static int history_pos[RTEMS_COMMAND_HISTORIES];
-static int history;
-static int history_next;
-#endif
-
-/*
- * Translation tables. Not sure if this is the best way to
- * handle this, how-ever I wish to avoid the overhead of
- * including a more complete and standard environment such
- * as ncurses.
- */
-
-struct translation_table
-{
- char expecting;
- struct translation_table *branch;
- unsigned int key;
-};
-
-#ifndef RTEMS_UNIX
-static struct translation_table trans_two[] =
-{
- { '~', 0, KEYS_INS },
- { 0, 0, 0 }
-};
-
-static struct translation_table trans_three[] =
-{
- { '~', 0, KEYS_DEL },
- { 0, 0, 0 }
-};
-
-static struct translation_table trans_tab_csi[] =
-{
- { '2', trans_two, 0 },
- { '3', trans_three, 0 },
- { 'A', 0, KEYS_UARROW },
- { 'B', 0, KEYS_DARROW },
- { 'D', 0, KEYS_LARROW },
- { 'C', 0, KEYS_RARROW },
- { 'F', 0, KEYS_END },
- { 'H', 0, KEYS_HOME },
- { 0, 0, 0 }
-};
-
-static struct translation_table trans_tab_O[] =
-{
- { '1', 0, KEYS_F1 },
- { '2', 0, KEYS_F2 },
- { '3', 0, KEYS_F3 },
- { '4', 0, KEYS_F4 },
- { '5', 0, KEYS_F5 },
- { '6', 0, KEYS_F6 },
- { '7', 0, KEYS_F7 },
- { '8', 0, KEYS_F8 },
- { '9', 0, KEYS_F9 },
- { ':', 0, KEYS_F10 },
- { 'P', 0, KEYS_F1 },
- { 'Q', 0, KEYS_F2 },
- { 'R', 0, KEYS_F3 },
- { 'S', 0, KEYS_F4 },
- { 'T', 0, KEYS_F5 },
- { 'U', 0, KEYS_F6 },
- { 'V', 0, KEYS_F7 },
- { 'W', 0, KEYS_F8 },
- { 'X', 0, KEYS_F9 },
- { 'Y', 0, KEYS_F10 },
- { 0, 0, 0 }
-};
-
-static struct translation_table trans_tab[] =
-{
- { '[', trans_tab_csi, 0 }, /* CSI command sequences */
- { 'O', trans_tab_O, 0 }, /* O are the fuction keys */
- { 0, 0, 0 }
-};
-#endif
-
-/*
- * Perform a basic translation for some ANSI/VT100 key codes.
- * This code could do with a timeout on the ESC as it is
- * now lost from the input stream. It is not* used by the
- * line editor below so considiered not worth the effort.
- */
-
-#ifndef RTEMS_UNIX
-static unsigned int
-rtems_monitor_getchar (void)
-{
- struct translation_table *translation = 0;
- for (;;)
- {
- char c = getchar ();
- if (c == 27)
- translation = trans_tab;
- else
- {
- /*
- * If no translation happing just pass through
- * and return the key.
- */
- if (translation)
- {
- /*
- * Scan the current table for the key, and if found
- * see if this key is a fork. If so follow it and
- * wait else return the extended key.
- */
- int index = 0;
- int branched = 0;
- while ((translation[index].expecting != '\0') ||
- (translation[index].key != '\0'))
- {
- if (translation[index].expecting == c)
- {
- /*
- * A branch is take if more keys are to come.
- */
- if (translation[index].branch == 0)
- return KEYS_EXTENDED | translation[index].key;
- else
- {
- translation = translation[index].branch;
- branched = 1;
- break;
- }
- }
- index++;
- }
- /*
- * Who knows what these keys are, just drop them.
- */
- if (!branched)
- translation = 0;
- }
- else
- return c;
- }
- }
-}
-#endif
-
-#ifndef RTEMS_UNIX
-/*
- * The line editor with history.
- */
-
-static int
-rtems_monitor_line_editor (
- char *command
-)
-{
- int repeating = 0;
-
- memset (buffer, 0, RTEMS_COMMAND_BUFFER_SIZE);
- history = history_next;
- pos = 0;
-
- if (!logged_in)
- fprintf(stdout,"\nMonitor ready, press enter to login.\n\n");
- else
- fprintf(stdout,"%s $ ", monitor_prompt);
-
- while (1)
- {
- unsigned int extended_key;
- char c;
-
- fflush (stdout);
-
- extended_key = rtems_monitor_getchar ();
- c = extended_key & KEYS_NORMAL_MASK;
-
- /*
- * Make the extended_key usable as a boolean.
- */
- extended_key &= ~KEYS_NORMAL_MASK;
-
- if (!extended_key && !logged_in)
- {
- if (c == '\n')
- {
- logged_in = 1;
- /*
- * The prompt has changed from `>' to `$' to help know
- * which version of the monitor code people are using.
- */
- fprintf(stdout,"%s $ ", monitor_prompt);
- }
- }
- else
- {
- if (extended_key)
- {
- switch (c)
- {
- case KEYS_END:
- fprintf(stdout,buffer + pos);
- pos = (int) strlen (buffer);
- break;
-
- case KEYS_HOME:
- fprintf(stdout,"\r%s $ ", monitor_prompt);
- pos = 0;
- break;
-
- case KEYS_LARROW:
- if (pos > 0)
- {
- pos--;
- putchar ('\b');
- }
- break;
-
- case KEYS_RARROW:
- if ((pos < RTEMS_COMMAND_BUFFER_SIZE) && (buffer[pos] != '\0'))
- {
- putchar (buffer[pos]);
- pos++;
- }
- break;
-
- case KEYS_UARROW:
- /*
- * If we are moving up the histories then we need to save the working
- * buffer.
- */
- if (history)
- {
- int end;
- int bs;
- if (history == history_next)
- {
- memcpy (history_buffer[history_next], buffer,
- RTEMS_COMMAND_BUFFER_SIZE);
- history_pos[history_next] = pos;
- }
- history--;
- memcpy (buffer, history_buffer[history],
- RTEMS_COMMAND_BUFFER_SIZE);
- pos = history_pos[history];
- fprintf(stdout,"\r%*c", RTEMS_COMMAND_BUFFER_SIZE, ' ');
- fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
- end = (int) strlen (buffer);
- for (bs = 0; bs < (end - pos); bs++)
- putchar ('\b');
- }
- break;
-
- case KEYS_DARROW:
- if (history < history_next)
- {
- int end;
- int bs;
- history++;
- memcpy (buffer, history_buffer[history],
- RTEMS_COMMAND_BUFFER_SIZE);
- pos = history_pos[history];
- fprintf(stdout,"\r%*c", RTEMS_COMMAND_BUFFER_SIZE, ' ');
- fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
- end = (int) strlen (buffer);
- for (bs = 0; bs < (end - pos); bs++)
- putchar ('\b');
- }
- break;
-
- case KEYS_DEL:
- if (buffer[pos] != '\0')
- {
- int end;
- int bs;
- strcpy (&buffer[pos], &buffer[pos + 1]);
- fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
- end = (int) strlen (buffer);
- for (bs = 0; bs < (end - pos); bs++)
- putchar ('\b');
- }
- break;
- }
- }
- else
- {
- switch (c)
- {
- case '\b':
- case '\x7e':
- case '\x7f':
- if (pos > 0)
- {
- int bs;
- pos--;
- strcpy (buffer + pos, buffer + pos + 1);
- fprintf(stdout,"\b%s \b", buffer + pos);
- for (bs = 0; bs < ((int) strlen (buffer) - pos); bs++)
- putchar ('\b');
- }
- break;
-
- case '\n':
- /*
- * Process the command.
- */
- fprintf(stdout,"\n");
- repeating = 1;
- /*
- * Only process the history if we have a command and
- *a history.
- */
- if (strlen (buffer))
- {
- if (history_next && (history == history_next))
- {
- /*
- * Do not place the last command into the history
- *if the same.
- */
- if (strcmp (history_buffer[history_next - 1], buffer))
- repeating = 0;
- }
- else
- repeating = 0;
- }
- if (!repeating)
- {
- memcpy (history_buffer[history_next], buffer,
- RTEMS_COMMAND_BUFFER_SIZE);
- history_pos[history_next] = pos;
- if (history_next < (RTEMS_COMMAND_HISTORIES - 1))
- history_next++;
- else
- {
- memmove (history_buffer[0], history_buffer[1],
- RTEMS_COMMAND_BUFFER_SIZE * (RTEMS_COMMAND_HISTORIES - 1));
- memmove (&history_pos[0], &history_pos[1],
- sizeof (history_pos[0]) * (RTEMS_COMMAND_HISTORIES - 1));
- }
- }
- else
- {
-#ifdef ENABLE_ENTER_REPEATS
- if (history_next)
- memcpy (buffer, history_buffer[history_next - 1],
- RTEMS_COMMAND_BUFFER_SIZE);
-#endif
- }
- memmove (command, buffer, RTEMS_COMMAND_BUFFER_SIZE);
- return repeating;
- break;
-
- default:
- if ((pos < (RTEMS_COMMAND_BUFFER_SIZE - 1)) &&
- (c >= ' ') && (c <= 'z'))
- {
- int end;
- end = strlen (buffer);
- if ((pos < end) && (end < RTEMS_COMMAND_BUFFER_SIZE))
- {
- int ch, bs;
- for (ch = end + 1; ch > pos; ch--)
- buffer[ch] = buffer[ch - 1];
- fprintf(stdout,buffer + pos);
- for (bs = 0; bs < (end - pos + 1); bs++)
- putchar ('\b');
- }
- buffer[pos++] = c;
- if (pos > end)
- buffer[pos] = '\0';
- putchar (c);
- }
- break;
- }
- }
- }
- }
-}
-#endif
-
-/*
- * make_argv(cp): token-count
- * Break up the command line in 'cp' into global argv[] and argc (return
- * value).
- */
-
-int
-rtems_monitor_make_argv(
- char *cp,
- int *argc_p,
- char **argv)
-{
- int argc = 0;
-
- while ((cp = strtok(cp, " \t\n\r")))
- {
- argv[argc++] = cp;
- cp = (char *) NULL;
- }
- argv[argc] = (char *) NULL; /* end of argv */
-
- return *argc_p = argc;
-}
-
-
-/*
- * Read and break up a monitor command
- *
- * We have to loop on the gets call, since it will return NULL under UNIX
- * RTEMS when we get a signal (eg: SIGALRM).
- */
-
-int
-rtems_monitor_command_read(char *command,
- int *argc,
- char **argv)
-{
- char *env_prompt;
-
- env_prompt = getenv("RTEMS_MONITOR_PROMPT");
+#include <string.h>
+#include <stdio.h>
- /*
- * put node number in the prompt if we are multiprocessing
- */
-#if defined(RTEMS_MULTIPROCESSING)
- if (!rtems_configuration_get_user_multiprocessing_table ())
- sprintf (monitor_prompt, "%s",
- (env_prompt == NULL) ? MONITOR_PROMPT: env_prompt);
- else /* .... */
-#endif
- if (rtems_monitor_default_node != rtems_monitor_node)
- sprintf (monitor_prompt, "%" PRId32 "-%s-%" PRId32 "", rtems_monitor_node,
- (env_prompt == NULL) ? MONITOR_PROMPT : env_prompt,
- rtems_monitor_default_node);
- else
- sprintf (monitor_prompt, "%" PRId32 "-%s", rtems_monitor_node,
- (env_prompt == NULL) ? MONITOR_PROMPT : env_prompt);
-
-#if defined(RTEMS_UNIX)
- /* RTEMS on unix gets so many interrupt system calls this is hosed */
- fprintf(stdout,"%s> ", monitor_prompt);
- fflush (stdout);
- while (gets(command) == (char *) 0)
- ;
-#else
- rtems_monitor_line_editor (command);
-#endif
-
- return rtems_monitor_make_argv (command, argc, argv);
-}
+#include <rtems.h>
+#include <rtems/monitor.h>
/*
* Look up a command in a command table
*
*/
-rtems_monitor_command_entry_t *
-rtems_monitor_command_lookup(
- rtems_monitor_command_entry_t *table,
- int argc,
- char **argv
+const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(
+ const rtems_monitor_command_entry_t *table,
+ const char *command_name
)
{
- int command_length;
- rtems_monitor_command_entry_t *found_it = NULL;
-
- command_length = strlen (argv[0]);
+ const rtems_monitor_command_entry_t *found_it = NULL;
+ size_t command_length = 0;
- if ((table == 0) || (argv[0] == 0))
- return 0;
-
- while (table)
- {
- if (table->command)
- {
+ if (command_name == NULL) {
+ return NULL;
+ }
- /*
- * Check for ambiguity
- */
- if (!strncmp (table->command, argv[0], command_length))
- {
- if (found_it)
- {
- return 0;
- }
+ command_length = strlen(command_name);
- else
+ while (table != NULL) {
+ if (table->command != NULL) {
+ /* Check for ambiguity */
+ if (!strncmp(table->command, command_name, command_length)) {
+ if (found_it == NULL) {
found_it = table;
+ } else {
+ return NULL;
+ }
}
}
table = table->next;
}
- /*
- * No ambiguity (the possible partial command was unique after all)
- */
- if (found_it)
- {
- if (found_it->command_function == 0)
- return 0;
+ /* No ambiguity (the possible partial command was unique after all) */
- return found_it;
+ /* Ignore empty commands */
+ if (found_it == NULL || found_it->command_function == NULL) {
+ return NULL;
}
- return 0;
+ return found_it;
}
static void
rtems_monitor_show_help (
- rtems_monitor_command_entry_t *help_cmd,
+ const rtems_monitor_command_entry_t *help_cmd,
int max_cmd_len
)
{
@@ -675,26 +162,21 @@ rtems_monitor_show_help (
void
rtems_monitor_command_usage(
- rtems_monitor_command_entry_t *table,
- char *command_string
+ const rtems_monitor_command_entry_t *table,
+ const char *command_name
)
{
- rtems_monitor_command_entry_t *command = table;
+ const rtems_monitor_command_entry_t *command = table;
int max_cmd_len = 0;
/* if first entry in table is a usage, then print it out */
- if (command_string && (*command_string != '\0'))
+ if (command_name && (*command_name != '\0'))
{
- char *argv[2];
-
- argv[0] = command_string;
- argv[1] = 0;
-
- command = rtems_monitor_command_lookup (table, 1, argv);
+ command = rtems_monitor_command_lookup (table, command_name);
if (command)
- rtems_monitor_show_help (command, strlen (command_string));
+ rtems_monitor_show_help (command, strlen (command_name));
else
fprintf(stdout,"Unrecognised command; try just 'help'\n");
return;
@@ -730,18 +212,16 @@ rtems_monitor_command_usage(
}
-void
-rtems_monitor_help_cmd(
- int argc,
- char **argv,
- rtems_monitor_command_arg_t *command_arg,
- bool verbose
+void rtems_monitor_help_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
)
{
int arg;
- rtems_monitor_command_entry_t *command;
-
- command = command_arg->monitor_command_entry;
+ const rtems_monitor_command_entry_t *command =
+ command_arg->monitor_command_entry;
if (argc == 1)
rtems_monitor_command_usage(command, 0);
diff --git a/cpukit/libmisc/monitor/mon-editor.c b/cpukit/libmisc/monitor/mon-editor.c
new file mode 100644
index 0000000000..c204e2716c
--- /dev/null
+++ b/cpukit/libmisc/monitor/mon-editor.c
@@ -0,0 +1,662 @@
+/**
+ * @file
+ *
+ * @brief Command line editor for RTEMS monitor.
+ */
+
+/*
+ * $Id$
+ *
+ * 2001-01-30 KJO (vac4050@cae597.rsc.raytheon.com):
+ * Fixed rtems_monitor_command_lookup() to accept partial
+ * commands to uniqeness. Added support for setting
+ * the monitor prompt via an environment variable:
+ * RTEMS_MONITOR_PROMPT
+ *
+ * CCJ: 26-3-2000, adding command history and command line
+ * editing. This code is donated from My Right Boot and not
+ * covered by GPL, only the RTEMS license.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+
+#include <rtems/monitor.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <termios.h>
+#include <unistd.h>
+
+#ifndef MONITOR_PROMPT
+#define MONITOR_PROMPT "rtems" /* will have '> ' appended */
+#endif
+
+/*
+ * Some key labels to define special keys.
+ */
+
+#define KEYS_EXTENDED (0x8000)
+#define KEYS_NORMAL_MASK (0x00ff)
+#define KEYS_INS (0)
+#define KEYS_DEL (1)
+#define KEYS_UARROW (2)
+#define KEYS_DARROW (3)
+#define KEYS_LARROW (4)
+#define KEYS_RARROW (5)
+#define KEYS_HOME (6)
+#define KEYS_END (7)
+#define KEYS_F1 (8)
+#define KEYS_F2 (9)
+#define KEYS_F3 (10)
+#define KEYS_F4 (11)
+#define KEYS_F5 (12)
+#define KEYS_F6 (13)
+#define KEYS_F7 (14)
+#define KEYS_F8 (15)
+#define KEYS_F9 (16)
+#define KEYS_F10 (17)
+
+#define RTEMS_COMMAND_BUFFER_SIZE (75)
+
+static char monitor_prompt[32];
+#ifndef RTEMS_UNIX
+static char buffer[RTEMS_COMMAND_BUFFER_SIZE];
+static int pos;
+static int logged_in;
+#endif
+/*
+ * History data.
+ */
+
+#define RTEMS_COMMAND_HISTORIES (20)
+
+#ifndef RTEMS_UNIX
+static char history_buffer[RTEMS_COMMAND_HISTORIES][RTEMS_COMMAND_BUFFER_SIZE];
+static int history_pos[RTEMS_COMMAND_HISTORIES];
+static int history;
+static int history_next;
+#endif
+
+/*
+ * Translation tables. Not sure if this is the best way to
+ * handle this, how-ever I wish to avoid the overhead of
+ * including a more complete and standard environment such
+ * as ncurses.
+ */
+
+struct translation_table
+{
+ char expecting;
+ const struct translation_table *branch;
+ unsigned int key;
+};
+
+#ifndef RTEMS_UNIX
+static const struct translation_table trans_two[] =
+{
+ { '~', 0, KEYS_INS },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_three[] =
+{
+ { '~', 0, KEYS_DEL },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_tab_csi[] =
+{
+ { '2', trans_two, 0 },
+ { '3', trans_three, 0 },
+ { 'A', 0, KEYS_UARROW },
+ { 'B', 0, KEYS_DARROW },
+ { 'D', 0, KEYS_LARROW },
+ { 'C', 0, KEYS_RARROW },
+ { 'F', 0, KEYS_END },
+ { 'H', 0, KEYS_HOME },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_tab_O[] =
+{
+ { '1', 0, KEYS_F1 },
+ { '2', 0, KEYS_F2 },
+ { '3', 0, KEYS_F3 },
+ { '4', 0, KEYS_F4 },
+ { '5', 0, KEYS_F5 },
+ { '6', 0, KEYS_F6 },
+ { '7', 0, KEYS_F7 },
+ { '8', 0, KEYS_F8 },
+ { '9', 0, KEYS_F9 },
+ { ':', 0, KEYS_F10 },
+ { 'P', 0, KEYS_F1 },
+ { 'Q', 0, KEYS_F2 },
+ { 'R', 0, KEYS_F3 },
+ { 'S', 0, KEYS_F4 },
+ { 'T', 0, KEYS_F5 },
+ { 'U', 0, KEYS_F6 },
+ { 'V', 0, KEYS_F7 },
+ { 'W', 0, KEYS_F8 },
+ { 'X', 0, KEYS_F9 },
+ { 'Y', 0, KEYS_F10 },
+ { 0, 0, 0 }
+};
+
+static const struct translation_table trans_tab[] =
+{
+ { '[', trans_tab_csi, 0 }, /* CSI command sequences */
+ { 'O', trans_tab_O, 0 }, /* O are the fuction keys */
+ { 0, 0, 0 }
+};
+#endif
+
+/*
+ * Perform a basic translation for some ANSI/VT100 key codes.
+ * This code could do with a timeout on the ESC as it is
+ * now lost from the input stream. It is not* used by the
+ * line editor below so considiered not worth the effort.
+ */
+
+#ifndef RTEMS_UNIX
+static unsigned int
+rtems_monitor_getchar (void)
+{
+ const struct translation_table *translation = 0;
+ for (;;)
+ {
+ char c = getchar ();
+ if (c == 27)
+ translation = trans_tab;
+ else
+ {
+ /*
+ * If no translation happing just pass through
+ * and return the key.
+ */
+ if (translation)
+ {
+ /*
+ * Scan the current table for the key, and if found
+ * see if this key is a fork. If so follow it and
+ * wait else return the extended key.
+ */
+ int index = 0;
+ int branched = 0;
+ while ((translation[index].expecting != '\0') ||
+ (translation[index].key != '\0'))
+ {
+ if (translation[index].expecting == c)
+ {
+ /*
+ * A branch is take if more keys are to come.
+ */
+ if (translation[index].branch == 0)
+ return KEYS_EXTENDED | translation[index].key;
+ else
+ {
+ translation = translation[index].branch;
+ branched = 1;
+ break;
+ }
+ }
+ index++;
+ }
+ /*
+ * Who knows what these keys are, just drop them.
+ */
+ if (!branched)
+ translation = 0;
+ }
+ else
+ return c;
+ }
+ }
+}
+#endif
+
+#ifndef RTEMS_UNIX
+/*
+ * The line editor with history.
+ */
+
+static int
+rtems_monitor_line_editor (
+ char *command
+)
+{
+ int repeating = 0;
+
+ memset (buffer, 0, RTEMS_COMMAND_BUFFER_SIZE);
+ history = history_next;
+ pos = 0;
+
+ if (!logged_in)
+ fprintf(stdout,"\nMonitor ready, press enter to login.\n\n");
+ else
+ fprintf(stdout,"%s $ ", monitor_prompt);
+
+ while (1)
+ {
+ unsigned int extended_key;
+ char c;
+
+ fflush (stdout);
+
+ extended_key = rtems_monitor_getchar ();
+ c = extended_key & KEYS_NORMAL_MASK;
+
+ /*
+ * Make the extended_key usable as a boolean.
+ */
+ extended_key &= ~KEYS_NORMAL_MASK;
+
+ if (!extended_key && !logged_in)
+ {
+ if (c == '\n')
+ {
+ logged_in = 1;
+ /*
+ * The prompt has changed from `>' to `$' to help know
+ * which version of the monitor code people are using.
+ */
+ fprintf(stdout,"%s $ ", monitor_prompt);
+ }
+ }
+ else
+ {
+ if (extended_key)
+ {
+ switch (c)
+ {
+ case KEYS_END:
+ fprintf(stdout,buffer + pos);
+ pos = (int) strlen (buffer);
+ break;
+
+ case KEYS_HOME:
+ fprintf(stdout,"\r%s $ ", monitor_prompt);
+ pos = 0;
+ break;
+
+ case KEYS_LARROW:
+ if (pos > 0)
+ {
+ pos--;
+ putchar ('\b');
+ }
+ break;
+
+ case KEYS_RARROW:
+ if ((pos < RTEMS_COMMAND_BUFFER_SIZE) && (buffer[pos] != '\0'))
+ {
+ putchar (buffer[pos]);
+ pos++;
+ }
+ break;
+
+ case KEYS_UARROW:
+ /*
+ * If we are moving up the histories then we need to save the working
+ * buffer.
+ */
+ if (history)
+ {
+ int end;
+ int bs;
+ if (history == history_next)
+ {
+ memcpy (history_buffer[history_next], buffer,
+ RTEMS_COMMAND_BUFFER_SIZE);
+ history_pos[history_next] = pos;
+ }
+ history--;
+ memcpy (buffer, history_buffer[history],
+ RTEMS_COMMAND_BUFFER_SIZE);
+ pos = history_pos[history];
+ fprintf(stdout,"\r%*c", RTEMS_COMMAND_BUFFER_SIZE, ' ');
+ fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
+ end = (int) strlen (buffer);
+ for (bs = 0; bs < (end - pos); bs++)
+ putchar ('\b');
+ }
+ break;
+
+ case KEYS_DARROW:
+ if (history < history_next)
+ {
+ int end;
+ int bs;
+ history++;
+ memcpy (buffer, history_buffer[history],
+ RTEMS_COMMAND_BUFFER_SIZE);
+ pos = history_pos[history];
+ fprintf(stdout,"\r%*c", RTEMS_COMMAND_BUFFER_SIZE, ' ');
+ fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
+ end = (int) strlen (buffer);
+ for (bs = 0; bs < (end - pos); bs++)
+ putchar ('\b');
+ }
+ break;
+
+ case KEYS_DEL:
+ if (buffer[pos] != '\0')
+ {
+ int end;
+ int bs;
+ strcpy (&buffer[pos], &buffer[pos + 1]);
+ fprintf(stdout,"\r%s $ %s", monitor_prompt, buffer);
+ end = (int) strlen (buffer);
+ for (bs = 0; bs < (end - pos); bs++)
+ putchar ('\b');
+ }
+ break;
+ }
+ }
+ else
+ {
+ switch (c)
+ {
+ case '\b':
+ case '\x7e':
+ case '\x7f':
+ if (pos > 0)
+ {
+ int bs;
+ pos--;
+ strcpy (buffer + pos, buffer + pos + 1);
+ fprintf(stdout,"\b%s \b", buffer + pos);
+ for (bs = 0; bs < ((int) strlen (buffer) - pos); bs++)
+ putchar ('\b');
+ }
+ break;
+
+ case '\n':
+ /*
+ * Process the command.
+ */
+ fprintf(stdout,"\n");
+ repeating = 1;
+ /*
+ * Only process the history if we have a command and
+ *a history.
+ */
+ if (strlen (buffer))
+ {
+ if (history_next && (history == history_next))
+ {
+ /*
+ * Do not place the last command into the history
+ *if the same.
+ */
+ if (strcmp (history_buffer[history_next - 1], buffer))
+ repeating = 0;
+ }
+ else
+ repeating = 0;
+ }
+ if (!repeating)
+ {
+ memcpy (history_buffer[history_next], buffer,
+ RTEMS_COMMAND_BUFFER_SIZE);
+ history_pos[history_next] = pos;
+ if (history_next < (RTEMS_COMMAND_HISTORIES - 1))
+ history_next++;
+ else
+ {
+ memmove (history_buffer[0], history_buffer[1],
+ RTEMS_COMMAND_BUFFER_SIZE * (RTEMS_COMMAND_HISTORIES - 1));
+ memmove (&history_pos[0], &history_pos[1],
+ sizeof (history_pos[0]) * (RTEMS_COMMAND_HISTORIES - 1));
+ }
+ }
+ else
+ {
+#ifdef ENABLE_ENTER_REPEATS
+ if (history_next)
+ memcpy (buffer, history_buffer[history_next - 1],
+ RTEMS_COMMAND_BUFFER_SIZE);
+#endif
+ }
+ memmove (command, buffer, RTEMS_COMMAND_BUFFER_SIZE);
+ return repeating;
+ break;
+
+ default:
+ if ((pos < (RTEMS_COMMAND_BUFFER_SIZE - 1)) &&
+ (c >= ' ') && (c <= 'z'))
+ {
+ int end;
+ end = strlen (buffer);
+ if ((pos < end) && (end < RTEMS_COMMAND_BUFFER_SIZE))
+ {
+ int ch, bs;
+ for (ch = end + 1; ch > pos; ch--)
+ buffer[ch] = buffer[ch - 1];
+ fprintf(stdout,buffer + pos);
+ for (bs = 0; bs < (end - pos + 1); bs++)
+ putchar ('\b');
+ }
+ buffer[pos++] = c;
+ if (pos > end)
+ buffer[pos] = '\0';
+ putchar (c);
+ }
+ break;
+ }
+ }
+ }
+ }
+}
+#endif
+
+/*
+ * make_argv(cp): token-count
+ * Break up the command line in 'cp' into global argv[] and argc (return
+ * value).
+ */
+
+int
+rtems_monitor_make_argv(
+ char *cp,
+ int *argc_p,
+ char **argv)
+{
+ int argc = 0;
+
+ while ((cp = strtok(cp, " \t\n\r")))
+ {
+ argv[argc++] = cp;
+ cp = (char *) NULL;
+ }
+ argv[argc] = (char *) NULL; /* end of argv */
+
+ return *argc_p = argc;
+}
+
+
+/*
+ * Read and break up a monitor command
+ *
+ * We have to loop on the gets call, since it will return NULL under UNIX
+ * RTEMS when we get a signal (eg: SIGALRM).
+ */
+
+int
+rtems_monitor_command_read(char *command,
+ int *argc,
+ char **argv)
+{
+ char *env_prompt;
+
+ env_prompt = getenv("RTEMS_MONITOR_PROMPT");
+
+ /*
+ * put node number in the prompt if we are multiprocessing
+ */
+#if defined(RTEMS_MULTIPROCESSING)
+ if (!rtems_configuration_get_user_multiprocessing_table ())
+ sprintf (monitor_prompt, "%s",
+ (env_prompt == NULL) ? MONITOR_PROMPT: env_prompt);
+ else /* .... */
+#endif
+ if (rtems_monitor_default_node != rtems_monitor_node)
+ sprintf (monitor_prompt, "%" PRId32 "-%s-%" PRId32 "", rtems_monitor_node,
+ (env_prompt == NULL) ? MONITOR_PROMPT : env_prompt,
+ rtems_monitor_default_node);
+ else
+ sprintf (monitor_prompt, "%" PRId32 "-%s", rtems_monitor_node,
+ (env_prompt == NULL) ? MONITOR_PROMPT : env_prompt);
+
+#if defined(RTEMS_UNIX)
+ /* RTEMS on unix gets so many interrupt system calls this is hosed */
+ fprintf(stdout,"%s> ", monitor_prompt);
+ fflush (stdout);
+ while (gets(command) == (char *) 0)
+ ;
+#else
+ rtems_monitor_line_editor (command);
+#endif
+
+ return rtems_monitor_make_argv (command, argc, argv);
+}
+
+/*
+ * Main monitor command loop
+ */
+
+void
+rtems_monitor_task(
+ rtems_task_argument monitor_flags
+)
+{
+ rtems_tcb *debugee = 0;
+ rtems_context *rp;
+#if (CPU_HARDWARE_FP == TRUE) || (CPU_SOFTWARE_FP == TRUE)
+ rtems_context_fp *fp;
+#endif
+ char command_buffer[513];
+ int argc;
+ char *argv[64];
+ bool verbose = false;
+ struct termios term;
+
+ /*
+ * Make the stdin stream characte not line based.
+ */
+
+ if (tcgetattr (STDIN_FILENO, &term) < 0)
+ {
+ fprintf(stdout,"rtems-monitor: cannot get terminal attributes.\n");
+ }
+ else
+ {
+ /*
+ * No echo, no canonical processing.
+ */
+
+ term.c_lflag &= ~(ECHO | ICANON | IEXTEN);
+
+ /*
+ * No sigint on BREAK, CR-to-NL off, input parity off,
+ * don't strip 8th bit on input, output flow control off
+ */
+
+ term.c_lflag &= ~(INPCK | ISTRIP | IXON);
+ term.c_cc[VMIN] = 1;
+ term.c_cc[VTIME] = 0;
+
+ if (tcsetattr (STDIN_FILENO, TCSANOW, &term) < 0)
+ {
+ fprintf(stdout,"cannot set terminal attributes\n");
+ }
+ }
+
+ if (!(monitor_flags & RTEMS_MONITOR_NOSYMLOAD)) {
+ rtems_monitor_symbols_loadup();
+ }
+
+ if (monitor_flags & RTEMS_MONITOR_SUSPEND)
+ (void) rtems_monitor_suspend(RTEMS_NO_TIMEOUT);
+
+ for (;;)
+ {
+ const rtems_monitor_command_entry_t *command;
+
+ debugee = _Thread_Executing;
+ rp = &debugee->Registers;
+#if (CPU_HARDWARE_FP == TRUE) || (CPU_SOFTWARE_FP == TRUE)
+ fp = debugee->fp_context; /* possibly 0 */
+#endif
+
+ if (0 == rtems_monitor_command_read(command_buffer, &argc, argv))
+ continue;
+ if (argc < 1
+ || (command = rtems_monitor_command_lookup(rtems_monitor_commands,
+ argv [0])) == 0)
+ {
+ /* no command */
+ fprintf(stdout,"Unrecognised command; try 'help'\n");
+ continue;
+ }
+
+ command->command_function(argc, argv, &command->command_arg, verbose);
+
+ fflush(stdout);
+ }
+}
+
+
+void
+rtems_monitor_kill(void)
+{
+ if (rtems_monitor_task_id)
+ rtems_task_delete(rtems_monitor_task_id);
+ rtems_monitor_task_id = 0;
+
+ rtems_monitor_server_kill();
+}
+
+void
+rtems_monitor_init(
+ uint32_t monitor_flags
+)
+{
+ rtems_status_code status;
+
+ rtems_monitor_kill();
+
+ status = rtems_task_create(RTEMS_MONITOR_NAME,
+ 1,
+ RTEMS_MINIMUM_STACK_SIZE * 2,
+ RTEMS_INTERRUPT_LEVEL(0),
+ RTEMS_DEFAULT_ATTRIBUTES,
+ &rtems_monitor_task_id);
+ if (status != RTEMS_SUCCESSFUL)
+ {
+ rtems_error(status, "could not create monitor task");
+ return;
+ }
+
+ rtems_monitor_node = rtems_object_id_get_node(rtems_monitor_task_id);
+ rtems_monitor_default_node = rtems_monitor_node;
+
+ rtems_monitor_server_init(monitor_flags);
+
+ if (!(monitor_flags & RTEMS_MONITOR_NOTASK)) {
+ /*
+ * Start the monitor task itself
+ */
+ status = rtems_task_start(
+ rtems_monitor_task_id, rtems_monitor_task, monitor_flags);
+ if (status != RTEMS_SUCCESSFUL) {
+ rtems_error(status, "could not start monitor");
+ return;
+ }
+ }
+}
diff --git a/cpukit/libmisc/monitor/mon-monitor.c b/cpukit/libmisc/monitor/mon-monitor.c
index c1365b340c..06f72e0f04 100644
--- a/cpukit/libmisc/monitor/mon-monitor.c
+++ b/cpukit/libmisc/monitor/mon-monitor.c
@@ -31,13 +31,9 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include <termios.h>
-#include <unistd.h>
#include <rtems/monitor.h>
-#define STREQ(a,b) (strcmp(a,b) == 0)
-
/* set by trap handler */
extern rtems_tcb *debugger_interrupted_task;
extern rtems_context *debugger_interrupted_task_context;
@@ -61,16 +57,10 @@ uint32_t rtems_monitor_default_node; /* current default for commands */
rtems_symbol_table_t *rtems_monitor_symbols;
/*
- * User registered commands.
- */
-
-rtems_monitor_command_entry_t rtems_registered_commands;
-
-/*
* The top-level commands
*/
-rtems_monitor_command_entry_t rtems_monitor_commands[] = {
+const rtems_monitor_command_entry_t rtems_monitor_commands[] = {
{ "config",
"Show the system configuration.",
0,
@@ -239,15 +229,6 @@ rtems_monitor_command_entry_t rtems_monitor_commands[] = {
{ .status_code = RTEMS_SUCCESSFUL }, /* exit value */
&rtems_monitor_commands[20],
},
- { "help",
- "Provide information about commands. "
- "Default is show basic command summary.\n"
- "help [ command [ command ] ]",
- 0,
- rtems_monitor_help_cmd,
- { .monitor_command_entry = rtems_monitor_commands },
- &rtems_monitor_commands[21],
- },
#ifdef RTEMS_POSIX_API
{ "pthread",
"Display information about the specified pthreads. "
@@ -256,8 +237,11 @@ rtems_monitor_command_entry_t rtems_monitor_commands[] = {
0,
rtems_monitor_object_cmd,
{ RTEMS_MONITOR_OBJECT_PTHREAD },
- &rtems_monitor_commands[22],
+ &rtems_monitor_commands[21],
},
+ #define RTEMS_MONITOR_DEBUGGER_NEXT 22
+#else
+ #define RTEMS_MONITOR_DEBUGGER_NEXT 21
#endif
#ifdef CPU_INVOKE_DEBUGGER
{ "debugger",
@@ -266,12 +250,27 @@ rtems_monitor_command_entry_t rtems_monitor_commands[] = {
0,
rtems_monitor_debugger_cmd,
{ 0 },
- &rtems_monitor_commands[23],
+ &rtems_monitor_commands[RTEMS_MONITOR_DEBUGGER_NEXT],
},
#endif
- { 0, 0, 0, 0, { 0 }, &rtems_registered_commands },
+ { "help",
+ "Provide information about commands. "
+ "Default is show basic command summary.\n"
+ "help [ command [ command ] ]",
+ 0,
+ rtems_monitor_help_cmd,
+ { .monitor_command_entry = rtems_monitor_commands },
+ NULL
+ }
};
+/*
+ * All registered commands.
+ */
+
+static const rtems_monitor_command_entry_t *rtems_monitor_registered_commands =
+ &rtems_monitor_commands [0];
+
rtems_status_code
rtems_monitor_suspend(rtems_interval timeout)
@@ -294,12 +293,11 @@ rtems_monitor_wakeup(void)
status = rtems_event_send(rtems_monitor_task_id, MONITOR_WAKEUP_EVENT);
}
-void
-rtems_monitor_debugger_cmd(
- int argc,
- char **argv,
- rtems_monitor_command_arg_t* command_arg,
- bool verbose
+void rtems_monitor_debugger_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
)
{
#ifdef CPU_INVOKE_DEBUGGER
@@ -307,12 +305,11 @@ rtems_monitor_debugger_cmd(
#endif
}
-void
-rtems_monitor_pause_cmd(
- int argc,
- char **argv,
- rtems_monitor_command_arg_t* command_arg,
- bool verbose
+void rtems_monitor_pause_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
)
{
if (argc == 1)
@@ -321,12 +318,11 @@ rtems_monitor_pause_cmd(
rtems_monitor_suspend(strtoul(argv[1], 0, 0));
}
-void
-rtems_monitor_fatal_cmd(
- int argc,
- char **argv,
- rtems_monitor_command_arg_t* command_arg,
- bool verbose
+void rtems_monitor_fatal_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
)
{
if (argc == 1)
@@ -335,23 +331,21 @@ rtems_monitor_fatal_cmd(
rtems_fatal_error_occurred(strtoul(argv[1], 0, 0));
}
-void
-rtems_monitor_continue_cmd(
- int argc,
- char **argv,
- rtems_monitor_command_arg_t* command_arg,
- bool verbose
+void rtems_monitor_continue_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
)
{
rtems_monitor_suspend(RTEMS_NO_TIMEOUT);
}
-void
-rtems_monitor_node_cmd(
- int argc,
- char **argv,
- rtems_monitor_command_arg_t* command_arg,
- bool verbose
+void rtems_monitor_node_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
)
{
uint32_t new_node = rtems_monitor_default_node;
@@ -462,172 +456,27 @@ done:
int
rtems_monitor_insert_cmd (
- rtems_monitor_command_entry_t *command
-)
-{
- rtems_monitor_command_entry_t **p = &rtems_registered_commands.next;
-
- command->next = 0;
-
- while (*p) {
- if ( STREQ(command->command, (*p)->command) )
- return 0;
- p = & (*p)->next;
- }
- *p = command;
- return 1;
-}
-
-int
-rtems_monitor_erase_cmd (
- rtems_monitor_command_entry_t *command
+ rtems_monitor_command_entry_t *command
)
{
- rtems_monitor_command_entry_t **p = & rtems_registered_commands.next;
+ const rtems_monitor_command_entry_t *e = rtems_monitor_registered_commands;
- while (*p) {
- if ( STREQ(command->command, (*p)->command) ) {
- *p = (*p)->next;
- command->next = 0;
- return 1;
- }
- p = & (*p)->next;
- }
+ /* Reject empty commands */
+ if (command->command == NULL) {
return 0;
+ }
-}
-
-/*
- * Main monitor command loop
- */
-
-void
-rtems_monitor_task(
- rtems_task_argument monitor_flags
-)
-{
- rtems_tcb *debugee = 0;
- rtems_context *rp;
-#if (CPU_HARDWARE_FP == TRUE) || (CPU_SOFTWARE_FP == TRUE)
- rtems_context_fp *fp;
-#endif
- char command_buffer[513];
- int argc;
- char *argv[64];
- bool verbose = false;
- struct termios term;
-
- /*
- * Make the stdin stream characte not line based.
- */
-
- if (tcgetattr (STDIN_FILENO, &term) < 0)
- {
- fprintf(stdout,"rtems-monitor: cannot get terminal attributes.\n");
- }
- else
- {
- /*
- * No echo, no canonical processing.
- */
-
- term.c_lflag &= ~(ECHO | ICANON | IEXTEN);
-
- /*
- * No sigint on BREAK, CR-to-NL off, input parity off,
- * don't strip 8th bit on input, output flow control off
- */
-
- term.c_lflag &= ~(INPCK | ISTRIP | IXON);
- term.c_cc[VMIN] = 1;
- term.c_cc[VTIME] = 0;
-
- if (tcsetattr (STDIN_FILENO, TCSANOW, &term) < 0)
- {
- fprintf(stdout,"cannot set terminal attributes\n");
+ /* Reject command if already present */
+ while (e->next != NULL) {
+ if (e->command != NULL && strcmp(command->command, e->command) == 0) {
+ return 0;
}
- }
-
- if (!(monitor_flags & RTEMS_MONITOR_NOSYMLOAD)) {
- rtems_monitor_symbols_loadup();
- }
-
- if (monitor_flags & RTEMS_MONITOR_SUSPEND)
- (void) rtems_monitor_suspend(RTEMS_NO_TIMEOUT);
-
- for (;;)
- {
- rtems_monitor_command_entry_t *command;
-
- debugee = _Thread_Executing;
- rp = &debugee->Registers;
-#if (CPU_HARDWARE_FP == TRUE) || (CPU_SOFTWARE_FP == TRUE)
- fp = debugee->fp_context; /* possibly 0 */
-#endif
-
- if (0 == rtems_monitor_command_read(command_buffer, &argc, argv))
- continue;
- if ((command = rtems_monitor_command_lookup(rtems_monitor_commands,
- argc,
- argv)) == 0)
- {
- /* no command */
- fprintf(stdout,"Unrecognised command; try 'help'\n");
- continue;
- }
-
- command->command_function(argc, argv, &command->command_arg, verbose);
-
- fflush(stdout);
- }
-}
-
-
-void
-rtems_monitor_kill(void)
-{
- if (rtems_monitor_task_id)
- rtems_task_delete(rtems_monitor_task_id);
- rtems_monitor_task_id = 0;
-
- rtems_monitor_server_kill();
-}
-
-void
-rtems_monitor_init(
- uint32_t monitor_flags
-)
-{
- rtems_status_code status;
-
- rtems_monitor_kill();
-
- status = rtems_task_create(RTEMS_MONITOR_NAME,
- 1,
- RTEMS_MINIMUM_STACK_SIZE * 2,
- RTEMS_INTERRUPT_LEVEL(0),
- RTEMS_DEFAULT_ATTRIBUTES,
- &rtems_monitor_task_id);
- if (status != RTEMS_SUCCESSFUL)
- {
- rtems_error(status, "could not create monitor task");
- return;
- }
+ e = e->next;
+ }
- rtems_monitor_node = rtems_object_id_get_node(rtems_monitor_task_id);
- rtems_monitor_default_node = rtems_monitor_node;
+ /* Prepend new command */
+ command->next = rtems_monitor_registered_commands;
+ rtems_monitor_registered_commands = command;
- rtems_monitor_server_init(monitor_flags);
-
- if (!(monitor_flags & RTEMS_MONITOR_NOTASK)) {
- /*
- * Start the monitor task itself
- */
- status = rtems_task_start(
- rtems_monitor_task_id, rtems_monitor_task, monitor_flags);
- if (status != RTEMS_SUCCESSFUL) {
- rtems_error(status, "could not start monitor");
- return;
- }
- }
+ return 1;
}
diff --git a/cpukit/libmisc/monitor/mon-object.c b/cpukit/libmisc/monitor/mon-object.c
index ea1556c91d..96b2a85f8d 100644
--- a/cpukit/libmisc/monitor/mon-object.c
+++ b/cpukit/libmisc/monitor/mon-object.c
@@ -37,7 +37,7 @@
* next
*/
-rtems_monitor_object_info_t rtems_monitor_object_info[] =
+static const rtems_monitor_object_info_t rtems_monitor_object_info[] =
{
{ RTEMS_MONITOR_OBJECT_CONFIG,
(void *) 0,
@@ -170,12 +170,12 @@ rtems_monitor_id_fixup(
}
-rtems_monitor_object_info_t *
+const rtems_monitor_object_info_t *
rtems_monitor_object_lookup(
rtems_monitor_object_type_t type
)
{
- rtems_monitor_object_info_t *p;
+ const rtems_monitor_object_info_t *p;
for (p = &rtems_monitor_object_info[0];
p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)];
p++)
@@ -229,7 +229,7 @@ failed:
rtems_id
rtems_monitor_object_canonical_next(
- rtems_monitor_object_info_t *info,
+ const rtems_monitor_object_info_t *info,
rtems_id id,
void *canonical
)
@@ -276,7 +276,7 @@ rtems_monitor_object_canonical_get(
size_t *size_p
)
{
- rtems_monitor_object_info_t *info;
+ const rtems_monitor_object_info_t *info;
rtems_id next_id;
*size_p = 0;
@@ -295,7 +295,7 @@ rtems_monitor_object_canonical_get(
void
rtems_monitor_object_dump_1(
- rtems_monitor_object_info_t *info,
+ const rtems_monitor_object_info_t *info,
rtems_id id,
bool verbose
)
@@ -329,7 +329,7 @@ rtems_monitor_object_dump_1(
void
rtems_monitor_object_dump_all(
- rtems_monitor_object_info_t *info,
+ const rtems_monitor_object_info_t *info,
bool verbose
)
{
@@ -349,14 +349,14 @@ rtems_monitor_object_dump_all(
void
rtems_monitor_object_cmd(
- int argc,
- char **argv,
- rtems_monitor_command_arg_t *command_arg,
- bool verbose
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
)
{
int arg;
- rtems_monitor_object_info_t *info = 0;
+ const rtems_monitor_object_info_t *info = 0;
rtems_monitor_object_type_t type;
/* what is the default type? */
diff --git a/cpukit/libmisc/monitor/mon-prmisc.c b/cpukit/libmisc/monitor/mon-prmisc.c
index 1962b71631..f8f215b8eb 100644
--- a/cpukit/libmisc/monitor/mon-prmisc.c
+++ b/cpukit/libmisc/monitor/mon-prmisc.c
@@ -56,8 +56,8 @@ rtems_monitor_dump_hex(uint32_t num)
int
rtems_monitor_dump_assoc_bitfield(
- rtems_assoc_t *ap,
- char *separator,
+ const rtems_assoc_t *ap,
+ const char *separator,
uint32_t value
)
{
@@ -105,7 +105,7 @@ rtems_monitor_dump_priority(rtems_task_priority priority)
}
-rtems_assoc_t rtems_monitor_state_assoc[] = {
+static const rtems_assoc_t rtems_monitor_state_assoc[] = {
{ "DORM", STATES_DORMANT, 0 },
{ "SUSP", STATES_SUSPENDED, 0 },
{ "TRANS", STATES_TRANSIENT, 0 },
@@ -142,7 +142,7 @@ rtems_monitor_dump_state(States_Control state)
return length;
}
-rtems_assoc_t rtems_monitor_attribute_assoc[] = {
+static const rtems_assoc_t rtems_monitor_attribute_assoc[] = {
{ "GL", RTEMS_GLOBAL, 0 },
{ "PR", RTEMS_PRIORITY, 0 },
{ "FL", RTEMS_FLOATING_POINT, 0 },
@@ -169,7 +169,7 @@ rtems_monitor_dump_attributes(rtems_attribute attributes)
return length;
}
-rtems_assoc_t rtems_monitor_modes_assoc[] = {
+static const rtems_assoc_t rtems_monitor_modes_assoc[] = {
{ "nP", RTEMS_NO_PREEMPT, 0 },
{ "T", RTEMS_TIMESLICE, 0 },
{ "nA", RTEMS_NO_ASR, 0 },
@@ -190,7 +190,7 @@ rtems_monitor_dump_modes(rtems_mode modes)
return length;
}
-rtems_assoc_t rtems_monitor_events_assoc[] = {
+static const rtems_assoc_t rtems_monitor_events_assoc[] = {
{ "0", RTEMS_EVENT_0, 0 },
{ "1", RTEMS_EVENT_1, 0 },
{ "2", RTEMS_EVENT_2, 0 },
diff --git a/cpukit/libmisc/monitor/mon-symbols.c b/cpukit/libmisc/monitor/mon-symbols.c
index 28d744ab06..84faa3982f 100644
--- a/cpukit/libmisc/monitor/mon-symbols.c
+++ b/cpukit/libmisc/monitor/mon-symbols.c
@@ -67,7 +67,7 @@ rtems_symbol_table_destroy(rtems_symbol_table_t *table)
rtems_symbol_t *
rtems_symbol_create(
rtems_symbol_table_t *table,
- char *name,
+ const char *name,
uint32_t value
)
{
@@ -274,7 +274,7 @@ rtems_symbol_value_lookup_exact(
rtems_symbol_t *
rtems_symbol_name_lookup(
rtems_symbol_table_t *table,
- char *name
+ const char *name
)
{
uint32_t s;
@@ -343,7 +343,7 @@ rtems_monitor_symbol_canonical(
void
rtems_monitor_symbol_canonical_by_name(
rtems_monitor_symbol_t *canonical_symbol,
- char *name
+ const char *name
)
{
rtems_symbol_t *sp;
@@ -450,12 +450,11 @@ rtems_monitor_symbol_dump_all(
* 'symbol' command
*/
-void
-rtems_monitor_symbol_cmd(
- int argc,
- char **argv,
- rtems_monitor_command_arg_t* command_arg,
- bool verbose
+void rtems_monitor_symbol_cmd(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
)
{
int arg;
diff --git a/cpukit/libmisc/monitor/monitor.h b/cpukit/libmisc/monitor/monitor.h
index 5442cc120f..28e6831834 100644
--- a/cpukit/libmisc/monitor/monitor.h
+++ b/cpukit/libmisc/monitor/monitor.h
@@ -328,28 +328,28 @@ extern uint32_t rtems_monitor_default_node; /* current default for commands *
typedef struct rtems_monitor_command_entry_s rtems_monitor_command_entry_t;
typedef union _rtems_monitor_command_arg_t rtems_monitor_command_arg_t;
-typedef void ( *rtems_monitor_command_function_t )(
- int argc,
- char **argv,
- rtems_monitor_command_arg_t *command_arg,
- bool verbose
- );
+typedef void (*rtems_monitor_command_function_t)(
+ int argc,
+ char **argv,
+ const rtems_monitor_command_arg_t *command_arg,
+ bool verbose
+);
union _rtems_monitor_command_arg_t {
rtems_monitor_object_type_t monitor_object;
rtems_status_code status_code;
rtems_symbol_table_t **symbol_table;
- rtems_monitor_command_entry_t *monitor_command_entry;
+ const rtems_monitor_command_entry_t *monitor_command_entry;
};
struct rtems_monitor_command_entry_s {
- char *command; /* command name */
- char *usage; /* usage string for the command */
- uint32_t arguments_required; /* # of required args */
+ const char *command; /* command name */
+ const char *usage; /* usage string for the command */
+ uint32_t arguments_required; /* # of required args */
rtems_monitor_command_function_t command_function;
/* Some argument for the command */
- rtems_monitor_command_arg_t command_arg;
- rtems_monitor_command_entry_t *next;
+ rtems_monitor_command_arg_t command_arg;
+ const rtems_monitor_command_entry_t *next;
};
@@ -370,18 +370,20 @@ typedef struct {
/* monitor.c */
-void rtems_monitor_kill(void);
-void rtems_monitor_init(uint32_t);
-void rtems_monitor_wakeup(void);
-void rtems_monitor_pause_cmd(int, char **, rtems_monitor_command_arg_t*, bool);
-void rtems_monitor_fatal_cmd(int, char **, rtems_monitor_command_arg_t*, bool);
-void rtems_monitor_continue_cmd(int, char **, rtems_monitor_command_arg_t*, bool);
-void rtems_monitor_debugger_cmd(int, char **, rtems_monitor_command_arg_t*, bool);
-void rtems_monitor_node_cmd(int, char **, rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_pause_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_fatal_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_continue_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_debugger_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_node_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
void rtems_monitor_symbols_loadup(void);
int rtems_monitor_insert_cmd(rtems_monitor_command_entry_t *);
int rtems_monitor_erase_cmd(rtems_monitor_command_entry_t *);
+void rtems_monitor_wakeup(void);
+rtems_status_code rtems_monitor_suspend(rtems_interval timeout);
+/* editor.c */
+void rtems_monitor_kill(void);
+void rtems_monitor_init(uint32_t);
void rtems_monitor_task(rtems_task_argument);
/* server.c */
@@ -393,10 +395,9 @@ void rtems_monitor_server_init(uint32_t );
/* command.c */
int rtems_monitor_make_argv(char *, int *, char **);
int rtems_monitor_command_read(char *, int *, char **);
-rtems_monitor_command_entry_t *rtems_monitor_command_lookup(
- rtems_monitor_command_entry_t * table, int argc, char **argv);
-void rtems_monitor_command_usage(rtems_monitor_command_entry_t *, char *);
-void rtems_monitor_help_cmd(int, char **, rtems_monitor_command_arg_t *, bool);
+const rtems_monitor_command_entry_t *rtems_monitor_command_lookup(const rtems_monitor_command_entry_t *table, const char *command_name);
+void rtems_monitor_command_usage(const rtems_monitor_command_entry_t *, const char *);
+void rtems_monitor_help_cmd(int, char **, const rtems_monitor_command_arg_t *, bool);
/* prmisc.c */
void rtems_monitor_separator(void);
@@ -414,12 +415,12 @@ int rtems_monitor_dump_notepad(uint32_t *notepad);
/* object.c */
rtems_id rtems_monitor_id_fixup(rtems_id, uint32_t , rtems_monitor_object_type_t);
-rtems_monitor_object_info_t *rtems_monitor_object_lookup(rtems_monitor_object_type_t type);
+const rtems_monitor_object_info_t *rtems_monitor_object_lookup(rtems_monitor_object_type_t type);
rtems_id rtems_monitor_object_canonical_get(rtems_monitor_object_type_t, rtems_id, void *, size_t *size_p);
-rtems_id rtems_monitor_object_canonical_next(rtems_monitor_object_info_t *, rtems_id, void *);
+rtems_id rtems_monitor_object_canonical_next(const rtems_monitor_object_info_t *, rtems_id, void *);
void *rtems_monitor_object_next(void *, void *, rtems_id, rtems_id *);
rtems_id rtems_monitor_object_canonical(rtems_id, void *);
-void rtems_monitor_object_cmd(int, char **, rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_object_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
/* manager.c */
void *rtems_monitor_manager_next(void *, void *, rtems_id *);
@@ -484,16 +485,16 @@ void rtems_monitor_driver_dump(rtems_monitor_driver_t *, bool);
rtems_symbol_table_t *rtems_symbol_table_create(void);
void rtems_symbol_table_destroy(rtems_symbol_table_t *table);
-rtems_symbol_t *rtems_symbol_create(rtems_symbol_table_t *, char *, uint32_t );
+rtems_symbol_t *rtems_symbol_create(rtems_symbol_table_t *, const char *, uint32_t );
rtems_symbol_t *rtems_symbol_value_lookup(rtems_symbol_table_t *, uint32_t );
const rtems_symbol_t *rtems_symbol_value_lookup_exact(rtems_symbol_table_t *, uint32_t );
-rtems_symbol_t *rtems_symbol_name_lookup(rtems_symbol_table_t *, char *);
+rtems_symbol_t *rtems_symbol_name_lookup(rtems_symbol_table_t *, const char *);
void *rtems_monitor_symbol_next(void *object_info, rtems_monitor_symbol_t *, rtems_id *);
void rtems_monitor_symbol_canonical(rtems_monitor_symbol_t *, rtems_symbol_t *);
-void rtems_monitor_symbol_canonical_by_name(rtems_monitor_symbol_t *, char *);
+void rtems_monitor_symbol_canonical_by_name(rtems_monitor_symbol_t *, const char *);
void rtems_monitor_symbol_canonical_by_value(rtems_monitor_symbol_t *, void *);
uint32_t rtems_monitor_symbol_dump(rtems_monitor_symbol_t *, bool);
-void rtems_monitor_symbol_cmd(int, char **, rtems_monitor_command_arg_t*, bool);
+void rtems_monitor_symbol_cmd(int, char **, const rtems_monitor_command_arg_t*, bool);
#if defined(RTEMS_NETWORKING)
void mon_ifconfig(
@@ -511,7 +512,7 @@ void mon_route(
#endif
/* mon-object.c */
-rtems_monitor_object_info_t *rtems_monitor_object_lookup(
+const rtems_monitor_object_info_t *rtems_monitor_object_lookup(
rtems_monitor_object_type_t type
);
@@ -519,7 +520,7 @@ rtems_monitor_object_info_t *rtems_monitor_object_lookup(
extern rtems_symbol_table_t *rtems_monitor_symbols;
/* FIXME: This should not be here */
-extern rtems_monitor_command_entry_t rtems_monitor_commands[];
+extern const rtems_monitor_command_entry_t rtems_monitor_commands[];
#define MONITOR_WAKEUP_EVENT RTEMS_EVENT_0