[rtems commit] PR 2012 - mdump/ wdump shell cmds handle length arg incorrectly; add ldump cmd

Joel Sherrill joel at rtems.org
Thu Feb 2 21:01:11 UTC 2012


Module:    rtems
Branch:    4.10
Commit:    bcd065cc16aa15c35f59618673220f6dc5504af7
Changeset: http://git.rtems.org/rtems/commit/?id=bcd065cc16aa15c35f59618673220f6dc5504af7

Author:    Joel Sherrill <joel.sherrill at oarcorp.com>
Date:      Thu Feb  2 14:59:15 2012 -0600

PR 2012 - mdump/wdump shell cmds handle length arg incorrectly; add ldump cmd

	* libmisc/shell/main_mdump.c: Reworked to fix bugs in handling of the
	length argument and to provide an "ldump" command.  This file now also
	supports the "wdump" command.  In addition, an RTEMS API function called
	rtems_mdump() is provided to allow easy dumping from application code.
	* libmisc/shell/main_mwdump.c: Obsolete file.
	* libmisc/Makefile.am: Removed main_mwdump.c
	* libmisc/shell/shellconfig.h: Added "ldump" command.
	* shell/memory.t: Added documentation for the "ldump" command

Signed-off-by: Ric Claus <claus at SLAC.Stanford.edu>

---

 cpukit/libmisc/Makefile.am         |    3 +-
 cpukit/libmisc/shell/main_mdump.c  |  194 +++++++++++++++++++++++++++++------
 cpukit/libmisc/shell/shellconfig.h |   10 ++-
 doc/shell/memory.t                 |  115 ++++++++++++++++++---
 4 files changed, 268 insertions(+), 54 deletions(-)

diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am
index 2a7ba78..4f4e671 100644
--- a/cpukit/libmisc/Makefile.am
+++ b/cpukit/libmisc/Makefile.am
@@ -1,5 +1,4 @@
 ##
-##  $Id$
 ##
 
 include $(top_srcdir)/automake/compile.am
@@ -77,7 +76,7 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \
     shell/main_mallocinfo.c shell/main_mdump.c shell/main_medit.c \
     shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \
     shell/main_mmove.c shell/main_msdosfmt.c \
-    shell/main_mv.c shell/main_mwdump.c shell/main_perioduse.c \
+    shell/main_mv.c shell/main_perioduse.c \
     shell/main_pwd.c shell/main_rm.c shell/main_rmdir.c shell/main_sleep.c \
     shell/main_stackuse.c shell/main_tty.c shell/main_umask.c \
     shell/main_unmount.c shell/main_blksync.c shell/main_whoami.c \
diff --git a/cpukit/libmisc/shell/main_mdump.c b/cpukit/libmisc/shell/main_mdump.c
index d196711..156a6f2 100644
--- a/cpukit/libmisc/shell/main_mdump.c
+++ b/cpukit/libmisc/shell/main_mdump.c
@@ -5,11 +5,11 @@
  *  Work: fernando.ruiz at ctv.es
  *  Home: correo at fernando-ruiz.com
  *
+ *  Reworked by Ric Claus at SLAC.Stanford.edu
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id$
  */
 
 #ifdef HAVE_CONFIG_H
@@ -26,71 +26,197 @@
 #include <rtems/stringto.h>
 #include "internal.h"
 
+static int args_parse(int argc, char* argv[], void** addr, int* max, int* sz);
+
+static void mdumpB(void* addr, int m);
+static void mdumpW(void* addr, int m);
+static void mdumpL(void* addr, int m);
+
+int rtems_mdump(void* addr, int max, int sz);
+
 int rtems_shell_main_mdump(
   int   argc,
   char *argv[]
 )
 {
-  unsigned char  n;
-  unsigned char  m;
-  int            max;
-  int            res;
-  void          *addr = NULL;
-  unsigned char *pb;
+  void *addr;
+  int   max;
+  int   sz;
+
+  if (args_parse(argc, argv, &addr, &max, &sz)) 
+    return -1;
+  return rtems_mdump(addr, max, sz);
+}
+
+int rtems_shell_main_wdump(
+  int   argc,
+  char *argv[]
+)
+{
+  void *addr;
+  int   max;
+  int   sz;
+
+  if (args_parse(argc, argv, &addr, &max, &sz))
+    return -1;
+  return rtems_mdump(addr, max, 2);
+}
+
+
+int rtems_shell_main_ldump(
+  int   argc,
+  char *argv[]
+)
+{
+  void *addr;
+  int   max;
+  int   sz;
+
+  if (args_parse(argc, argv, &addr, &max, &sz))
+    return -1;
+  return rtems_mdump(addr, max, 4);
+}
+
+
+int args_parse(int    argc,
+               char*  argv[],
+               void** addr,
+               int*   max,
+               int*   sz)
+{
+  *addr = NULL;
+  *max  = 320;
+  *sz   = 1;
 
   if (argc > 1) {
-    if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
+    if ( rtems_string_to_pointer(argv[1], addr, NULL) ) {
       printf( "Address argument (%s) is not a number\n", argv[1] );
       return -1;
     }
 
-  }
+    if (argc > 2) {
+      if ( rtems_string_to_int(argv[2], max, NULL, 0) ) {
+        printf( "Length argument (%s) is not a number\n", argv[2] );
+        return -1;
+      }
 
-  if (argc > 2) {
-    if ( rtems_string_to_int(argv[1], &max, NULL, 0) ) {
-      printf( "Length argument (%s) is not a number\n", argv[1] );
-      return -1;
-    }
-    if (max <= 0) {
-      max = 1;      /* print 1 item if 0 or neg. */
-      res = 0;
-    } else {
-      max--;
-      res = max & 0xf;/* num bytes in last row */
-      max >>= 4;      /* div by 16 */
-      max++;          /* num of rows to print */
-      if (max > 20) { /* limit to 20 */
-        max = 20;
-        res = 0xf;    /* 16 bytes print in last row */
+      if (argc > 3) {
+        if ( rtems_string_to_int(argv[3], sz, NULL, 0) ) {
+          printf( "Size argument (%s) is not a valid number\n", argv[3] );
+          return -1;
+        }
       }
     }
+  }
+  return 0;
+}
+
+
+int rtems_mdump(void* addr, int max, int sz)
+{
+  unsigned char           n;
+  unsigned char           m;
+  volatile unsigned char *pb;
+  int                     res;
+  int                     cnt;
+
+  if (!((sz == 1) || (sz == 2) || (sz == 4))) {
+    printf( "Size argument (%d) is not one of 1 (bytes), "
+              " 2 (words) or 4 (longwords)\n", sz);
+    return -1;
+  }
+
+  if (max <= 0) {
+    max = 1;           /* print 1 item if 0 or neg. */
+    res = 0;
   } else {
-    max = 20;
-    res = 0xf;
+    max--;
+    res = max & 0xf;   /* num bytes in last row */
+    max >>= 4;         /* div by 16 */
+    max++;             /* num of rows to print */
+    if (max > 64) {    /* limit to 64 lines */
+      max = 64;
+      res = 0xf;       /* 16 bytes print in last row */
+    }
   }
 
   pb = addr;
   for (m=0; m<max; m++) {
+    cnt = m==(max-1)?res:0xf;
     printf("%10p ", pb);
-    for (n=0;n<=(m==(max-1)?res:0xf);n++)
-      printf("%02X%c",pb[n],n==7?'-':' ');
-    for (;n<=0xf;n++)
-      printf("  %c",n==7?'-':' ');
-    for (n=0;n<=(m==(max-1)?res:0xf);n++) {
+    if      (sz == 1)  mdumpB(pb, cnt);
+    else if (sz == 2)  mdumpW(pb, cnt);
+    else if (sz == 4)  mdumpL(pb, cnt);
+    for (n=0;n<=cnt;n++) {
       printf("%c", isprint(pb[n]) ? pb[n] : '.');
     }
     printf("\n");
     pb += 16;
   }
+
   return 0;
 }
 
+
+void mdumpB(void* addr, int m)
+{
+  volatile unsigned char* pb = addr;
+  int n;
+  for (n=0;n<=m;n++)
+    printf("%02X%c",*pb++,n==7?'-':' ');
+  for (;n<=0xf;n++)
+    printf("  %c",n==7?'-':' ');
+}
+
+
+void mdumpW(void* addr, int m)
+{
+  volatile unsigned short* pb = addr;
+  int n;
+  for (n=0;n<=m;n+=2)
+    printf("%04X%c",*pb++,n==6?'-':' ');
+  for (;n<=0xf;n+=2)
+    printf("    %c", n==6?'-':' ');
+}
+
+
+void mdumpL(void* addr, int m)
+{
+  volatile unsigned int* pb = addr;
+  int n;
+  for (n=0;n<=m;n+=4)
+    printf("%08X%c",*pb++,n==4?'-':' ');
+  for (;n<=0xf;n+=4)
+    printf("        %c", n==4?'-':' ');
+}
+
+
 rtems_shell_cmd_t rtems_shell_MDUMP_Command = {
   "mdump",                                      /* name */
-  "mdump [address [length]]",                   /* usage */
+  "mdump [address [length [size]]]",            /* usage */
   "mem",                                        /* topic */
   rtems_shell_main_mdump,                       /* command */
   NULL,                                         /* alias */
   NULL                                          /* next */
 };
 
+
+rtems_shell_cmd_t rtems_shell_WDUMP_Command = {
+  "wdump",                                      /* name */
+  "wdump [address [length]]",                   /* usage */
+  "mem",                                        /* topic */
+  rtems_shell_main_wdump,                       /* command */
+  NULL,                                         /* alias */
+  NULL                                          /* next */
+};
+
+
+rtems_shell_cmd_t rtems_shell_LDUMP_Command = {
+  "ldump",                                      /* name */
+  "ldump [address [length]]",                   /* usage */
+  "mem",                                        /* topic */
+  rtems_shell_main_ldump,                       /* command */
+  NULL,                                         /* alias */
+  NULL                                          /* next */
+};
+
diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h
index cfc4750..f2ee9c8 100644
--- a/cpukit/libmisc/shell/shellconfig.h
+++ b/cpukit/libmisc/shell/shellconfig.h
@@ -1,14 +1,12 @@
 /*
  *  RTEMS Shell Command Set Configuration
  *
- *  COPYRIGHT (c) 1989-2007.
+ *  COPYRIGHT (c) 1989-2012.
  *  On-Line Applications Research Corporation (OAR).
  *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
- *
- *  $Id$
  */
 
 #ifndef _RTEMS_SHELL_CONFIG_h
@@ -29,6 +27,7 @@ extern rtems_shell_cmd_t rtems_shell_UNSETENV_Command;
 
 extern rtems_shell_cmd_t rtems_shell_MDUMP_Command;
 extern rtems_shell_cmd_t rtems_shell_WDUMP_Command;
+extern rtems_shell_cmd_t rtems_shell_LDUMP_Command;
 extern rtems_shell_cmd_t rtems_shell_MEDIT_Command;
 extern rtems_shell_cmd_t rtems_shell_MFILL_Command;
 extern rtems_shell_cmd_t rtems_shell_MMOVE_Command;
@@ -221,6 +220,11 @@ extern rtems_shell_alias_t *rtems_shell_Initial_aliases[];
       &rtems_shell_WDUMP_Command,
     #endif
     #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
+         !defined(CONFIGURE_SHELL_NO_COMMAND_LDUMP)) || \
+        defined(CONFIGURE_SHELL_COMMAND_LDUMP)
+      &rtems_shell_LDUMP_Command,
+    #endif
+    #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
          !defined(CONFIGURE_SHELL_NO_COMMAND_MEDIT)) || \
         defined(CONFIGURE_SHELL_COMMAND_MEDIT)
       &rtems_shell_MEDIT_Command,
diff --git a/doc/shell/memory.t b/doc/shell/memory.t
index cb78277..3227e73 100644
--- a/doc/shell/memory.t
+++ b/doc/shell/memory.t
@@ -1,10 +1,8 @@
 @c
- at c  COPYRIGHT (c) 1988-2008.
+ at c  COPYRIGHT (c) 1988-2012.
 @c  On-Line Applications Research Corporation (OAR).
 @c  All rights reserved.
 @c
- at c  $Id$
- at c
 
 @chapter Memory Commands
 
@@ -16,6 +14,7 @@ The RTEMS shell has the following memory commands:
 
 @item @code{mdump} - Display contents of memory
 @item @code{wdump} - Display contents of memory (word)
+ at item @code{ldump} - Display contents of memory (longword)
 @item @code{medit} - Modify contents of memory
 @item @code{mfill} - File memory with pattern
 @item @code{mmove} - Move contents of memory
@@ -41,13 +40,17 @@ command as well as providing an example usage.
 @subheading SYNOPSYS:
 
 @example
-mdump [address [length]]
+mdump [address [length [size]]]
 @end example
 
 @subheading DESCRIPTION:
 
 This command displays the contents of memory at the @code{address}
-and @code{length} in bytes specified on the command line.  
+and @code{length} in @code{size} byte units specified on the command line.
+
+When @code{size} is not provided, it defaults to @code{1} byte units.
+Values of @code{1}, @code{2}, and @code{4} are valid; all others will
+cause an error to be reported.
 
 When @code{length} is not provided, it defaults to @code{320} which
 is twenty lines of output with sixteen bytes of output per line.
@@ -84,7 +87,7 @@ SHLL [/] $ mdump 0x02001000 32
 @findex CONFIGURE_SHELL_NO_COMMAND_MDUMP
 @findex CONFIGURE_SHELL_COMMAND_MDUMP
 
-This command is included in the default shell command set.  
+This command is included in the default shell command set.
 When building a custom command set, define
 @code{CONFIGURE_SHELL_COMMAND_MDUMP} to have this
 command included.
@@ -131,10 +134,12 @@ wdump [address [length]]
 @subheading DESCRIPTION:
 
 This command displays the contents of memory at the @code{address}
-and @code{length} in bytes specified on the command line.  
+and @code{length} in bytes specified on the command line.
+
+This command is equivalent to @code{mdump address length 2}.
 
 When @code{length} is not provided, it defaults to @code{320} which
-is twenty lines of output with sixteen bytes of output per line.
+is twenty lines of output with eight words of output per line.
 
 When @code{address} is not provided, it defaults to @code{0x00000000}.
 
@@ -162,7 +167,7 @@ SHLL [/] $ wdump 0x02010000 32
 @findex CONFIGURE_SHELL_NO_COMMAND_WDUMP
 @findex CONFIGURE_SHELL_COMMAND_WDUMP
 
-This command is included in the default shell command set.  
+This command is included in the default shell command set.
 When building a custom command set, define
 @code{CONFIGURE_SHELL_COMMAND_WDUMP} to have this
 command included.
@@ -196,6 +201,86 @@ extern rtems_shell_cmd_t rtems_shell_WDUMP_Command;
 @c
 @c
 @page
+ at subsection ldump - display contents of memory (longword)
+
+ at pgindex ldump
+
+ at subheading SYNOPSYS:
+
+ at example
+ldump [address [length]]
+ at end example
+
+ at subheading DESCRIPTION:
+
+This command displays the contents of memory at the @code{address}
+and @code{length} in bytes specified on the command line.
+
+This command is equivalent to @code{mdump address length 4}.
+
+When @code{length} is not provided, it defaults to @code{320} which
+is twenty lines of output with four longwords of output per line.
+
+When @code{address} is not provided, it defaults to @code{0x00000000}.
+
+ at subheading EXIT STATUS:
+
+This command always returns 0 to indicate success.
+
+ at subheading NOTES:
+
+Dumping memory from a non-existent address may result in an unrecoverable
+program fault.
+
+ at subheading EXAMPLES:
+
+The following is an example of how to use @code{ldump}:
+
+ at smallexample
+SHLL [/] $ ldump 0x02010000 32
+0x02010000 020108D8 020108C0-020108AC 02010874 ...............t
+0x02010010 020 0894 02010718-02010640 02010798 ........... at ....
+ at end smallexample
+
+ at subheading CONFIGURATION:
+
+ at findex CONFIGURE_SHELL_NO_COMMAND_LDUMP
+ at findex CONFIGURE_SHELL_COMMAND_LDUMP
+
+This command is included in the default shell command set.
+When building a custom command set, define
+ at code{CONFIGURE_SHELL_COMMAND_LDUMP} to have this
+command included.
+
+This command can be excluded from the shell command set by
+defining @code{CONFIGURE_SHELL_NO_COMMAND_LDUMP} when all
+shell commands have been configured.
+
+ at subheading PROGRAMMING INFORMATION:
+
+ at findex rtems_shell_rtems_main_ldump
+
+The @code{ldump} is implemented by a C language function
+which has the following prototype:
+
+ at example
+int rtems_shell_rtems_main_ldump(
+  int    argc,
+  char **argv
+);
+ at end example
+
+The configuration structure for the @code{ldump} has the
+following prototype:
+
+ at example
+extern rtems_shell_cmd_t rtems_shell_LDUMP_Command;
+ at end example
+
+ at c
+ at c
+ at c
+ at page
 @subsection medit - modify contents of memory
 
 @pgindex medit
@@ -240,7 +325,7 @@ SHLL [/] $ mdump 0x02000000 32
 @findex CONFIGURE_SHELL_NO_COMMAND_MEDIT
 @findex CONFIGURE_SHELL_COMMAND_MEDIT
 
-This command is included in the default shell command set.  
+This command is included in the default shell command set.
 When building a custom command set, define
 @code{CONFIGURE_SHELL_COMMAND_MEDIT} to have this
 command included.
@@ -303,7 +388,7 @@ space or critical data areas can be fatal as shown in the example.
 @subheading EXAMPLES:
 
 In this example, the address used (@code{0x23d89a0}) as the base
-address of the filled area is the end of the stack for the 
+address of the filled area is the end of the stack for the
 Idle thread.  This address was determined manually using gdb and
 is very specific to this application and BSP.  The first command
 in this example is an @code{mdump} to display the initial contents
@@ -327,7 +412,7 @@ SHLL [/] $ BLOWN STACK!!! Offending task(0x23D4418): id=0x09010001; name=0x0203D
 @findex CONFIGURE_SHELL_NO_COMMAND_MFILL
 @findex CONFIGURE_SHELL_COMMAND_MFILL
 
-This command is included in the default shell command set.  
+This command is included in the default shell command set.
 When building a custom command set, define
 @code{CONFIGURE_SHELL_COMMAND_MFILL} to have this
 command included.
@@ -404,7 +489,7 @@ SHLL [/] $ mdump 0x023d99a0 16
 @findex CONFIGURE_SHELL_NO_COMMAND_MMOVE
 @findex CONFIGURE_SHELL_COMMAND_MMOVE
 
-This command is included in the default shell command set.  
+This command is included in the default shell command set.
 When building a custom command set, define
 @code{CONFIGURE_SHELL_COMMAND_MMOVE} to have this
 command included.
@@ -473,7 +558,7 @@ be enabled for all of the values to be updated.  The statistics
 available includes the following information:
 
 @itemize @bullet
- at item 
+ at item
 @item Currently available memory (in kilobytes)
 @item Currently allocated memory (in kilobytes)
 @item Maximum amount of memory ever allocated (in kilobytes)
@@ -537,7 +622,7 @@ that memory was allocated and freed as a side-effect of the commands.
 @findex CONFIGURE_SHELL_NO_COMMAND_MALLOC
 @findex CONFIGURE_SHELL_COMMAND_MALLOC
 
-This command is included in the default shell command set.  
+This command is included in the default shell command set.
 When building a custom command set, define
 @code{CONFIGURE_SHELL_COMMAND_MALLOC} to have this
 command included.




More information about the vc mailing list