summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc
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
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 'cpukit/libmisc')
-rw-r--r--cpukit/libmisc/Makefile.am4
-rw-r--r--cpukit/libmisc/capture/capture-cli.c34
-rw-r--r--cpukit/libmisc/cpuuse/cpuusagereport.c46
-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
-rw-r--r--cpukit/libmisc/serdbg/termios_printk.c2
-rw-r--r--cpukit/libmisc/serdbg/termios_printk.h2
-rw-r--r--cpukit/libmisc/shell/cat_file.c2
-rw-r--r--cpukit/libmisc/shell/cmds.c62
-rw-r--r--cpukit/libmisc/shell/internal.h4
-rw-r--r--cpukit/libmisc/shell/main_help.c2
-rw-r--r--cpukit/libmisc/shell/shell.c12
-rw-r--r--cpukit/libmisc/shell/shell.h42
-rw-r--r--cpukit/libmisc/shell/shell_cmdset.c68
-rw-r--r--cpukit/libmisc/shell/shell_getchar.c16
-rw-r--r--cpukit/libmisc/shell/str2int.c2
21 files changed, 996 insertions, 969 deletions
diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am
index b0f7522db3..55ce5cc14a 100644
--- a/cpukit/libmisc/Makefile.am
+++ b/cpukit/libmisc/Makefile.am
@@ -44,8 +44,8 @@ libmonitor_a_SOURCES = monitor/mon-command.c monitor/mon-symbols.c \
monitor/mon-server.c monitor/mon-task.c monitor/mon-queue.c \
monitor/mon-driver.c monitor/mon-itask.c monitor/mon-extension.c \
monitor/mon-manager.c monitor/mon-config.c monitor/mon-part.c \
- monitor/mon-region.c monitor/mon-sema.c monitor/symbols.h \
- monitor/monitor.h
+ monitor/mon-region.c monitor/mon-sema.c monitor/mon-editor.c \
+ monitor/symbols.h monitor/monitor.h
if LIBNETWORKING
libmonitor_a_SOURCES += monitor/mon-network.c
endif
diff --git a/cpukit/libmisc/capture/capture-cli.c b/cpukit/libmisc/capture/capture-cli.c
index cf288f9b26..2ba3030881 100644
--- a/cpukit/libmisc/capture/capture-cli.c
+++ b/cpukit/libmisc/capture/capture-cli.c
@@ -65,7 +65,7 @@ static const char* open_usage = "usage: copen [-i] size\n";
static void
rtems_capture_cli_open (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
uint32_t size = 0;
@@ -136,7 +136,7 @@ rtems_capture_cli_open (int argc,
static void
rtems_capture_cli_close (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -164,7 +164,7 @@ rtems_capture_cli_close (int argc,
static void
rtems_capture_cli_enable (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -192,7 +192,7 @@ rtems_capture_cli_enable (int argc,
static void
rtems_capture_cli_disable (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -220,7 +220,7 @@ rtems_capture_cli_disable (int argc,
static void
rtems_capture_cli_task_list (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_task_priority ceiling = rtems_capture_watch_get_ceiling ();
@@ -459,7 +459,7 @@ rtems_capture_cli_task_load_thread (rtems_task_argument arg)
static void
rtems_capture_cli_task_load (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -532,7 +532,7 @@ rtems_capture_cli_task_load (int argc,
static void
rtems_capture_cli_watch_list (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_capture_control_t* control = rtems_capture_get_control_list ();
@@ -684,7 +684,7 @@ static char const * watch_add_usage = "usage: cwadd [task name] [id]\n";
static void
rtems_capture_cli_watch_add (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -747,7 +747,7 @@ static char const * watch_del_usage = "usage: cwdel [task name] [id]\n";
static void
rtems_capture_cli_watch_del (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -809,7 +809,7 @@ static char const * watch_control_usage = "usage: cwctl [task name] [id] on/off\
static void
rtems_capture_cli_watch_control (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -876,7 +876,7 @@ static char const * watch_global_usage = "usage: cwglob on/off\n";
static void
rtems_capture_cli_watch_global (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -930,7 +930,7 @@ static char const * watch_ceiling_usage = "usage: cwceil priority\n";
static void
rtems_capture_cli_watch_ceiling (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -981,7 +981,7 @@ static char const * watch_floor_usage = "usage: cwfloor priority\n";
static void
rtems_capture_cli_watch_floor (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -1259,7 +1259,7 @@ rtems_capture_cli_trigger_worker (int set, int argc, char** argv)
static void
rtems_capture_cli_trigger_set (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_capture_cli_trigger_worker (1, argc, argv);
@@ -1277,7 +1277,7 @@ rtems_capture_cli_trigger_set (int argc,
static void
rtems_capture_cli_trigger_clear (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_capture_cli_trigger_worker (0, argc, argv);
@@ -1295,7 +1295,7 @@ rtems_capture_cli_trigger_clear (int argc,
static void
rtems_capture_cli_trace_records (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
@@ -1426,7 +1426,7 @@ rtems_capture_cli_trace_records (int argc,
static void
rtems_capture_cli_flush (int argc,
char** argv,
- rtems_monitor_command_arg_t* command_arg,
+ const rtems_monitor_command_arg_t* command_arg,
bool verbose)
{
rtems_status_code sc;
diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c
index b0144948e4..d8f08a9a65 100644
--- a/cpukit/libmisc/cpuuse/cpuusagereport.c
+++ b/cpukit/libmisc/cpuuse/cpuusagereport.c
@@ -86,12 +86,17 @@ void rtems_cpu_usage_report_with_plugin(
}
#endif
- (*print)( context, "CPU Usage by thread\n"
- #if defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
- " ID NAME SECONDS PERCENT\n"
- #else
- " ID NAME TICKS PERCENT\n"
- #endif
+ (*print)(
+ context,
+ "-------------------------------------------------------------------------------\n"
+ " CPU USAGE BY THREAD\n"
+ "------------+----------------------------------------+---------------+---------\n"
+ #if defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
+ " ID | NAME | SECONDS | PERCENT\n"
+ #else
+ " ID | NAME | TICKS | PERCENT\n"
+ #endif
+ "------------+----------------------------------------+---------------+---------\n"
);
for ( api_index = 1 ;
@@ -111,7 +116,7 @@ void rtems_cpu_usage_report_with_plugin(
(*print)(
context,
- "0x%08" PRIx32 " %-12s ",
+ " 0x%08" PRIx32 " | %-38s |",
the_thread->Object.id,
name
);
@@ -136,7 +141,7 @@ void rtems_cpu_usage_report_with_plugin(
*/
(*print)( context,
- "%3" PRId32 ".%06" PRId32 " %3" PRId32 ".%03" PRId32 "\n",
+ "%7" PRIu32 ".%06" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
_Timestamp_Get_seconds( &ran ),
_Timestamp_Get_nanoseconds( &ran ) /
TOD_NANOSECONDS_PER_MICROSECOND,
@@ -145,10 +150,10 @@ void rtems_cpu_usage_report_with_plugin(
#else
ival = (total_units) ?
the_thread->cpu_time_used * 10000 / total_units : 0;
- fval = ival % 100;
- ival /= 100;
+ fval = ival % 1000;
+ ival /= 1000;
(*print)( context,
- "%8" PRId32 " %3" PRId32 ".%02" PRId32"\n",
+ "%14" PRIu32 " |%4" PRIu32 ".%03" PRIu32 "\n",
the_thread->cpu_time_used,
ival,
fval
@@ -159,17 +164,24 @@ void rtems_cpu_usage_report_with_plugin(
}
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
- (*print)( context, "Time since last CPU Usage reset %" PRId32
- ".%06" PRId32 " seconds\n",
+ (*print)(
+ context,
+ "------------+----------------------------------------+---------------+---------\n"
+ " TIME SINCE LAST CPU USAGE RESET IN SECONDS: %7" PRIu32 ".%06" PRIu32 "\n"
+ "-------------------------------------------------------------------------------\n",
_Timestamp_Get_seconds( &total ),
_Timestamp_Get_nanoseconds( &total ) / TOD_NANOSECONDS_PER_MICROSECOND
);
#else
- (*print)( context,
- "Ticks since last reset = %" PRId32 "\n",
- _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset
+ (*print)(
+ context,
+ "------------+----------------------------------------+---------------+---------\n"
+ " TICKS SINCE LAST SYSTEM RESET: %14" PRIu32 "\n"
+ " TOTAL UNITS: %14" PRIu32 "\n"
+ "-------------------------------------------------------------------------------\n",
+ _Watchdog_Ticks_since_boot - CPU_usage_Ticks_at_last_reset,
+ total_units
);
- (*print)( context, "Total Units = %" PRId32 "\n", total_units );
#endif
}
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
diff --git a/cpukit/libmisc/serdbg/termios_printk.c b/cpukit/libmisc/serdbg/termios_printk.c
index 2b1f0cb0bd..60a3c1390e 100644
--- a/cpukit/libmisc/serdbg/termios_printk.c
+++ b/cpukit/libmisc/serdbg/termios_printk.c
@@ -94,7 +94,7 @@ void termios_printk_outputchar
/*=========================================================================*\
| Function: |
\*-------------------------------------------------------------------------*/
-char termios_printk_inputchar
+int termios_printk_inputchar
/*-------------------------------------------------------------------------*\
| Purpose: |
| wait for one character from serial port |
diff --git a/cpukit/libmisc/serdbg/termios_printk.h b/cpukit/libmisc/serdbg/termios_printk.h
index 7392991753..4f484df62f 100644
--- a/cpukit/libmisc/serdbg/termios_printk.h
+++ b/cpukit/libmisc/serdbg/termios_printk.h
@@ -61,7 +61,7 @@ void termios_printk_outputchar
/*=========================================================================*\
| Function: |
\*-------------------------------------------------------------------------*/
-char termios_printk_inputchar
+int termios_printk_inputchar
/*-------------------------------------------------------------------------*\
| Purpose: |
| wait for one character from serial port |
diff --git a/cpukit/libmisc/shell/cat_file.c b/cpukit/libmisc/shell/cat_file.c
index 91e719aec0..1a5efb4418 100644
--- a/cpukit/libmisc/shell/cat_file.c
+++ b/cpukit/libmisc/shell/cat_file.c
@@ -18,7 +18,7 @@
#include <stdio.h>
-int rtems_shell_cat_file(FILE * out,char * name) {
+int rtems_shell_cat_file(FILE * out,const char * name) {
FILE * fd;
int c;
diff --git a/cpukit/libmisc/shell/cmds.c b/cpukit/libmisc/shell/cmds.c
index aa63a46a3b..9cb48d9d76 100644
--- a/cpukit/libmisc/shell/cmds.c
+++ b/cpukit/libmisc/shell/cmds.c
@@ -29,40 +29,48 @@
* with this you can call at all the rtems monitor commands.
* Not all work fine but you can show the rtems status and more.
*-----------------------------------------------------------*/
-int rtems_shell_main_monitor(int argc,char * argv[]) {
- rtems_monitor_command_entry_t *command;
+static int rtems_shell_main_monitor(int argc, char **argv) {
+ const rtems_monitor_command_entry_t *command = NULL;
- if ((command=rtems_monitor_command_lookup(rtems_monitor_commands,argc,argv)))
- command->command_function(argc, argv, &command->command_arg, 0);
+ if (argc < 1) {
+ return 1;
+ }
+
+ command = rtems_monitor_command_lookup(rtems_monitor_commands, argv [0]);
+
+ if (command == NULL) {
+ return 1;
+ }
+
+ command->command_function(argc, argv, &command->command_arg, 0);
return 0;
}
void rtems_shell_register_monitor_commands(void)
{
- rtems_monitor_command_entry_t *command;
-
- /* monitor topic */
- command = rtems_monitor_commands;
-
- while (command) {
- /* Exclude EXIT (alias quit)*/
- if (strcmp("exit",command->command)) {
- rtems_shell_cmd_t *shell_cmd;
-
- shell_cmd = (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
- shell_cmd->name = command->command;
- shell_cmd->topic = "monitor";
- shell_cmd->usage = command->usage;
- shell_cmd->command = rtems_shell_main_monitor;
- shell_cmd->alias = (rtems_shell_cmd_t *) NULL;
- shell_cmd->next = (rtems_shell_cmd_t *) NULL;
+ /* Monitor topic */
+ const rtems_monitor_command_entry_t *e = rtems_monitor_commands;
- if (rtems_shell_add_cmd_struct( shell_cmd ) == NULL) {
- free( shell_cmd );
- shell_cmd = NULL;
- }
- }
- command = command->next;
+ while (e != NULL) {
+ /* Exclude EXIT (alias quit)*/
+ if (e->command != NULL && strcmp("exit", e->command) != 0) {
+ rtems_shell_cmd_t *shell_cmd =
+ (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
+
+ if (shell_cmd != NULL) {
+ shell_cmd->name = e->command;
+ shell_cmd->topic = "monitor";
+ shell_cmd->usage = e->usage;
+ shell_cmd->command = rtems_shell_main_monitor;
+ shell_cmd->alias = NULL;
+ shell_cmd->next = NULL;
+
+ if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
+ free(shell_cmd);
+ }
+ }
+ }
+ e = e->next;
}
}
diff --git a/cpukit/libmisc/shell/internal.h b/cpukit/libmisc/shell/internal.h
index c0a9908cdf..1855d0b080 100644
--- a/cpukit/libmisc/shell/internal.h
+++ b/cpukit/libmisc/shell/internal.h
@@ -15,7 +15,7 @@ struct rtems_shell_topic_tt;
typedef struct rtems_shell_topic_tt rtems_shell_topic_t;
struct rtems_shell_topic_tt {
- char *topic;
+ const char *topic;
rtems_shell_topic_t *next;
};
@@ -23,7 +23,7 @@ struct rtems_shell_topic_tt {
extern rtems_shell_cmd_t * rtems_shell_first_cmd;
extern rtems_shell_topic_t * rtems_shell_first_topic;
-rtems_shell_topic_t * rtems_shell_lookup_topic(char * topic);
+rtems_shell_topic_t * rtems_shell_lookup_topic(const char *topic);
void rtems_shell_register_monitor_commands(void);
diff --git a/cpukit/libmisc/shell/main_help.c b/cpukit/libmisc/shell/main_help.c
index 01dd35020f..5aa9dc759e 100644
--- a/cpukit/libmisc/shell/main_help.c
+++ b/cpukit/libmisc/shell/main_help.c
@@ -31,7 +31,7 @@ int rtems_shell_help_cmd(
rtems_shell_cmd_t *shell_cmd
)
{
- char * pc;
+ const char * pc;
int col,line;
printf("%-10.10s - ",shell_cmd->name);
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index a320e46902..0a784ba712 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -939,10 +939,10 @@ bool rtems_shell_main_loop(
/* ----------------------------------------------- */
static rtems_status_code rtems_shell_run (
- char *task_name,
+ const char *task_name,
uint32_t task_stacksize,
rtems_task_priority task_priority,
- char *devname,
+ const char *devname,
int forever,
int wait,
const char* input,
@@ -957,7 +957,7 @@ static rtems_status_code rtems_shell_run (
rtems_shell_env_t *shell_env;
rtems_name name;
- if ( task_name )
+ if ( task_name && strlen(task_name) >= 4)
name = rtems_build_name(
task_name[0], task_name[1], task_name[2], task_name[3]);
else
@@ -1010,10 +1010,10 @@ static rtems_status_code rtems_shell_run (
}
rtems_status_code rtems_shell_init(
- char *task_name,
+ const char *task_name,
uint32_t task_stacksize,
rtems_task_priority task_priority,
- char *devname,
+ const char *devname,
int forever,
int wait
)
@@ -1039,7 +1039,7 @@ rtems_status_code rtems_shell_init(
}
rtems_status_code rtems_shell_script (
- char *task_name,
+ const char *task_name,
uint32_t task_stacksize,
rtems_task_priority task_priority,
const char* input,
diff --git a/cpukit/libmisc/shell/shell.h b/cpukit/libmisc/shell/shell.h
index 5509b365bc..fa3ad00cc5 100644
--- a/cpukit/libmisc/shell/shell.h
+++ b/cpukit/libmisc/shell/shell.h
@@ -54,23 +54,23 @@ extern "C" {
#define RTEMS_SHELL_KEYS_F9 (16)
#define RTEMS_SHELL_KEYS_F10 (17)
-typedef int (*rtems_shell_command_t)(int argc,char * argv[]);
+typedef int (*rtems_shell_command_t)(int argc, char **argv);
struct rtems_shell_cmd_tt;
typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t;
struct rtems_shell_cmd_tt {
- char *name;
- char *usage;
- char *topic;
+ const char *name;
+ const char *usage;
+ const char *topic;
rtems_shell_command_t command;
rtems_shell_cmd_t *alias;
rtems_shell_cmd_t *next;
};
typedef struct {
- char *name;
- char *alias;
+ const char *name;
+ const char *alias;
} rtems_shell_alias_t;
/*
@@ -79,22 +79,22 @@ typedef struct {
*/
unsigned int rtems_shell_getchar(FILE *in);
-rtems_shell_cmd_t * rtems_shell_lookup_cmd(char * cmd);
+rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
rtems_shell_cmd_t *shell_cmd
);
rtems_shell_cmd_t * rtems_shell_add_cmd(
- char *cmd,
- char *topic,
- char *usage,
+ const char *cmd,
+ const char *topic,
+ const char *usage,
rtems_shell_command_t command
);
rtems_shell_cmd_t * rtems_shell_alias_cmd(
- char *cmd,
- char *alias
+ const char *cmd,
+ const char *alias
);
int rtems_shell_make_args(
@@ -113,7 +113,7 @@ int rtems_shell_scanline(
int rtems_shell_cat_file(
FILE *out,
- char *name
+ const char *name
);
void rtems_shell_write_file(
@@ -122,8 +122,8 @@ void rtems_shell_write_file(
);
int rtems_shell_script_file(
- int argc,
- char *argv[]
+ int argc,
+ char **argv
);
/**
@@ -138,10 +138,10 @@ int rtems_shell_script_file(
*
*/
rtems_status_code rtems_shell_init(
- char *task_name,
+ const char *task_name,
uint32_t task_stacksize, /*0 default*/
rtems_task_priority task_priority,
- char *devname,
+ const char *devname,
int forever,
int wait
);
@@ -160,7 +160,7 @@ rtems_status_code rtems_shell_init(
* @param wait Wait for the script to finish.
*/
rtems_status_code rtems_shell_script(
- char *task_name,
+ const char *task_name,
uint32_t task_stacksize, /*0 default*/
rtems_task_priority task_priority,
const char *input,
@@ -174,12 +174,12 @@ rtems_status_code rtems_shell_script(
* Things that are useful to external entities developing commands and plugging
* them in.
*/
-int rtems_shell_str2int(char * s);
+int rtems_shell_str2int(const char * s);
typedef struct {
rtems_name magic; /* 'S','E','N','V': Shell Environment */
- char *devname;
- char *taskname;
+ const char *devname;
+ const char *taskname;
/* user extensions */
bool exit_shell; /* logout */
bool forever ; /* repeat login */
diff --git a/cpukit/libmisc/shell/shell_cmdset.c b/cpukit/libmisc/shell/shell_cmdset.c
index 124296de0c..8f6aa4fdbf 100644
--- a/cpukit/libmisc/shell/shell_cmdset.c
+++ b/cpukit/libmisc/shell/shell_cmdset.c
@@ -50,7 +50,7 @@ rtems_shell_topic_t * rtems_shell_first_topic;
/*
* Find the topic from the set of topics registered.
*/
-rtems_shell_topic_t * rtems_shell_lookup_topic(char * topic) {
+rtems_shell_topic_t * rtems_shell_lookup_topic(const char * topic) {
rtems_shell_topic_t * shell_topic;
shell_topic=rtems_shell_first_topic;
@@ -65,7 +65,7 @@ rtems_shell_topic_t * rtems_shell_lookup_topic(char * topic) {
/*
* Add a new topic to the list of topics
*/
-rtems_shell_topic_t * rtems_shell_add_topic(char * topic) {
+rtems_shell_topic_t * rtems_shell_add_topic(const char * topic) {
rtems_shell_topic_t * current,*aux;
if (!rtems_shell_first_topic) {
@@ -93,7 +93,7 @@ rtems_shell_topic_t * rtems_shell_add_topic(char * topic) {
/*
* Find the command in the set
*/
-rtems_shell_cmd_t * rtems_shell_lookup_cmd(char * cmd) {
+rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char * cmd) {
rtems_shell_cmd_t * shell_cmd;
shell_cmd=rtems_shell_first_cmd;
while (shell_cmd) {
@@ -136,33 +136,49 @@ rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
* allocate the command structure on the fly.
*/
rtems_shell_cmd_t * rtems_shell_add_cmd(
- char *cmd,
- char *topic,
- char *usage,
+ const char *name,
+ const char *topic,
+ const char *usage,
rtems_shell_command_t command
)
{
- rtems_shell_cmd_t *shell_cmd;
+ rtems_shell_cmd_t *shell_cmd = NULL;
+ char *my_name = NULL;
+ char *my_topic = NULL;
+ char *my_usage = NULL;
+
+ /* Reject empty commands */
+ if (name == NULL || command == NULL) {
+ return NULL;
+ }
+
+ /* Allocate command stucture */
+ shell_cmd = (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
+ if (shell_cmd == NULL) {
+ return NULL;
+ }
- if (!cmd)
- return (rtems_shell_cmd_t *) NULL;
- if (!command)
- return (rtems_shell_cmd_t *) NULL;
+ /* Allocate strings */
+ my_name = strdup(name);
+ my_topic = strdup(topic);
+ my_usage = strdup(usage);
- shell_cmd = (rtems_shell_cmd_t *) malloc(sizeof(rtems_shell_cmd_t));
- shell_cmd->name = strdup( cmd );
- shell_cmd->topic = strdup( topic );
- shell_cmd->usage = strdup( usage );
+ /* Assign values */
+ shell_cmd->name = my_name;
+ shell_cmd->topic = my_topic;
+ shell_cmd->usage = my_usage;
shell_cmd->command = command;
- shell_cmd->alias = (rtems_shell_cmd_t *) NULL;
- shell_cmd->next = (rtems_shell_cmd_t *) NULL;
-
- if (rtems_shell_add_cmd_struct( shell_cmd ) == NULL) {
- free( shell_cmd->usage );
- free( shell_cmd->topic );
- free( shell_cmd->name );
- free( shell_cmd );
- shell_cmd = NULL;
+ shell_cmd->alias = NULL;
+ shell_cmd->next = NULL;
+
+ if (rtems_shell_add_cmd_struct(shell_cmd) == NULL) {
+ /* Something is wrong, free allocated resources */
+ free(my_usage);
+ free(my_topic);
+ free(my_name);
+ free(shell_cmd);
+
+ return NULL;
}
return shell_cmd;
@@ -189,8 +205,8 @@ void rtems_shell_initialize_command_set(void)
* you can make an alias for every command.
* ----------------------------------------------- */
rtems_shell_cmd_t *rtems_shell_alias_cmd(
- char *cmd,
- char *alias
+ const char *cmd,
+ const char *alias
)
{
rtems_shell_cmd_t *shell_cmd, *shell_aux;
diff --git a/cpukit/libmisc/shell/shell_getchar.c b/cpukit/libmisc/shell/shell_getchar.c
index 53b80dd953..b214a9511f 100644
--- a/cpukit/libmisc/shell/shell_getchar.c
+++ b/cpukit/libmisc/shell/shell_getchar.c
@@ -41,29 +41,29 @@
struct translation_table
{
char expecting;
- struct translation_table *branch;
+ const struct translation_table *branch;
unsigned int key;
};
-static struct translation_table trans_one[] =
+static const struct translation_table trans_one[] =
{
{ '\x7e', 0, RTEMS_SHELL_KEYS_HOME },
{ 0, 0, 0 }
};
-static struct translation_table trans_two[] =
+static const struct translation_table trans_two[] =
{
{ '~', 0, RTEMS_SHELL_KEYS_INS },
{ 0, 0, 0 }
};
-static struct translation_table trans_three[] =
+static const struct translation_table trans_three[] =
{
{ '~', 0, RTEMS_SHELL_KEYS_DEL },
{ 0, 0, 0 }
};
-static struct translation_table trans_tab_csi[] =
+static const struct translation_table trans_tab_csi[] =
{
{ '1', trans_one, 0 },
{ '2', trans_two, 0 },
@@ -77,7 +77,7 @@ static struct translation_table trans_tab_csi[] =
{ 0, 0, 0 }
};
-static struct translation_table trans_tab_O[] =
+static const struct translation_table trans_tab_O[] =
{
{ '1', 0, RTEMS_SHELL_KEYS_F1 },
{ '2', 0, RTEMS_SHELL_KEYS_F2 },
@@ -103,7 +103,7 @@ static struct translation_table trans_tab_O[] =
{ 0, 0, 0 }
};
-static struct translation_table trans_tab[] =
+static const struct translation_table trans_tab[] =
{
{ '[', trans_tab_csi, 0 }, /* CSI command sequences */
{ 'O', trans_tab_O, 0 }, /* O are the fuction keys */
@@ -120,7 +120,7 @@ static struct translation_table trans_tab[] =
unsigned int
rtems_shell_getchar (FILE *in)
{
- struct translation_table *translation = 0;
+ const struct translation_table *translation = 0;
for (;;)
{
int c = fgetc (in);
diff --git a/cpukit/libmisc/shell/str2int.c b/cpukit/libmisc/shell/str2int.c
index a569772bb6..ee02f74bf3 100644
--- a/cpukit/libmisc/shell/str2int.c
+++ b/cpukit/libmisc/shell/str2int.c
@@ -21,7 +21,7 @@
/*
* str to int "0xaffe" "0b010010" "0123" "192939"
*/
-int rtems_shell_str2int(char * s) {
+int rtems_shell_str2int(const char * s) {
int sign=1;
int base=10;
int value=0;