mirror of
https://github.com/t-crest/rtems.git
synced 2025-11-16 12:34:47 +00:00
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@SLAC.Stanford.edu>
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
##
|
##
|
||||||
## $Id$
|
|
||||||
##
|
##
|
||||||
|
|
||||||
include $(top_srcdir)/automake/compile.am
|
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_mallocinfo.c shell/main_mdump.c shell/main_medit.c \
|
||||||
shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \
|
shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \
|
||||||
shell/main_mmove.c shell/main_msdosfmt.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_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_stackuse.c shell/main_tty.c shell/main_umask.c \
|
||||||
shell/main_unmount.c shell/main_blksync.c shell/main_whoami.c \
|
shell/main_unmount.c shell/main_blksync.c shell/main_whoami.c \
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
* Work: fernando.ruiz@ctv.es
|
* Work: fernando.ruiz@ctv.es
|
||||||
* Home: correo@fernando-ruiz.com
|
* Home: correo@fernando-ruiz.com
|
||||||
*
|
*
|
||||||
|
* Reworked by Ric Claus at SLAC.Stanford.edu
|
||||||
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
||||||
* http://www.rtems.com/license/LICENSE.
|
* http://www.rtems.com/license/LICENSE.
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@@ -26,71 +26,197 @@
|
|||||||
#include <rtems/stringto.h>
|
#include <rtems/stringto.h>
|
||||||
#include "internal.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 rtems_shell_main_mdump(
|
||||||
int argc,
|
int argc,
|
||||||
char *argv[]
|
char *argv[]
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
unsigned char n;
|
void *addr;
|
||||||
unsigned char m;
|
|
||||||
int max;
|
int max;
|
||||||
int res;
|
int sz;
|
||||||
void *addr = NULL;
|
|
||||||
unsigned char *pb;
|
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 (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] );
|
printf( "Address argument (%s) is not a number\n", argv[1] );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 2) {
|
if (argc > 2) {
|
||||||
if ( rtems_string_to_int(argv[1], &max, NULL, 0) ) {
|
if ( rtems_string_to_int(argv[2], max, NULL, 0) ) {
|
||||||
printf( "Length argument (%s) is not a number\n", argv[1] );
|
printf( "Length argument (%s) is not a number\n", argv[2] );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
if (max <= 0) {
|
||||||
max = 1; /* print 1 item if 0 or neg. */
|
max = 1; /* print 1 item if 0 or neg. */
|
||||||
res = 0;
|
res = 0;
|
||||||
} else {
|
} else {
|
||||||
max--;
|
max--;
|
||||||
res = max & 0xf;/* num bytes in last row */
|
res = max & 0xf; /* num bytes in last row */
|
||||||
max >>= 4; /* div by 16 */
|
max >>= 4; /* div by 16 */
|
||||||
max++; /* num of rows to print */
|
max++; /* num of rows to print */
|
||||||
if (max > 20) { /* limit to 20 */
|
if (max > 64) { /* limit to 64 lines */
|
||||||
max = 20;
|
max = 64;
|
||||||
res = 0xf; /* 16 bytes print in last row */
|
res = 0xf; /* 16 bytes print in last row */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
max = 20;
|
|
||||||
res = 0xf;
|
|
||||||
}
|
|
||||||
|
|
||||||
pb = addr;
|
pb = addr;
|
||||||
for (m=0; m<max; m++) {
|
for (m=0; m<max; m++) {
|
||||||
|
cnt = m==(max-1)?res:0xf;
|
||||||
printf("%10p ", pb);
|
printf("%10p ", pb);
|
||||||
for (n=0;n<=(m==(max-1)?res:0xf);n++)
|
if (sz == 1) mdumpB(pb, cnt);
|
||||||
printf("%02X%c",pb[n],n==7?'-':' ');
|
else if (sz == 2) mdumpW(pb, cnt);
|
||||||
for (;n<=0xf;n++)
|
else if (sz == 4) mdumpL(pb, cnt);
|
||||||
printf(" %c",n==7?'-':' ');
|
for (n=0;n<=cnt;n++) {
|
||||||
for (n=0;n<=(m==(max-1)?res:0xf);n++) {
|
|
||||||
printf("%c", isprint(pb[n]) ? pb[n] : '.');
|
printf("%c", isprint(pb[n]) ? pb[n] : '.');
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
pb += 16;
|
pb += 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
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 = {
|
rtems_shell_cmd_t rtems_shell_MDUMP_Command = {
|
||||||
"mdump", /* name */
|
"mdump", /* name */
|
||||||
"mdump [address [length]]", /* usage */
|
"mdump [address [length [size]]]", /* usage */
|
||||||
"mem", /* topic */
|
"mem", /* topic */
|
||||||
rtems_shell_main_mdump, /* command */
|
rtems_shell_main_mdump, /* command */
|
||||||
NULL, /* alias */
|
NULL, /* alias */
|
||||||
NULL /* next */
|
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 */
|
||||||
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* RTEMS Shell Command Set Configuration
|
* RTEMS Shell Command Set Configuration
|
||||||
*
|
*
|
||||||
* COPYRIGHT (c) 1989-2007.
|
* COPYRIGHT (c) 1989-2012.
|
||||||
* On-Line Applications Research Corporation (OAR).
|
* On-Line Applications Research Corporation (OAR).
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
||||||
* http://www.rtems.com/license/LICENSE.
|
* http://www.rtems.com/license/LICENSE.
|
||||||
*
|
|
||||||
* $Id$
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _RTEMS_SHELL_CONFIG_h
|
#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_MDUMP_Command;
|
||||||
extern rtems_shell_cmd_t rtems_shell_WDUMP_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_MEDIT_Command;
|
||||||
extern rtems_shell_cmd_t rtems_shell_MFILL_Command;
|
extern rtems_shell_cmd_t rtems_shell_MFILL_Command;
|
||||||
extern rtems_shell_cmd_t rtems_shell_MMOVE_Command;
|
extern rtems_shell_cmd_t rtems_shell_MMOVE_Command;
|
||||||
@@ -220,6 +219,11 @@ extern rtems_shell_alias_t *rtems_shell_Initial_aliases[];
|
|||||||
defined(CONFIGURE_SHELL_COMMAND_WDUMP)
|
defined(CONFIGURE_SHELL_COMMAND_WDUMP)
|
||||||
&rtems_shell_WDUMP_Command,
|
&rtems_shell_WDUMP_Command,
|
||||||
#endif
|
#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) && \
|
#if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
|
||||||
!defined(CONFIGURE_SHELL_NO_COMMAND_MEDIT)) || \
|
!defined(CONFIGURE_SHELL_NO_COMMAND_MEDIT)) || \
|
||||||
defined(CONFIGURE_SHELL_COMMAND_MEDIT)
|
defined(CONFIGURE_SHELL_COMMAND_MEDIT)
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
@c
|
@c
|
||||||
@c COPYRIGHT (c) 1988-2008.
|
@c COPYRIGHT (c) 1988-2012.
|
||||||
@c On-Line Applications Research Corporation (OAR).
|
@c On-Line Applications Research Corporation (OAR).
|
||||||
@c All rights reserved.
|
@c All rights reserved.
|
||||||
@c
|
@c
|
||||||
@c $Id$
|
|
||||||
@c
|
|
||||||
|
|
||||||
@chapter Memory Commands
|
@chapter Memory Commands
|
||||||
|
|
||||||
@@ -16,6 +14,7 @@ The RTEMS shell has the following memory commands:
|
|||||||
|
|
||||||
@item @code{mdump} - Display contents of memory
|
@item @code{mdump} - Display contents of memory
|
||||||
@item @code{wdump} - Display contents of memory (word)
|
@item @code{wdump} - Display contents of memory (word)
|
||||||
|
@item @code{ldump} - Display contents of memory (longword)
|
||||||
@item @code{medit} - Modify contents of memory
|
@item @code{medit} - Modify contents of memory
|
||||||
@item @code{mfill} - File memory with pattern
|
@item @code{mfill} - File memory with pattern
|
||||||
@item @code{mmove} - Move contents of memory
|
@item @code{mmove} - Move contents of memory
|
||||||
@@ -41,13 +40,17 @@ command as well as providing an example usage.
|
|||||||
@subheading SYNOPSYS:
|
@subheading SYNOPSYS:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
mdump [address [length]]
|
mdump [address [length [size]]]
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@subheading DESCRIPTION:
|
@subheading DESCRIPTION:
|
||||||
|
|
||||||
This command displays the contents of memory at the @code{address}
|
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
|
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 sixteen bytes of output per line.
|
||||||
@@ -133,8 +136,10 @@ wdump [address [length]]
|
|||||||
This command displays the contents of memory at the @code{address}
|
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
|
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}.
|
When @code{address} is not provided, it defaults to @code{0x00000000}.
|
||||||
|
|
||||||
@@ -192,6 +197,86 @@ following prototype:
|
|||||||
extern rtems_shell_cmd_t rtems_shell_WDUMP_Command;
|
extern rtems_shell_cmd_t rtems_shell_WDUMP_Command;
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
@c
|
||||||
|
@c
|
||||||
|
@c
|
||||||
|
@page
|
||||||
|
@subsection ldump - display contents of memory (longword)
|
||||||
|
|
||||||
|
@pgindex ldump
|
||||||
|
|
||||||
|
@subheading SYNOPSYS:
|
||||||
|
|
||||||
|
@example
|
||||||
|
ldump [address [length]]
|
||||||
|
@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.
|
||||||
|
|
||||||
|
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}.
|
||||||
|
|
||||||
|
@subheading EXIT STATUS:
|
||||||
|
|
||||||
|
This command always returns 0 to indicate success.
|
||||||
|
|
||||||
|
@subheading NOTES:
|
||||||
|
|
||||||
|
Dumping memory from a non-existent address may result in an unrecoverable
|
||||||
|
program fault.
|
||||||
|
|
||||||
|
@subheading EXAMPLES:
|
||||||
|
|
||||||
|
The following is an example of how to use @code{ldump}:
|
||||||
|
|
||||||
|
@smallexample
|
||||||
|
SHLL [/] $ ldump 0x02010000 32
|
||||||
|
0x02010000 020108D8 020108C0-020108AC 02010874 ...............t
|
||||||
|
0x02010010 020 0894 02010718-02010640 02010798 ...........@....
|
||||||
|
@end smallexample
|
||||||
|
|
||||||
|
@subheading CONFIGURATION:
|
||||||
|
|
||||||
|
@findex CONFIGURE_SHELL_NO_COMMAND_LDUMP
|
||||||
|
@findex CONFIGURE_SHELL_COMMAND_LDUMP
|
||||||
|
|
||||||
|
This command is included in the default shell command set.
|
||||||
|
When building a custom command set, define
|
||||||
|
@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.
|
||||||
|
|
||||||
|
@subheading PROGRAMMING INFORMATION:
|
||||||
|
|
||||||
|
@findex rtems_shell_rtems_main_ldump
|
||||||
|
|
||||||
|
The @code{ldump} is implemented by a C language function
|
||||||
|
which has the following prototype:
|
||||||
|
|
||||||
|
@example
|
||||||
|
int rtems_shell_rtems_main_ldump(
|
||||||
|
int argc,
|
||||||
|
char **argv
|
||||||
|
);
|
||||||
|
@end example
|
||||||
|
|
||||||
|
The configuration structure for the @code{ldump} has the
|
||||||
|
following prototype:
|
||||||
|
|
||||||
|
@example
|
||||||
|
extern rtems_shell_cmd_t rtems_shell_LDUMP_Command;
|
||||||
|
@end example
|
||||||
|
|
||||||
@c
|
@c
|
||||||
@c
|
@c
|
||||||
@c
|
@c
|
||||||
|
|||||||
Reference in New Issue
Block a user