Changeset bcd065cc in rtems


Ignore:
Timestamp:
Feb 2, 2012, 8:59:15 PM (7 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10
Children:
7f0ad21
Parents:
5de3d25
Message:

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@…>

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libmisc/Makefile.am

    r5de3d25 rbcd065cc  
    11##
    2 ##  $Id$
    32##
    43
     
    7877    shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \
    7978    shell/main_mmove.c shell/main_msdosfmt.c \
    80     shell/main_mv.c shell/main_mwdump.c shell/main_perioduse.c \
     79    shell/main_mv.c shell/main_perioduse.c \
    8180    shell/main_pwd.c shell/main_rm.c shell/main_rmdir.c shell/main_sleep.c \
    8281    shell/main_stackuse.c shell/main_tty.c shell/main_umask.c \
  • cpukit/libmisc/shell/main_mdump.c

    r5de3d25 rbcd065cc  
    66 *  Home: correo@fernando-ruiz.com
    77 *
     8 *  Reworked by Ric Claus at SLAC.Stanford.edu
     9 *
    810 *  The license and distribution terms for this file may be
    911 *  found in the file LICENSE in this distribution or at
    1012 *  http://www.rtems.com/license/LICENSE.
    11  *
    12  *  $Id$
    1313 */
    1414
     
    2727#include "internal.h"
    2828
     29static int args_parse(int argc, char* argv[], void** addr, int* max, int* sz);
     30
     31static void mdumpB(void* addr, int m);
     32static void mdumpW(void* addr, int m);
     33static void mdumpL(void* addr, int m);
     34
     35int rtems_mdump(void* addr, int max, int sz);
     36
    2937int rtems_shell_main_mdump(
    3038  int   argc,
     
    3240)
    3341{
    34   unsigned char  n;
    35   unsigned char  m;
    36   int            max;
    37   int            res;
    38   void          *addr = NULL;
    39   unsigned char *pb;
     42  void *addr;
     43  int   max;
     44  int   sz;
     45
     46  if (args_parse(argc, argv, &addr, &max, &sz))
     47    return -1;
     48  return rtems_mdump(addr, max, sz);
     49}
     50
     51int rtems_shell_main_wdump(
     52  int   argc,
     53  char *argv[]
     54)
     55{
     56  void *addr;
     57  int   max;
     58  int   sz;
     59
     60  if (args_parse(argc, argv, &addr, &max, &sz))
     61    return -1;
     62  return rtems_mdump(addr, max, 2);
     63}
     64
     65
     66int rtems_shell_main_ldump(
     67  int   argc,
     68  char *argv[]
     69)
     70{
     71  void *addr;
     72  int   max;
     73  int   sz;
     74
     75  if (args_parse(argc, argv, &addr, &max, &sz))
     76    return -1;
     77  return rtems_mdump(addr, max, 4);
     78}
     79
     80
     81int args_parse(int    argc,
     82               char*  argv[],
     83               void** addr,
     84               int*   max,
     85               int*   sz)
     86{
     87  *addr = NULL;
     88  *max  = 320;
     89  *sz   = 1;
    4090
    4191  if (argc > 1) {
    42     if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
     92    if ( rtems_string_to_pointer(argv[1], addr, NULL) ) {
    4393      printf( "Address argument (%s) is not a number\n", argv[1] );
    4494      return -1;
    4595    }
    4696
    47   }
    48 
    49   if (argc > 2) {
    50     if ( rtems_string_to_int(argv[1], &max, NULL, 0) ) {
    51       printf( "Length argument (%s) is not a number\n", argv[1] );
    52       return -1;
    53     }
    54     if (max <= 0) {
    55       max = 1;      /* print 1 item if 0 or neg. */
    56       res = 0;
    57     } else {
    58       max--;
    59       res = max & 0xf;/* num bytes in last row */
    60       max >>= 4;      /* div by 16 */
    61       max++;          /* num of rows to print */
    62       if (max > 20) { /* limit to 20 */
    63         max = 20;
    64         res = 0xf;    /* 16 bytes print in last row */
     97    if (argc > 2) {
     98      if ( rtems_string_to_int(argv[2], max, NULL, 0) ) {
     99        printf( "Length argument (%s) is not a number\n", argv[2] );
     100        return -1;
    65101      }
    66     }
     102
     103      if (argc > 3) {
     104        if ( rtems_string_to_int(argv[3], sz, NULL, 0) ) {
     105          printf( "Size argument (%s) is not a valid number\n", argv[3] );
     106          return -1;
     107        }
     108      }
     109    }
     110  }
     111  return 0;
     112}
     113
     114
     115int rtems_mdump(void* addr, int max, int sz)
     116{
     117  unsigned char           n;
     118  unsigned char           m;
     119  volatile unsigned char *pb;
     120  int                     res;
     121  int                     cnt;
     122
     123  if (!((sz == 1) || (sz == 2) || (sz == 4))) {
     124    printf( "Size argument (%d) is not one of 1 (bytes), "
     125              " 2 (words) or 4 (longwords)\n", sz);
     126    return -1;
     127  }
     128
     129  if (max <= 0) {
     130    max = 1;           /* print 1 item if 0 or neg. */
     131    res = 0;
    67132  } else {
    68     max = 20;
    69     res = 0xf;
     133    max--;
     134    res = max & 0xf;   /* num bytes in last row */
     135    max >>= 4;         /* div by 16 */
     136    max++;             /* num of rows to print */
     137    if (max > 64) {    /* limit to 64 lines */
     138      max = 64;
     139      res = 0xf;       /* 16 bytes print in last row */
     140    }
    70141  }
    71142
    72143  pb = addr;
    73144  for (m=0; m<max; m++) {
     145    cnt = m==(max-1)?res:0xf;
    74146    printf("%10p ", pb);
    75     for (n=0;n<=(m==(max-1)?res:0xf);n++)
    76       printf("%02X%c",pb[n],n==7?'-':' ');
    77     for (;n<=0xf;n++)
    78       printf("  %c",n==7?'-':' ');
    79     for (n=0;n<=(m==(max-1)?res:0xf);n++) {
     147    if      (sz == 1)  mdumpB(pb, cnt);
     148    else if (sz == 2)  mdumpW(pb, cnt);
     149    else if (sz == 4)  mdumpL(pb, cnt);
     150    for (n=0;n<=cnt;n++) {
    80151      printf("%c", isprint(pb[n]) ? pb[n] : '.');
    81152    }
     
    83154    pb += 16;
    84155  }
     156
    85157  return 0;
    86158}
     159
     160
     161void mdumpB(void* addr, int m)
     162{
     163  volatile unsigned char* pb = addr;
     164  int n;
     165  for (n=0;n<=m;n++)
     166    printf("%02X%c",*pb++,n==7?'-':' ');
     167  for (;n<=0xf;n++)
     168    printf("  %c",n==7?'-':' ');
     169}
     170
     171
     172void mdumpW(void* addr, int m)
     173{
     174  volatile unsigned short* pb = addr;
     175  int n;
     176  for (n=0;n<=m;n+=2)
     177    printf("%04X%c",*pb++,n==6?'-':' ');
     178  for (;n<=0xf;n+=2)
     179    printf("    %c", n==6?'-':' ');
     180}
     181
     182
     183void mdumpL(void* addr, int m)
     184{
     185  volatile unsigned int* pb = addr;
     186  int n;
     187  for (n=0;n<=m;n+=4)
     188    printf("%08X%c",*pb++,n==4?'-':' ');
     189  for (;n<=0xf;n+=4)
     190    printf("        %c", n==4?'-':' ');
     191}
     192
    87193
    88194rtems_shell_cmd_t rtems_shell_MDUMP_Command = {
    89195  "mdump",                                      /* name */
    90   "mdump [address [length]]",                   /* usage */
     196  "mdump [address [length [size]]]",            /* usage */
    91197  "mem",                                        /* topic */
    92198  rtems_shell_main_mdump,                       /* command */
     
    95201};
    96202
     203
     204rtems_shell_cmd_t rtems_shell_WDUMP_Command = {
     205  "wdump",                                      /* name */
     206  "wdump [address [length]]",                   /* usage */
     207  "mem",                                        /* topic */
     208  rtems_shell_main_wdump,                       /* command */
     209  NULL,                                         /* alias */
     210  NULL                                          /* next */
     211};
     212
     213
     214rtems_shell_cmd_t rtems_shell_LDUMP_Command = {
     215  "ldump",                                      /* name */
     216  "ldump [address [length]]",                   /* usage */
     217  "mem",                                        /* topic */
     218  rtems_shell_main_ldump,                       /* command */
     219  NULL,                                         /* alias */
     220  NULL                                          /* next */
     221};
     222
  • cpukit/libmisc/shell/shellconfig.h

    r5de3d25 rbcd065cc  
    22 *  RTEMS Shell Command Set Configuration
    33 *
    4  *  COPYRIGHT (c) 1989-2007.
     4 *  COPYRIGHT (c) 1989-2012.
    55 *  On-Line Applications Research Corporation (OAR).
    66 *
     
    88 *  found in the file LICENSE in this distribution or at
    99 *  http://www.rtems.com/license/LICENSE.
    10  *
    11  *  $Id$
    1210 */
    1311
     
    3028extern rtems_shell_cmd_t rtems_shell_MDUMP_Command;
    3129extern rtems_shell_cmd_t rtems_shell_WDUMP_Command;
     30extern rtems_shell_cmd_t rtems_shell_LDUMP_Command;
    3231extern rtems_shell_cmd_t rtems_shell_MEDIT_Command;
    3332extern rtems_shell_cmd_t rtems_shell_MFILL_Command;
     
    222221    #endif
    223222    #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
     223         !defined(CONFIGURE_SHELL_NO_COMMAND_LDUMP)) || \
     224        defined(CONFIGURE_SHELL_COMMAND_LDUMP)
     225      &rtems_shell_LDUMP_Command,
     226    #endif
     227    #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
    224228         !defined(CONFIGURE_SHELL_NO_COMMAND_MEDIT)) || \
    225229        defined(CONFIGURE_SHELL_COMMAND_MEDIT)
  • doc/shell/memory.t

    r5de3d25 rbcd065cc  
    11@c
    2 @c  COPYRIGHT (c) 1988-2008.
     2@c  COPYRIGHT (c) 1988-2012.
    33@c  On-Line Applications Research Corporation (OAR).
    44@c  All rights reserved.
    55@c
    6 @c  $Id$
    7 @c
    86
    97@chapter Memory Commands
     
    1715@item @code{mdump} - Display contents of memory
    1816@item @code{wdump} - Display contents of memory (word)
     17@item @code{ldump} - Display contents of memory (longword)
    1918@item @code{medit} - Modify contents of memory
    2019@item @code{mfill} - File memory with pattern
     
    4241
    4342@example
    44 mdump [address [length]]
     43mdump [address [length [size]]]
    4544@end example
    4645
     
    4847
    4948This command displays the contents of memory at the @code{address}
    50 and @code{length} in bytes specified on the command line. 
     49and @code{length} in @code{size} byte units specified on the command line.
     50
     51When @code{size} is not provided, it defaults to @code{1} byte units.
     52Values of @code{1}, @code{2}, and @code{4} are valid; all others will
     53cause an error to be reported.
    5154
    5255When @code{length} is not provided, it defaults to @code{320} which
     
    8588@findex CONFIGURE_SHELL_COMMAND_MDUMP
    8689
    87 This command is included in the default shell command set. 
     90This command is included in the default shell command set.
    8891When building a custom command set, define
    8992@code{CONFIGURE_SHELL_COMMAND_MDUMP} to have this
     
    132135
    133136This command displays the contents of memory at the @code{address}
    134 and @code{length} in bytes specified on the command line. 
     137and @code{length} in bytes specified on the command line.
     138
     139This command is equivalent to @code{mdump address length 2}.
    135140
    136141When @code{length} is not provided, it defaults to @code{320} which
    137 is twenty lines of output with sixteen bytes of output per line.
     142is twenty lines of output with eight words of output per line.
    138143
    139144When @code{address} is not provided, it defaults to @code{0x00000000}.
     
    163168@findex CONFIGURE_SHELL_COMMAND_WDUMP
    164169
    165 This command is included in the default shell command set. 
     170This command is included in the default shell command set.
    166171When building a custom command set, define
    167172@code{CONFIGURE_SHELL_COMMAND_WDUMP} to have this
     
    191196@example
    192197extern rtems_shell_cmd_t rtems_shell_WDUMP_Command;
     198@end example
     199
     200@c
     201@c
     202@c
     203@page
     204@subsection ldump - display contents of memory (longword)
     205
     206@pgindex ldump
     207
     208@subheading SYNOPSYS:
     209
     210@example
     211ldump [address [length]]
     212@end example
     213
     214@subheading DESCRIPTION:
     215
     216This command displays the contents of memory at the @code{address}
     217and @code{length} in bytes specified on the command line.
     218
     219This command is equivalent to @code{mdump address length 4}.
     220
     221When @code{length} is not provided, it defaults to @code{320} which
     222is twenty lines of output with four longwords of output per line.
     223
     224When @code{address} is not provided, it defaults to @code{0x00000000}.
     225
     226@subheading EXIT STATUS:
     227
     228This command always returns 0 to indicate success.
     229
     230@subheading NOTES:
     231
     232Dumping memory from a non-existent address may result in an unrecoverable
     233program fault.
     234
     235@subheading EXAMPLES:
     236
     237The following is an example of how to use @code{ldump}:
     238
     239@smallexample
     240SHLL [/] $ ldump 0x02010000 32
     2410x02010000 020108D8 020108C0-020108AC 02010874 ...............t
     2420x02010010 020 0894 02010718-02010640 02010798 ...........@....
     243@end smallexample
     244
     245@subheading CONFIGURATION:
     246
     247@findex CONFIGURE_SHELL_NO_COMMAND_LDUMP
     248@findex CONFIGURE_SHELL_COMMAND_LDUMP
     249
     250This command is included in the default shell command set.
     251When building a custom command set, define
     252@code{CONFIGURE_SHELL_COMMAND_LDUMP} to have this
     253command included.
     254
     255This command can be excluded from the shell command set by
     256defining @code{CONFIGURE_SHELL_NO_COMMAND_LDUMP} when all
     257shell commands have been configured.
     258
     259@subheading PROGRAMMING INFORMATION:
     260
     261@findex rtems_shell_rtems_main_ldump
     262
     263The @code{ldump} is implemented by a C language function
     264which has the following prototype:
     265
     266@example
     267int rtems_shell_rtems_main_ldump(
     268  int    argc,
     269  char **argv
     270);
     271@end example
     272
     273The configuration structure for the @code{ldump} has the
     274following prototype:
     275
     276@example
     277extern rtems_shell_cmd_t rtems_shell_LDUMP_Command;
    193278@end example
    194279
     
    241326@findex CONFIGURE_SHELL_COMMAND_MEDIT
    242327
    243 This command is included in the default shell command set. 
     328This command is included in the default shell command set.
    244329When building a custom command set, define
    245330@code{CONFIGURE_SHELL_COMMAND_MEDIT} to have this
     
    304389
    305390In this example, the address used (@code{0x23d89a0}) as the base
    306 address of the filled area is the end of the stack for the 
     391address of the filled area is the end of the stack for the
    307392Idle thread.  This address was determined manually using gdb and
    308393is very specific to this application and BSP.  The first command
     
    328413@findex CONFIGURE_SHELL_COMMAND_MFILL
    329414
    330 This command is included in the default shell command set. 
     415This command is included in the default shell command set.
    331416When building a custom command set, define
    332417@code{CONFIGURE_SHELL_COMMAND_MFILL} to have this
     
    405490@findex CONFIGURE_SHELL_COMMAND_MMOVE
    406491
    407 This command is included in the default shell command set. 
     492This command is included in the default shell command set.
    408493When building a custom command set, define
    409494@code{CONFIGURE_SHELL_COMMAND_MMOVE} to have this
     
    474559
    475560@itemize @bullet
    476 @item 
     561@item
    477562@item Currently available memory (in kilobytes)
    478563@item Currently allocated memory (in kilobytes)
     
    538623@findex CONFIGURE_SHELL_COMMAND_MALLOC
    539624
    540 This command is included in the default shell command set. 
     625This command is included in the default shell command set.
    541626When building a custom command set, define
    542627@code{CONFIGURE_SHELL_COMMAND_MALLOC} to have this
Note: See TracChangeset for help on using the changeset viewer.